List of usage examples for org.apache.solr.response ResultContext getDocList
public abstract DocList getDocList();
From source file:org.alfresco.solr.Cloud.java
License:Open Source License
/** * 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 *//*from w w w . ja v a 2 s .co m*/ 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; }
From source file:org.alfresco.solr.Cloud.java
License:Open Source License
/** * 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 */// w w w . j a v a 2s. c o m 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; }
From source file:org.alfresco.solr.query.AlfrescoReRankQParserPluginTest.java
License:Open Source License
@Test public void testScale() throws Exception { assertU(delQ("*:*")); assertU(commit());/*from w ww .j a va 2 s. c o m*/ String[] doc = { "id", "1", "term_s", "YYYY", "group_s", "group1", "test_ti", "5", "test_tl", "10", "test_tf", "2000" }; assertU(adoc(doc)); assertU(commit()); String[] doc1 = { "id", "2", "term_s", "YYYY", "group_s", "group1", "test_ti", "50", "test_tl", "100", "test_tf", "200" }; assertU(adoc(doc1)); String[] doc2 = { "id", "3", "term_s", "YYYY", "test_ti", "5000", "test_tl", "100", "test_tf", "200" }; assertU(adoc(doc2)); assertU(commit()); String[] doc3 = { "id", "4", "term_s", "YYYY", "test_ti", "500", "test_tl", "1000", "test_tf", "2000" }; assertU(adoc(doc3)); String[] doc4 = { "id", "5", "term_s", "YYYY", "group_s", "group2", "test_ti", "4", "test_tl", "10", "test_tf", "2000" }; assertU(adoc(doc4)); assertU(commit()); String[] doc5 = { "id", "6", "term_s", "YYYY", "group_s", "group2", "test_ti", "10", "test_tl", "100", "test_tf", "200" }; assertU(adoc(doc5)); assertU(commit()); //Calculate the scales manually ModifiableSolrParams params = new ModifiableSolrParams(); params.add("rq", "{!alfrescoReRank reRankQuery=$rqq reRankDocs=200 scale=false}"); params.add("df", "TEXT"); params.add("q", "term_s:YYYY"); params.add("rqq", "{!edismax bf=$bff}id:(1 2 4 5 6)"); params.add("bff", "field(test_ti)"); params.add("fl", "id,score"); params.add("start", "0"); params.add("rows", "6"); SolrQueryRequest req = req(params); SolrQueryResponse res = null; try { res = queryAndResponse(null, req); } finally { req.close(); } @SuppressWarnings("rawtypes") NamedList vals = res.getValues(); ResultContext resultContext = (ResultContext) vals.get("response"); DocList docs = resultContext.getDocList(); DocIterator it = docs.iterator(); float max = -Float.MAX_VALUE; List<Float> scores = new ArrayList<Float>(); while (it.hasNext()) { it.next(); float score = it.score(); max = Math.max(score, max); scores.add(score); } float[] scaledScores = new float[scores.size()]; for (int i = 0; i < scaledScores.length; i++) { float score = scores.get(i); if (i < 5) { //The first 5 docs are hit on the reRanker so add 1 to score scaledScores[i] = (score / max) + 1; } else { //The last score is not a hit on the reRanker scaledScores[i] = (score / max); } } //Get the scaled scores from the reRanker params = new ModifiableSolrParams(); params.add("rq", "{!alfrescoReRank reRankQuery=$rqq reRankDocs=200 scale=true}"); params.add("df", "TEXT"); params.add("q", "term_s:YYYY"); params.add("rqq", "{!edismax bf=$bff}id:(1 2 4 5 6)"); params.add("bff", "field(test_ti)"); params.add("fl", "id,score"); params.add("start", "0"); params.add("rows", "6"); req = req(params); try { res = queryAndResponse(null, req); } finally { req.close(); } vals = res.getValues(); resultContext = (ResultContext) vals.get("response"); docs = resultContext.getDocList(); it = docs.iterator(); int index = 0; while (it.hasNext()) { it.next(); float score = it.score(); float scaledScore = scaledScores[index++]; Assert.assertEquals("score should be equal to scaled score", score, scaledScore, 0.00001); } req.close(); }
From source file:org.alfresco.solr.SolrInformationServer.java
License:Open Source License
private int getDocListSize(String query) { try (SolrQueryRequest request = this.newSolrQueryRequest()) { ModifiableSolrParams params = new ModifiableSolrParams(request.getParams()).set(CommonParams.Q, query) .set(CommonParams.ROWS, 0); ResultContext resultContext = cloud.getResultContext(nativeRequestHandler, request, params); return resultContext.getDocList().matches(); }/*from www . j a va2 s .c om*/ }