Java Code Examples for org.apache.solr.response.ResultContext#getDocList()

The following examples show how to use org.apache.solr.response.ResultContext#getDocList() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Cloud.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
     * 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;
    }
 
Example 2
Source File: ResponseLogComponent.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void process(ResponseBuilder rb) throws IOException {
  SolrParams params = rb.req.getParams();
  if (!params.getBool(COMPONENT_NAME, false)) return;
  
  SolrIndexSearcher searcher = rb.req.getSearcher();
  IndexSchema schema = searcher.getSchema();
  if (schema.getUniqueKeyField() == null) return;

  ResultContext rc = (ResultContext) rb.rsp.getResponse();

  DocList docs = rc.getDocList();
  if (docs.hasScores()) {
    processScores(rb, docs, schema, searcher);
  } else {
    processIds(rb, docs, schema, searcher);
  }
}
 
Example 3
Source File: TestXJoinSearchComponent.java    From BioSolr with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("rawtypes")
public void testUngrouped() {
  ModifiableSolrParams params = new ModifiableSolrParams();
  NamedList results = test(params, "xjoin");
  testXJoinResults(results, "xjoin");
  ResultContext response = (ResultContext)results.get("response");
  DocList docs = response.getDocList();
  assertEquals(2, docs.size());
  DocIterator it = docs.iterator();
  assertTrue(it.hasNext());
  assertEquals(1, it.nextDoc());
  assertTrue(it.hasNext());
  assertEquals(3, it.nextDoc());
  assertFalse(it.hasNext());
}
 
Example 4
Source File: Cloud.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns the doc list resulting from running the 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 docs
 * @return the docs that come back from the query
 */
DocList getDocList(SolrRequestHandler requestHandler, SolrQueryRequest request, String query)
{
    // Getting the doc list is shard-specific, and not really cloud-friendly
    
    ModifiableSolrParams params = new ModifiableSolrParams(request.getParams());
    // Sets MAX_VALUE to get all the rows
    params.set("q", query).set("fl", QueryConstants.FIELD_SOLR4_ID).set("rows", Integer.MAX_VALUE);
    ResultContext rc = this.getResultContext(requestHandler, request, params);
    return rc != null ? rc.getDocList() : null;
}
 
Example 5
Source File: TestSimple.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("rawtypes")
public void testSimpleXJoinResultsFactory() {
  ModifiableSolrParams params = new ModifiableSolrParams();
  params.add("fl", "*, score");
  params.add("xjoin", "false");
  params.add("xjoin5", "true");
  params.add("xjoin5.fl", "*");
  
  // score boosts using value source parser
  params.add("defType", "edismax");
  params.add("bf", "xjoin5(value)");
  
  NamedList results = test(params, "xjoin5");
  ResultContext response = (ResultContext)results.get("response");
  DocList docs = response.getDocList();
  assertEquals(2, docs.size());
  DocIterator it = docs.iterator();
  assertTrue(it.hasNext());
  assertEquals(0, it.nextDoc());
  double score0 = it.score();
  assertTrue(it.hasNext());
  assertEquals(2, it.nextDoc());
  double score2 = it.score();
  assertFalse(it.hasNext());
 
  // bf score boost for testid=0 only
  assertTrue(score0 > score2);
  
  List externalList = (List)((NamedList)results.get("xjoin5")).get("external");
  NamedList hit0 = (NamedList)externalList.get(0);
  assertEquals("0", hit0.get("joinId"));
  NamedList doc0 = (NamedList)hit0.get("doc");
  assertEquals("red", doc0.get("colour"));
  assertEquals(10.5, doc0.get("value"));
}