Search in sources :

Example 16 with ResultContext

use of org.apache.solr.response.ResultContext in project SearchServices by Alfresco.

the class Cloud method exists.

/**
 * Returns whether or not a doc exists that satisfies the specified query
 * @param requestHandler the handler that handles the request
 * @param request the request object to put the query on
 * @param query the string that specifies the doc
 * @return <code>true</code> if the specified query returns a doc
 */
boolean exists(SolrRequestHandler requestHandler, SolrQueryRequest request, String query) {
    ModifiableSolrParams params = new ModifiableSolrParams(request.getParams());
    // Sets 1 because this is effectively a boolean query to see if there exists a single match
    params.set("q", query).set("fl", "id").set("rows", "1");
    ResultContext rc = this.getResultContext(requestHandler, request, params);
    if (rc != null) {
        // TODO Should we use rc.docs.matches() instead?
        if (rc.getDocList() != null) {
            return rc.getDocList().iterator().hasNext();
        }
    }
    return false;
}
Also used : ResultContext(org.apache.solr.response.ResultContext) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 17 with ResultContext

use of org.apache.solr.response.ResultContext in project SearchServices by Alfresco.

the class SolrInformationServer method getDocListSize.

private int getDocListSize(String query) {
    SolrQueryRequest request = null;
    try {
        request = this.getLocalSolrQueryRequest();
        ModifiableSolrParams params = new ModifiableSolrParams(request.getParams());
        params.set("q", query);
        // Sets the rows to zero, because we actually just want the count
        params.set("rows", 0);
        ResultContext resultContext = cloud.getResultContext(nativeRequestHandler, request, params);
        int matches = resultContext.getDocList().matches();
        return matches;
    } finally {
        if (request != null) {
            request.close();
        }
    }
}
Also used : ResultContext(org.apache.solr.response.ResultContext) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Aggregations

ResultContext (org.apache.solr.response.ResultContext)17 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)10 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)10 DocList (org.apache.solr.search.DocList)9 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)8 NamedList (org.apache.solr.common.util.NamedList)6 SolrDocumentList (org.apache.solr.common.SolrDocumentList)5 SolrException (org.apache.solr.common.SolrException)5 SolrParams (org.apache.solr.common.params.SolrParams)5 DocIterator (org.apache.solr.search.DocIterator)5 Document (org.apache.lucene.document.Document)4 SolrCore (org.apache.solr.core.SolrCore)4 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)4 SolrIndexSearcher (org.apache.solr.search.SolrIndexSearcher)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 SolrRequestInfo (org.apache.solr.request.SolrRequestInfo)3 SchemaField (org.apache.solr.schema.SchemaField)3 IOException (java.io.IOException)2