本文整理汇总了Java中org.apache.solr.client.solrj.SolrClient.query方法的典型用法代码示例。如果您正苦于以下问题:Java SolrClient.query方法的具体用法?Java SolrClient.query怎么用?Java SolrClient.query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.solr.client.solrj.SolrClient
的用法示例。
在下文中一共展示了SolrClient.query方法的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: getHeader
import org.apache.solr.client.solrj.SolrClient; //导入方法依赖的package包/类
@Override
public Optional<Header> getHeader(String mcrId) {
SolrQuery query = getBaseQuery(CommonParams.FQ);
query.set(CommonParams.Q, "id:" + MCRSolrUtils.escapeSearchValue(mcrId));
query.setRows(1);
// do the query
SolrClient solrClient = MCRSolrClientFactory.getSolrClient();
try {
QueryResponse response = solrClient.query(query);
SolrDocumentList results = response.getResults();
if (!results.isEmpty()) {
return Optional.of(toHeader(results.get(0), getSetResolver(results)));
}
} catch (Exception exc) {
LOGGER.error("Unable to handle solr request", exc);
}
return Optional.empty();
}
示例3: 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));
}
示例4: getEarliestTimestamp
import org.apache.solr.client.solrj.SolrClient; //导入方法依赖的package包/类
@Override
public Optional<Instant> getEarliestTimestamp() {
String sortBy = getConfig().getString(getConfigPrefix() + "EarliestDatestamp.SortBy", "modified asc");
String fieldName = getConfig().getString(getConfigPrefix() + "EarliestDatestamp.FieldName", "modified");
String restriction = getConfig().getString(getConfigPrefix() + "Search.Restriction", null);
ModifiableSolrParams params = new ModifiableSolrParams();
params.add(CommonParams.SORT, sortBy);
params.add(CommonParams.Q, restriction);
params.add(CommonParams.FQ, fieldName + ":[* TO *]");
params.add(CommonParams.FL, fieldName);
params.add(CommonParams.ROWS, "1");
SolrClient solrClient = MCRSolrClientFactory.getSolrClient();
try {
QueryResponse response = solrClient.query(params);
SolrDocumentList list = response.getResults();
if (list.size() >= 1) {
Date date = (Date) list.get(0).getFieldValue(fieldName);
return Optional.of(date.toInstant());
}
} catch (Exception exc) {
LOGGER.error("Unable to handle solr request", exc);
}
return Optional.empty();
}
示例5: 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;
}
}
示例6: 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());
}
示例7: 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));
}
}
示例8: IterableSearchResult
import org.apache.solr.client.solrj.SolrClient; //导入方法依赖的package包/类
/**
* Creates a new SearchResult.
* @param client Solr client instance.
* @param query to perform.
* @throws SolrServerException Solr client exception.
* @throws IOException network exception.
*/
public IterableSearchResult(SolrClient client, SolrQuery query)
throws SolrServerException, IOException
{
Objects.requireNonNull(client);
Objects.requireNonNull(query);
this.client = client;
this.query = query;
this.query.setRows(FETCH_SIZE);
rsp = client.query(this.query, SolrRequest.METHOD.POST);
}
示例9: getQuerySuggestions
import org.apache.solr.client.solrj.SolrClient; //导入方法依赖的package包/类
private void getQuerySuggestions( String fieldPattern, SuggestionProcessor suggestProcessor ) throws Exception {
LOG.info( "PivotFacetQueryCollector.getQuerySuggestions " + fieldPattern );
String pivotFields = getPivotFields( fieldPattern );
LOG.info( "pivotFields = " + pivotFields );
ModifiableSolrParams params = new ModifiableSolrParams( );
HashMap<String,String> qParams = parseQuery( this.query );
for (String param : qParams.keySet( ) ) {
params.set( param, qParams.get( param ) );
}
params.set( "facet", "true" );
params.set( "facet.pivot", pivotFields );
params.set( "facet.mincount", "1" );
params.set( "rows", "0" ); // just want the facets
params.set( "facet.limit", "-1" );
if (patternFilterMap != null && patternFilterMap.get( fieldPattern ) != null ) {
LOG.info( "Adding filter query: " + patternFilterMap.get( fieldPattern ) );
params.set( "fq", patternFilterMap.get( fieldPattern ));
}
try {
SolrClient client = getSolrClient( );
LOG.info( "got Solr Client " + client );
LOG.info( "querying collection " + this.collection );
QueryResponse resp = client.query( this.collection, params );
getQuerySuggestions( resp, fieldPattern, suggestProcessor );
}
catch( SolrServerException sse ) {
LOG.info( "Got SolorServerException: " + sse );
throw new Exception( "Got SolrServerException: " + sse.getMessage( ) );
}
catch( IOException ioe ) {
throw new Exception( "Got IOException: " + ioe.getMessage( ) );
}
}
示例10: retrieveLinkedObjects
import org.apache.solr.client.solrj.SolrClient; //导入方法依赖的package包/类
@GET
@Path("link/{id}")
@Produces(MediaType.APPLICATION_JSON)
public Response retrieveLinkedObjects(@PathParam("id") String id, @QueryParam("start") Integer start,
@QueryParam("rows") Integer rows) throws SolrServerException, IOException {
// do solr query
SolrClient solrClient = MCRSolrClientFactory.getSolrClient();
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("start", start != null ? start : 0);
params.set("rows", rows != null ? rows : 50);
params.set("fl", "id");
String configQuery = MCRConfiguration.instance().getString("MCR.Module-solr.linkQuery", "category.top:{0}");
String query = MessageFormat.format(configQuery, id.replaceAll(":", "\\\\:"));
params.set("q", query);
QueryResponse solrResponse = solrClient.query(params);
SolrDocumentList solrResults = solrResponse.getResults();
// build json response
JsonObject response = new JsonObject();
response.addProperty("numFound", solrResults.getNumFound());
response.addProperty("start", solrResults.getStart());
JsonArray docList = new JsonArray();
for (SolrDocument doc : solrResults) {
docList.add(new JsonPrimitive((String) doc.getFieldValue("id")));
}
response.add("docs", docList);
return Response.ok().entity(response.toString()).build();
}
示例11: fetchExistingOrCreateNewSolrDoc
import org.apache.solr.client.solrj.SolrClient; //导入方法依赖的package包/类
private static SolrInputDocument fetchExistingOrCreateNewSolrDoc(SolrClient solr, String id) throws SolrServerException, IOException {
countCreatedAcDocs++;
if (!mergingWithOldDocsEnabled) {
// if disabled, always use fresh document and override older docs with the same phrase
return new SolrInputDocument();
}
if (id.equals("")) {
return new SolrInputDocument();
}
Map<String, String> p = new HashMap<String, String>();
p.put("q", PHRASE + ":\"" + ClientUtils.escapeQueryChars(id) + "\"");
long t1 = System.currentTimeMillis();
SolrParams params = new MapSolrParams(p);
QueryResponse res = solr.query(params);
totalSearchTime += (System.currentTimeMillis() - t1);
if (res.getResults().size() == 0) {
// System.out.println("Document for phrase " + id + " NOT FOUND");
countDistinctNewDocs++;
return new SolrInputDocument();
} else if (res.getResults().size() == 1) {
SolrDocument doc = res.getResults().get(0);
SolrInputDocument tmp = new SolrInputDocument();
// System.out.println("Document for phrase " + id + " found");
for (String fieldName : doc.getFieldNames()) {
tmp.addField(fieldName, doc.getFieldValue(fieldName));
}
return tmp;
} else {
throw new IllegalStateException("Query with params : " + p + " returned more than 1 hit!");
}
}
示例12: query
import org.apache.solr.client.solrj.SolrClient; //导入方法依赖的package包/类
SearchResult query(Document document, SolrUrl solrUrl, SolrClient solrClient) {
SolrQuery solrQuery = new SolrQuery();
Map<String, String> valueMap = new HashMap<String, String>();
String queryString = document.getFieldValue("query");
valueMap.put("query", queryString);
StrSubstitutor strSubstitutor = new StrSubstitutor(valueMap);
for(Map<String, String> map : solrUrl.getQuery()) {
for(String key: map.keySet()) {
String value = map.get(key);
value = strSubstitutor.replace(value);
solrQuery.add(key, value);
}
}
SearchResult searchResult = new SearchResult();
try {
QueryResponse response = solrClient.query(solrQuery);
searchResult.setResponseTime(response.getQTime());
searchResult.setNumFound(response.getResults().getNumFound());
searchResult.setQuery(queryString);
Iterator<SolrDocument> resultIterator = response.getResults().iterator();
int position = 0;
while(resultIterator.hasNext()) {
SolrDocument solrDocument = resultIterator.next();
String id = (String) solrDocument.getFieldValue("id");
Result result = new Result(id,position++);
searchResult.getResultList().add(result);
}
} catch (Exception e) {
if(failOnError) {
throw new RuntimeException(e);
} else {
searchResult.setValid(false);
searchResult.setErrorMessage(e.getMessage());
}
}
return searchResult;
}
示例13: firstHandlerMatch
import org.apache.solr.client.solrj.SolrClient; //导入方法依赖的package包/类
@Test
public void firstHandlerMatch() throws Exception {
final SolrClient searcher = getSolrClient();
final String query = "Apache Solr";
final QueryResponse response = searcher.query(new SolrQuery(query));
assertEquals(1, response.getResults().getNumFound());
final SolrDocument match = response.getResults().iterator().next();
assertEquals("1",match.getFieldValue("id"));
assertNull(match.getFieldValue("title"));
assertNull(match.getFieldValue("author"));
}
示例14: secondHandlerMatch
import org.apache.solr.client.solrj.SolrClient; //导入方法依赖的package包/类
@Test
public void secondHandlerMatch() throws Exception {
final SolrClient searcher = getSolrClient();
final String query = "Solr books";
final QueryResponse response = searcher.query(new SolrQuery(query));
assertEquals(1, response.getResults().getNumFound());
final SolrDocument match = response.getResults().iterator().next();
assertEquals("Apache Solr Essentials", match.getFieldValue("title"));
assertNull(match.getFieldValue("id"));
assertNull(match.getFieldValue("author"));
}
示例15: thirdHandlerMatch
import org.apache.solr.client.solrj.SolrClient; //导入方法依赖的package包/类
@Test
public void thirdHandlerMatch() throws Exception {
final SolrClient searcher = getSolrClient();
final String query = "Andrea Gazzarini";
final QueryResponse response = searcher.query(new SolrQuery(query));
assertEquals(1, response.getResults().getNumFound());
final SolrDocument match = response.getResults().iterator().next();
assertEquals("Andrea Gazzarini", match.getFieldValue("author"));
assertNull(match.getFieldValue("id"));
assertNull(match.getFieldValue("title"));
}