當前位置: 首頁>>代碼示例>>Java>>正文


Java SolrClient.query方法代碼示例

本文整理匯總了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"));
}
 
開發者ID:RBMHTechnology,項目名稱:vind,代碼行數:25,代碼來源:TestServerTest.java

示例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();
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:19,代碼來源:MCROAISolrSearcher.java

示例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));
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:27,代碼來源:MCROAISolrSearcher.java

示例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();
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:25,代碼來源:MCROAISolrSearcher.java

示例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;
    }
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:24,代碼來源:MCROAIClassificationToSetHandler.java

示例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());
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:18,代碼來源:MCROAIQuerySetResolver.java

示例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));
    }
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:25,代碼來源:MCRRestAPIClassifications.java

示例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);
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:21,代碼來源:SolrDao.java

示例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( ) );
  }
}
 
開發者ID:detnavillus,項目名稱:multifield_suggester_code,代碼行數:38,代碼來源:PivotFacetQueryCollector.java

示例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();
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:28,代碼來源:MCRClassificationEditorResource.java

示例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!");
  }
}
 
開發者ID:sematext,項目名稱:solr-autocomplete,代碼行數:40,代碼來源:CustomIndexLoader.java

示例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;
}
 
開發者ID:tblsoft,項目名稱:solr-cmd-utils,代碼行數:43,代碼來源:SolrCompareFilter.java

示例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"));
  }
 
開發者ID:spaziocodice,項目名稱:invisible-queries-request-handler,代碼行數:14,代碼來源:FacadeRequestHandler_IT.java

示例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"));
  }
 
開發者ID:spaziocodice,項目名稱:invisible-queries-request-handler,代碼行數:14,代碼來源:FacadeRequestHandler_IT.java

示例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"));
  }
 
開發者ID:spaziocodice,項目名稱:invisible-queries-request-handler,代碼行數:14,代碼來源:FacadeRequestHandler_IT.java


注:本文中的org.apache.solr.client.solrj.SolrClient.query方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。