本文整理汇总了Java中org.apache.solr.client.solrj.SolrClient类的典型用法代码示例。如果您正苦于以下问题:Java SolrClient类的具体用法?Java SolrClient怎么用?Java SolrClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SolrClient类属于org.apache.solr.client.solrj包,在下文中一共展示了SolrClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRuntimeLib
import org.apache.solr.client.solrj.SolrClient; //导入依赖的package包/类
@Test
public void testRuntimeLib() throws SolrServerException, IOException {
SearchServer server = testSearchServer.getSearchServer();
SolrClient client = (SolrClient) server.getBackend();
SolrInputDocument document = new SolrInputDocument();
document.setField("_id_", "1");
document.setField("_type_", "doc");
document.setField("dynamic_multi_facet_string_f1", "test");
document.setField("dynamic_multi_facet_string_f2", "hello");
client.add(document);
client.commit();
SolrQuery query = new SolrQuery("t");
query.setRequestHandler("/suggester");
query.set("suggestion.df", "facets");
query.set("suggestion.field", "dynamic_multi_facet_string_f1");
QueryResponse response = client.query(query);
assertEquals(1, ((HashMap) response.getResponse().get("suggestions")).get("suggestion_count"));
}
示例2: SolrSearchServer
import org.apache.solr.client.solrj.SolrClient; //导入依赖的package包/类
/**
* Creates an instance of SolrSearch server allowing to avoid the schema validity check.
* @param client SolrClient to connect to.
* @param check true to perform local schema validity check against remote schema, false otherwise.
*/
protected SolrSearchServer(SolrClient client, boolean check) {
solrClient = client;
//In order to perform unit tests with mocked solrClient, we do not need to do the schema check.
if(check && client != null) {
try {
final SolrPingResponse ping = solrClient.ping();
if (ping.getStatus() == 0) {
log.debug("Pinged Solr in {}", ping.getQTime());
}
} catch (SolrServerException | IOException e) {
log.error("Cannot connect to solr server", e);
throw new RuntimeException();
}
log.info("Connection to solr server successful");
checkVersionAndSchema();
} else {
log.warn("Solr ping and schema validity check has been deactivated.");
}
}
示例3: main
import org.apache.solr.client.solrj.SolrClient; //导入依赖的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();
}
}
示例4: createNewSolrClient
import org.apache.solr.client.solrj.SolrClient; //导入依赖的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);
}
}
示例5: indexConversation
import org.apache.solr.client.solrj.SolrClient; //导入依赖的package包/类
public void indexConversation(Conversation conversation, boolean commit) {
try (SolrClient solr = solrServer.getSolrClient(conversationCore)){
SolrInputDocument doc = toSolrInputDocument(conversation);
if(doc != null){
solr.add(doc, commitWithin);
} else { //remove from index
solr.deleteByQuery(getDeleteQuery(conversation),commitWithin);
}
if(commit){
solr.commit();
}
} catch (IOException | SolrServerException e) {
log.warn("Unable to index Conversation {} ({}: {})",conversation.getId(), e.getClass().getSimpleName(), e.getMessage());
log.debug("STACKTRACE",e);
}
}
示例6: solrQuery
import org.apache.solr.client.solrj.SolrClient; //导入依赖的package包/类
protected MCROAISolrResult solrQuery(Optional<String> cursor) throws SolrServerException, IOException {
SolrQuery query = getBaseQuery(CommonParams.Q);
// set support
if (this.set != null) {
String setId = this.set.getSetId();
MCROAISetConfiguration<SolrQuery, SolrDocument, String> setConfig = getSetManager().getConfig(setId);
setConfig.getHandler().apply(this.set, query);
}
// from & until
if (this.from != null || this.until != null) {
String fromUntilCondition = buildFromUntilCondition(this.from, this.until);
query.add(CommonParams.FQ, fromUntilCondition);
}
// cursor
query.set(CursorMarkParams.CURSOR_MARK_PARAM, cursor.orElse(CursorMarkParams.CURSOR_MARK_START));
query.set(CommonParams.ROWS, String.valueOf(getPartitionSize()));
query.set(CommonParams.SORT, "id asc");
// do the query
SolrClient solrClient = MCRSolrClientFactory.getSolrClient();
QueryResponse response = solrClient.query(query);
Collection<MCROAISetResolver<String, SolrDocument>> setResolver = getSetResolver(response.getResults());
return new MCROAISolrResult(response, d -> toHeader(d, setResolver));
}
示例7: filter
import org.apache.solr.client.solrj.SolrClient; //导入依赖的package包/类
@Override
public boolean filter(MCRSet set) {
if (!filterEmptySets()) {
return false;
}
SolrClient solrClient = MCRSolrClientFactory.getSolrClient();
ModifiableSolrParams p = new ModifiableSolrParams();
String value = set.getSpec();
p.set(CommonParams.Q, MCROAIUtils.getDefaultSetQuery(value, getConfigPrefix()));
String restriction = MCROAIUtils.getDefaultRestriction(getConfigPrefix());
if (restriction != null) {
p.set(CommonParams.FQ, restriction);
}
p.set(CommonParams.ROWS, 1);
p.set(CommonParams.FL, "id");
try {
QueryResponse response = solrClient.query(p);
return response.getResults().isEmpty();
} catch (Exception exc) {
LOGGER.error("Unable to get results of solr server", exc);
return true;
}
}
示例8: init
import org.apache.solr.client.solrj.SolrClient; //导入依赖的package包/类
@Override
public void init(String configPrefix, String setId, Map<String, MCRSet> setMap, Collection<SolrDocument> result,
Function<SolrDocument, String> identifier) {
super.init(configPrefix, setId, setMap, result, identifier);
if (result.isEmpty()) {
idsInSet = Collections.emptySet();
return;
}
SolrClient solrClient = MCRSolrClientFactory.getSolrClient();
QueryResponse response;
try {
response = solrClient.query(getQuery());
} catch (SolrServerException | IOException e) {
throw new MCRException("Error while getting set membership.", e);
}
idsInSet = response.getResults().stream().map(getIdentifier()).collect(Collectors.toSet());
}
示例9: filterNonEmpty
import org.apache.solr.client.solrj.SolrClient; //导入依赖的package包/类
private void filterNonEmpty(String classId, Element e) {
SolrClient solrClient = MCRSolrClientFactory.getSolrClient();
for (int i = 0; i < e.getChildren("category").size(); i++) {
Element cat = e.getChildren("category").get(i);
SolrQuery solrQquery = new SolrQuery();
solrQquery.setQuery(
"category:\"" + MCRSolrUtils.escapeSearchValue(classId + ":" + cat.getAttributeValue("ID")) + "\"");
solrQquery.setRows(0);
try {
QueryResponse response = solrClient.query(solrQquery);
SolrDocumentList solrResults = response.getResults();
if (solrResults.getNumFound() == 0) {
e.removeContent(cat);
i--;
}
} catch (SolrServerException | IOException exc) {
LOGGER.error(exc);
}
}
for (int i = 0; i < e.getChildren("category").size(); i++) {
filterNonEmpty(classId, e.getChildren("category").get(i));
}
}
示例10: filter
import org.apache.solr.client.solrj.SolrClient; //导入依赖的package包/类
@GET
@Path("filter/{text}")
@Produces(MediaType.APPLICATION_JSON)
public Response filter(@PathParam("text") String text) {
SolrClient solrClient = MCRSolrClassificationUtil.getCore().getClient();
ModifiableSolrParams p = new ModifiableSolrParams();
p.set("q", "*" + text + "*");
p.set("fl", "id,ancestors");
JsonArray docList = new JsonArray();
MCRSolrSearchUtils.stream(solrClient, p).flatMap(document -> {
List<String> ids = new ArrayList<>();
ids.add(document.getFirstValue("id").toString());
Collection<Object> fieldValues = document.getFieldValues("ancestors");
if (fieldValues != null) {
for (Object anc : fieldValues) {
ids.add(anc.toString());
}
}
return ids.stream();
}).distinct().map(JsonPrimitive::new).forEach(docList::add);
return Response.ok().entity(docList.toString()).build();
}
示例11: rebuildContentIndex
import org.apache.solr.client.solrj.SolrClient; //导入依赖的package包/类
/**
* Rebuilds solr's content index.
*
* @param solrClient
* solr client connection
* @param list
* list of mycore object id's
* @param priority
* higher priority means earlier execution
*/
public static void rebuildContentIndex(SolrClient solrClient, List<String> list, int priority) {
LOGGER.info("Re-building Content Index");
if (list.isEmpty()) {
LOGGER.info("No objects to index");
return;
}
long tStart = System.currentTimeMillis();
int totalCount = list.size();
LOGGER.info("Sending content of {} derivates to solr for reindexing", totalCount);
for (String id : list) {
MCRSolrFilesIndexHandler indexHandler = new MCRSolrFilesIndexHandler(id, solrClient);
indexHandler.setCommitWithin(BATCH_AUTO_COMMIT_WITHIN_MS);
submitIndexHandler(indexHandler, priority);
}
long tStop = System.currentTimeMillis();
MCRSolrIndexStatisticCollector.FILE_TRANSFER.addTime(tStop - tStart);
}
示例12: executeStreamingExpression
import org.apache.solr.client.solrj.SolrClient; //导入依赖的package包/类
public static RStreamingExpressionIterator executeStreamingExpression(SolrClient sc, String collection,
String expression, String[] columnNames) throws IOException, SolrServerException {
if (!checkResponseWriter(sc)) {
log.error("The SolrClient's Response Writer should be: " + InputStreamResponseParser.class.getName());
}
SolrParams sp = new MapSolrParams(Collections.singletonMap("expr", expression));
SolrRequest<?> sr = new GenericSolrRequest(METHOD.POST, "/stream", sp);
NamedList<Object> nl = sc.request(sr, collection);
InputStream stream = (InputStream) nl.get("stream");
InputStreamReader reader = new InputStreamReader(stream, "UTF-8");
if (columnNames == null || columnNames.length == 0) {
return new RStreamingExpressionIterator(reader);
}
return new RStreamingExpressionIterator(reader, columnNames);
}
示例13: checkResponseWriter
import org.apache.solr.client.solrj.SolrClient; //导入依赖的package包/类
private static boolean checkResponseWriter(SolrClient sc) {
if (sc instanceof HttpSolrClient && !(((HttpSolrClient) sc).getParser() instanceof InputStreamResponseParser)) {
return false;
} else if (sc instanceof LBHttpSolrClient
&& !(((LBHttpSolrClient) sc).getParser() instanceof InputStreamResponseParser)) {
return false;
} else if (sc instanceof CloudSolrClient
&& !(((CloudSolrClient) sc).getParser() instanceof InputStreamResponseParser)) {
return false;
}
return true;
}
示例14: fromZookeeperHosts
import org.apache.solr.client.solrj.SolrClient; //导入依赖的package包/类
public static SolrClient fromZookeeperHosts(String zkHostsCommaSeparated, String zkChroot) {
CloudSolrClient.Builder b =
new CloudSolrClient.Builder().withZkHost(Arrays.asList(zkHostsCommaSeparated.split(",")));
if (zkChroot != null && zkChroot.length() > 0) {
b.withZkChroot(zkChroot);
}
CloudSolrClient csc = b.build();
csc.setParser(new InputStreamResponseParser("json"));
return csc;
}
示例15: fromSolrHosts
import org.apache.solr.client.solrj.SolrClient; //导入依赖的package包/类
public static SolrClient fromSolrHosts(String solrHostsCommaSeparated) {
String[] hostArr = solrHostsCommaSeparated.split(",");
if (hostArr.length == 1) {
return new HttpSolrClient.Builder(hostArr[0]).withResponseParser(new InputStreamResponseParser("json"))
.build();
}
return new LBHttpSolrClient.Builder().withBaseSolrUrls(hostArr)
.withResponseParser(new InputStreamResponseParser("json")).build();
}