本文整理汇总了Java中org.apache.solr.client.solrj.impl.HttpSolrClient类的典型用法代码示例。如果您正苦于以下问题:Java HttpSolrClient类的具体用法?Java HttpSolrClient怎么用?Java HttpSolrClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpSolrClient类属于org.apache.solr.client.solrj.impl包,在下文中一共展示了HttpSolrClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createNewSolrClient
import org.apache.solr.client.solrj.impl.HttpSolrClient; //导入依赖的package包/类
protected static HttpSolrClient createNewSolrClient(final String core) {
try {
URL url = jetty.getBaseUrl();
// For debugging in Charles:
// - set the proxy port to 8888
// - enable transparent proxying
// - enable Map Remote and map 127.0.0.1:8888 to 127.0.0.1:8080
url = new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile() + "/" + core);
ModifiableSolrParams params = new ModifiableSolrParams();
params.add(HttpClientUtil.PROP_CONNECTION_TIMEOUT, Integer.toString(DEFAULT_CONNECTION_TIMEOUT));
return new HttpSolrClient.Builder(url.toString()).
withHttpClient(HttpClientUtil.createClient(params)).build();
} catch(Exception e) {
throw new RuntimeException(e);
}
}
示例2: getHttpSolrClients
import org.apache.solr.client.solrj.impl.HttpSolrClient; //导入依赖的package包/类
/**
*
* @param cloudSolrClient
* @return
* @throws SolrServerException
* @throws IOException
*/
private List<HttpSolrClient> getHttpSolrClients(CloudSolrClient cloudSolrClient) throws SolrServerException, IOException {
List<HttpSolrClient> solrClients = new ArrayList<>();
for (String baseUrl : getBaseUrls(cloudSolrClient)) {
NoOpResponseParser responseParser = new NoOpResponseParser();
responseParser.setWriterType("json");
HttpSolrClient.Builder builder = new HttpSolrClient.Builder();
builder.withBaseSolrUrl(baseUrl);
HttpSolrClient httpSolrClient = builder.build();
httpSolrClient.setParser(responseParser);
solrClients.add(httpSolrClient);
}
return solrClients;
}
示例3: indexMap
import org.apache.solr.client.solrj.impl.HttpSolrClient; //导入依赖的package包/类
public void indexMap(String id, Map<String, List<String>> objectMap)
throws IOException, SolrServerException {
SolrInputDocument document = new SolrInputDocument();
document.addField("id", id);
for (String key : objectMap.keySet()) {
Object value = objectMap.get(key);
if (value != null) {
// System.err.printf("%s: class: %s\n", key, value.getClass());
document.addField(key + "_ss", value);
}
}
try {
UpdateResponse response = solr.add(document);
// solr.commit();
} catch (HttpSolrClient.RemoteSolrException ex) {
System.err.printf("document: %s", document);
System.err.printf("Commit exception: %s\n", ex.getMessage());
}
}
示例4: getCores
import org.apache.solr.client.solrj.impl.HttpSolrClient; //导入依赖的package包/类
/**
* Get target cores via CoreAdminAPI.
*
* @param httpSolrClient
* @return
*/
public static List<String> getCores(HttpSolrClient httpSolrClient) throws SolrServerException, IOException {
List<String> cores = new ArrayList<>();
NoOpResponseParser responseParser = new NoOpResponseParser();
responseParser.setWriterType("json");
httpSolrClient.setParser(responseParser);
CoreAdminRequest coreAdminRequest = new CoreAdminRequest();
coreAdminRequest.setAction(CoreAdminParams.CoreAdminAction.STATUS);
coreAdminRequest.setIndexInfoNeeded(false);
NamedList<Object> coreAdminResponse = httpSolrClient.request(coreAdminRequest);
JsonNode statusJsonNode = om.readTree((String) coreAdminResponse.get("response")).get("status");
for (Iterator<JsonNode> i = statusJsonNode.iterator(); i.hasNext(); ) {
String core = i.next().get("name").textValue();
if (!cores.contains(core)) {
cores.add(core);
}
}
return cores;
}
示例5: indexDuplumKey
import org.apache.solr.client.solrj.impl.HttpSolrClient; //导入依赖的package包/类
public void indexDuplumKey(String id, Map<String, Object> objectMap)
throws IOException, SolrServerException {
SolrInputDocument document = new SolrInputDocument();
document.addField("id", id);
for (String key : objectMap.keySet()) {
Object value = objectMap.get(key);
if (value != null) {
// System.err.printf("%s: class: %s\n", key, value.getClass());
document.addField(key + "_ss", value);
}
}
try {
UpdateResponse response = solr.add(document);
// solr.commit();
} catch (HttpSolrClient.RemoteSolrException ex) {
System.err.printf("document: %s", document);
System.err.printf("Commit exception: %s\n", ex.getMessage());
}
}
示例6: main
import org.apache.solr.client.solrj.impl.HttpSolrClient; //导入依赖的package包/类
/**
* Main entry point.
*
* @param args the command line arguments.
* @throws IOException in case of I/O failure.
*/
public static void main(String[] args) throws IOException, SolrServerException {
// This is the list of documents we will send to Solr
List<SolrInputDocument> books = new ArrayList<SolrInputDocument>();
// Populate the list
books.add(newBook("1", "Apache Solr Essentials", "Andrea Gazzarini"));
books.add(newBook("2", "Apache Solr FullText Search Server", "John White"));
books.add(newBook("3", "Enterprise Search with Apache Solr", "Martin Green"));
// Creates the Solr remote proxy
try (SolrClient client = new HttpSolrClient.Builder("http://127.0.0.1:8983/solr/ex1").build()) {
// Indexes data
client.add(books);
// Commits
client.commit();
}
}
示例7: createNewSolrClient
import org.apache.solr.client.solrj.impl.HttpSolrClient; //导入依赖的package包/类
public SolrClient createNewSolrClient(final String index) {
if (jetty != null) {
try {
// setup the client...
String url = jetty.getBaseUrl().toString() + "/" + index;
HttpSolrClient client = getHttpSolrClient(url);
client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
client.setDefaultMaxConnectionsPerHost(100);
client.setMaxTotalConnections(100);
return client;
} catch (Exception ex) {
throw new RuntimeException(ex);
}
} else {
return new EmbeddedSolrServer(h.getCoreContainer(), index);
}
}
示例8: doFeed
import org.apache.solr.client.solrj.impl.HttpSolrClient; //导入依赖的package包/类
public void doFeed() throws Exception {
this.server = new ConcurrentUpdateSolrClient(serverUrl,queueSize,threads);
if(threads==1 && queueSize == 1) {
this.server = new HttpSolrClient(serverUrl);
}
if(deleteIndex) {
System.out.println("Delete the index.");
server.deleteByQuery("*:*");
}
parse();
server.commit();
server.optimize();
server.close();
}
示例9: connect
import org.apache.solr.client.solrj.impl.HttpSolrClient; //导入依赖的package包/类
/**
* Verbindung zum Solr-Server herstellen
*/
private void connect() {
solrClient = new HttpSolrClient.Builder(Configuration.SOLR_SERVER_URL + Configuration.SOLR_CORE_NAME).build();
// Verbindung zum Solr-Server prüfen
try {
SolrPing ping = new SolrPing();
ping.setBasicAuthCredentials(Configuration.USERNAME, Configuration.PASSWORD);
SolrPingResponse pingResponse = ping.process(solrClient);
if (pingResponse.getStatus() != 0) {
System.out.println("Es gab einen unerwarteten Fehler beim Ping auf den Solr-Server (Status-Code ist " + pingResponse.getStatus() + ")");
}
else {
System.out.println("Ping zum Solr-Server war erfolgreich und dauerte " + pingResponse.getQTime() + " ms");
}
} catch (SolrServerException|IOException e) {
// do something reasonable
System.err.println(e);
}
}
示例10: main
import org.apache.solr.client.solrj.impl.HttpSolrClient; //导入依赖的package包/类
public static void main(String[] args) throws IOException, FitsConfigurationException, NoSuchAlgorithmException {
if (args.length < 2) {
System.out.println("You need to add the path to the FITS directory, the URI of your Solr server, and the path to the directory to index.");
} else {
Fits fits = new Fits(args[0]);
String urlString = args[1];
SolrClient solr = new HttpSolrClient.Builder(urlString).build();
DupeChecker dupeChecker = new DupeChecker(solr);
FitsVisitor fv = new FitsVisitor(fits,solr,dupeChecker);
Path startingDir = Paths.get(args[2]);
walkFileTree(startingDir, fv);
}
}
示例11: examineFile
import org.apache.solr.client.solrj.impl.HttpSolrClient; //导入依赖的package包/类
void examineFile(File file) throws FitsException, IOException, SolrServerException, XMLStreamException {
System.out.println("Adding " + file.getName());
FitsOutput fitsOutput = fits.examine(file);
fitsOutput.addStandardCombinedFormat();
SolrInputDocument solrDoc = new SolrInputDocument();
this.indexFitsFileInfo(fitsOutput, solrDoc);
this.indexFitsIdentities(fitsOutput, solrDoc);
this.indexTechMetadata(fitsOutput, solrDoc);
Document fitsXml = fitsOutput.getFitsXml();
this.indexFitsXml(fitsXml, solrDoc);
try {
UpdateResponse response = solr.add(solrDoc);
solr.commit();
} catch (HttpSolrClient.RemoteSolrException e) {
e.printStackTrace();
}
}
示例12: createSolrSpewer
import org.apache.solr.client.solrj.impl.HttpSolrClient; //导入依赖的package包/类
/**
* Create a new {@link SolrSpewer} by parsing the given options.
*
* @param options the options to parse
* @return A new spewer configured according to the given parameters.
*/
private static SolrSpewer createSolrSpewer(final Options<String> options, final FieldNames fields) {
final Extractor.EmbedHandling handling = options.ifPresent("embedHandling", o -> o.parse().asEnum(Extractor
.EmbedHandling::parse)).orElse(Extractor.EmbedHandling.getDefault());
// Calling #close on the SolrSpewer later on automatically closes the HTTP client.
final SolrClient solrClient = new HttpSolrClient.Builder(options.get("indexAddress").value().orElse
("http://127.0.0.1:8983/solr/"))
.withHttpClient(createHttpClient(options))
.build();
if (Extractor.EmbedHandling.SPAWN == handling) {
return new MergingSolrSpewer(solrClient, fields);
}
return new SolrSpewer(solrClient, fields);
}
示例13: commitDocumentChanges
import org.apache.solr.client.solrj.impl.HttpSolrClient; //导入依赖的package包/类
private void commitDocumentChanges(String collectionName, Collection<SolrInputDocument> documents) throws SolrServerException, IOException {
if (documents.size() == 0) return;
try {
solrClient.request(newUpdateRequest().add(documents), collectionName);
} catch (HttpSolrClient.RemoteSolrException rse) {
logger.error("Unable to save documents to Solr as one of the shape objects stored were not compatible with Solr.", rse);
logger.error("Details in failed document batch: ");
for (SolrInputDocument d : documents) {
Collection<String> fieldNames = d.getFieldNames();
for (String name : fieldNames) {
logger.error(name + ":" + d.getFieldValue(name).toString());
}
}
throw rse;
}
}
示例14: main
import org.apache.solr.client.solrj.impl.HttpSolrClient; //导入依赖的package包/类
public static void main(String[] args) {
SolrClient solr = new HttpSolrClient.Builder().withBaseSolrUrl("http://localhost:8983/solr/chronix/").build();
//Define a group by function for the time series records
Function<GenericTimeSeries<Long, Double>, String> groupBy = ts -> ts.getAttribute("name") + "-" + ts.getAttribute("host");
//Define a reduce function for the grouped time series records. We use the average.
BinaryOperator<GenericTimeSeries<Long, Double>> reduce = (ts1, ts2) -> merge(ts1, ts2, (y1, y2) -> (y1 + y2) / 2);
//Instantiate a Chronix Client
ChronixClient<GenericTimeSeries<Long, Double>, SolrClient, SolrQuery> chronix = new ChronixClient<>(
new GenericTimeSeriesConverter(), new ChronixSolrStorage<>(200, groupBy, reduce));
//We want the maximum of all time series that metric matches *load*.
SolrQuery query = new SolrQuery("name:*Load*");
query.setParam("cf", "metric{max}");
//The result is a Java Stream. We simply collect the result into a list.
List<GenericTimeSeries<Long, Double>> maxTS = chronix.stream(solr, query).collect(Collectors.toList());
//Just print it out.
LOGGER.info("Result for query {} is: {}", query, maxTS);
}
示例15: init
import org.apache.solr.client.solrj.impl.HttpSolrClient; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void init(Map<String, Object> conf) throws ConfigException {
String solrApiUrl = null;
String collectionName = null;
if (conf != null) {
solrApiUrl = (String) conf.get(SOLR_API_URL_KEY);
collectionName = (String) conf.get(COLLECTION_NAME);
if (collectionName == null) {
collectionName = DEFAULT_COLLECTION_NAME;
}
}
if (solrApiUrl == null || collectionName == null) {
throw new ConfigException("'solrApiUrl' must be presented in configuration.");
}
if ((boolean) conf.getOrDefault(SECURED_CLUSTER, false)) {
HttpClientUtil.addConfigurer(new Krb5HttpClientConfigurer());
}
solr = new HttpSolrClient.Builder(solrApiUrl + "/" + collectionName).build();
}