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;
}
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();
}
}
}
Aggregations