org.apache.solr.search.DocList Java Examples
The following examples show how to use
org.apache.solr.search.DocList.
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: TaggerRequestHandler.java From SolrTextTagger with Apache License 2.0 | 6 votes |
private DocList getDocList(int rows, FixedBitSet matchDocIdsBS) throws IOException { //Now we must supply a Solr DocList and add it to the response. // Typically this is gotten via a SolrIndexSearcher.search(), but in this case we // know exactly what documents to return, the order doesn't matter nor does // scoring. // Ideally an implementation of DocList could be directly implemented off // of a BitSet, but there are way too many methods to implement for a minor // payoff. int matchDocs = matchDocIdsBS.cardinality(); int[] docIds = new int[ Math.min(rows, matchDocs) ]; DocIdSetIterator docIdIter = new BitSetIterator(matchDocIdsBS, 1); for (int i = 0; i < docIds.length; i++) { docIds[i] = docIdIter.nextDoc(); } return new DocSlice(0, docIds.length, docIds, null, matchDocs, 1f); }
Example #2
Source File: BasicFunctionalityTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testNotLazyField() throws IOException { assertU(adoc("id", "7777", "title", "keyword", "test_hlt", mkstr(20000))); assertU(commit()); SolrCore core = h.getCore(); SolrQueryRequest req = req("q", "id:7777", "fl", "id,title,test_hlt"); SolrQueryResponse rsp = new SolrQueryResponse(); core.execute(core.getRequestHandler(req.getParams().get(CommonParams.QT)), req, rsp); DocList dl = ((ResultContext) rsp.getResponse()).getDocList(); Document d = req.getSearcher().doc(dl.iterator().nextDoc()); // ensure field in fl is not lazy assertFalse( ((Field) d.getField("test_hlt")).getClass().getSimpleName().equals("LazyField")); assertFalse( ((Field) d.getField("title")).getClass().getSimpleName().equals("LazyField")); req.close(); }
Example #3
Source File: UnifiedSolrHighlighter.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public NamedList<Object> doHighlighting(DocList docs, Query query, SolrQueryRequest req, String[] defaultFields) throws IOException { final SolrParams params = req.getParams(); // if highlighting isn't enabled, then why call doHighlighting? if (!isHighlightingEnabled(params)) return null; int[] docIDs = toDocIDs(docs); // fetch the unique keys String[] keys = getUniqueKeys(req.getSearcher(), docIDs); // query-time parameters String[] fieldNames = getHighlightFields(query, req, defaultFields); int maxPassages[] = new int[fieldNames.length]; for (int i = 0; i < fieldNames.length; i++) { maxPassages[i] = params.getFieldInt(fieldNames[i], HighlightParams.SNIPPETS, 1); } UnifiedHighlighter highlighter = getHighlighter(req); Map<String, String[]> snippets = highlighter.highlightFields(fieldNames, query, docIDs, maxPassages); return encodeSnippets(keys, fieldNames, snippets); }
Example #4
Source File: LireRequestHandler.java From liresolr with GNU General Public License v2.0 | 6 votes |
/** * Returns a random set of documents from the index. Mainly for testing purposes. * * @param req * @param rsp * @throws IOException */ private void handleRandomSearch(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException { SolrIndexSearcher searcher = req.getSearcher(); Query query = new MatchAllDocsQuery(); DocList docList = searcher.getDocList(query, getFilterQueries(req), Sort.RELEVANCE, 0, numberOfCandidateResults, 0); int paramRows = Math.min(req.getParams().getInt("rows", defaultNumberOfResults), docList.size()); if (docList.size() < 1) { rsp.add("Error", "No documents in index"); } else { LinkedList list = new LinkedList(); while (list.size() < paramRows) { DocList auxList = docList.subset((int) (Math.random() * docList.size()), 1); Document doc = null; for (DocIterator it = auxList.iterator(); it.hasNext(); ) { doc = searcher.doc(it.nextDoc()); } if (!list.contains(doc)) { list.add(doc); } } rsp.addResponse(list); } }
Example #5
Source File: SolrPluginUtils.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * Executes a basic query */ public static DocList doSimpleQuery(String sreq, SolrQueryRequest req, int start, int limit) throws IOException { List<String> commands = StrUtils.splitSmart(sreq,';'); String qs = commands.size() >= 1 ? commands.get(0) : ""; try { Query query = QParser.getParser(qs, req).getQuery(); // If the first non-query, non-filter command is a simple sort on an indexed field, then // we can use the Lucene sort ability. Sort sort = null; if (commands.size() >= 2) { sort = SortSpecParsing.parseSortSpec(commands.get(1), req).getSort(); } DocList results = req.getSearcher().getDocList(query,(DocSet)null, sort, start, limit); return results; } catch (SyntaxError e) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Error parsing query: " + qs); } }
Example #6
Source File: SolrPluginUtils.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * Generates an NamedList of Explanations for each item in a list of docs. * * @param query The Query you want explanations in the context of * @param docs The Documents you want explained relative that query */ public static NamedList<Explanation> getExplanations (Query query, DocList docs, SolrIndexSearcher searcher, IndexSchema schema) throws IOException { NamedList<Explanation> explainList = new SimpleOrderedMap<>(); DocIterator iterator = docs.iterator(); for (int i=0; i<docs.size(); i++) { int id = iterator.nextDoc(); Document doc = searcher.doc(id); String strid = schema.printableUniqueKey(doc); explainList.add(strid, searcher.explain(query, id) ); } return explainList; }
Example #7
Source File: AnalysisHandler.java From chronix.server with Apache License 2.0 | 6 votes |
/** * Collects the document matching the given solr query request by using the given collection key function. * * @param query the plain solr query * @param req the request object * @param collectionKey the key to collected documents * @return the collected and grouped documents * @throws IOException if bad things happen */ private Map<ChronixType, Map<String, List<SolrDocument>>> collectDocuments(String query, SolrQueryRequest req, CQLJoinFunction collectionKey) throws IOException { //query and collect all documents Set<String> fields = getFields(req.getParams().get(CommonParams.FL), req.getSchema().getFields()); //we always need the data field fields.add(Schema.DATA); //add the involved fields from in the join key if (!isEmptyArray(collectionKey.involvedFields())) { Collections.addAll(fields, collectionKey.involvedFields()); } DocList result = docListProvider.doSimpleQuery(query, req, 0, Integer.MAX_VALUE); SolrDocumentList docs = docListProvider.docListToSolrDocumentList(result, req.getSearcher(), fields, null); return collect(docs, collectionKey); }
Example #8
Source File: ResponseLogComponent.java From lucene-solr with Apache License 2.0 | 6 votes |
@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 #9
Source File: TaggerRequestHandler.java From lucene-solr with Apache License 2.0 | 6 votes |
private DocList getDocList(int rows, FixedBitSet matchDocIdsBS) throws IOException { //Now we must supply a Solr DocList and add it to the response. // Typically this is gotten via a SolrIndexSearcher.search(), but in this case we // know exactly what documents to return, the order doesn't matter nor does // scoring. // Ideally an implementation of DocList could be directly implemented off // of a BitSet, but there are way too many methods to implement for a minor // payoff. int matchDocs = matchDocIdsBS.cardinality(); int[] docIds = new int[ Math.min(rows, matchDocs) ]; DocIdSetIterator docIdIter = new BitSetIterator(matchDocIdsBS, 1); for (int i = 0; i < docIds.length; i++) { docIds[i] = docIdIter.nextDoc(); } return new DocSlice(0, docIds.length, docIds, null, matchDocs, 1f, TotalHits.Relation.EQUAL_TO); }
Example #10
Source File: TestXJoinSearchComponent.java From BioSolr with Apache License 2.0 | 6 votes |
@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 #11
Source File: TestXJoinSearchComponent.java From BioSolr with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("rawtypes") public void testGroupedSimple() { ModifiableSolrParams params = new ModifiableSolrParams(); params.add("group", "true"); params.add("group.field", "colour"); params.add("group.format", "simple"); NamedList results = test(params, "xjoin"); testXJoinResults(results, "xjoin"); NamedList grouped = (NamedList)results.get("grouped"); NamedList colours = (NamedList)grouped.get("colour"); assertEquals(2, colours.get("matches")); DocList docs = (DocList)colours.get("doclist"); assertEquals(docs.size(), 2); DocIterator it = docs.iterator(); assertTrue(it.hasNext()); assertEquals(1, it.nextDoc()); assertTrue(it.hasNext()); assertEquals(3, it.nextDoc()); assertFalse(it.hasNext()); }
Example #12
Source File: TestXJoinSearchComponent.java From BioSolr with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("rawtypes") public void testGroupedSimple() { ModifiableSolrParams params = new ModifiableSolrParams(); params.add("group", "true"); params.add("group.field", "colour"); params.add("group.format", "simple"); NamedList results = test(params, "xjoin"); testXJoinResults(results, "xjoin"); NamedList grouped = (NamedList)results.get("grouped"); NamedList colours = (NamedList)grouped.get("colour"); assertEquals(2, colours.get("matches")); DocList docs = (DocList)colours.get("doclist"); assertEquals(docs.size(), 2); DocIterator it = docs.iterator(); assertTrue(it.hasNext()); assertEquals(1, it.nextDoc()); assertTrue(it.hasNext()); assertEquals(3, it.nextDoc()); assertFalse(it.hasNext()); }
Example #13
Source File: CarrotClusteringEngineTest.java From lucene-solr with Apache License 2.0 | 6 votes |
private List<NamedList<Object>> checkEngine(CarrotClusteringEngine engine, int expectedNumDocs, int expectedNumClusters, Query query, SolrParams clusteringParams) throws IOException { // Get all documents to cluster return h.getCore().withSearcher(searcher -> { DocList docList = searcher.getDocList(query, (Query) null, new Sort(), 0, numberOfDocs); assertEquals("docList size", expectedNumDocs, docList.matches()); ModifiableSolrParams solrParams = new ModifiableSolrParams(); solrParams.add(clusteringParams); // Perform clustering LocalSolrQueryRequest req = new LocalSolrQueryRequest(h.getCore(), solrParams); Map<SolrDocument,Integer> docIds = new HashMap<>(docList.size()); SolrDocumentList solrDocList = ClusteringComponent.docListToSolrDocumentList( docList, searcher, engine.getFieldsToLoad(req), docIds ); @SuppressWarnings("unchecked") List<NamedList<Object>> results = (List<NamedList<Object>>) engine.cluster(query, solrDocList, docIds, req); req.close(); assertEquals("number of clusters: " + results, expectedNumClusters, results.size()); checkClusters(results, false); return results; }); }
Example #14
Source File: TestXJoinSearchComponent.java From BioSolr with Apache License 2.0 | 6 votes |
@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.docs; 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 #15
Source File: TestXJoinSearchComponent.java From BioSolr with Apache License 2.0 | 6 votes |
@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.docs; 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 #16
Source File: TestXJoinSearchComponent.java From BioSolr with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("rawtypes") public void testGroupedSimple() { ModifiableSolrParams params = new ModifiableSolrParams(); params.add("group", "true"); params.add("group.field", "colour"); params.add("group.format", "simple"); NamedList results = test(params, "xjoin"); testXJoinResults(results, "xjoin"); NamedList grouped = (NamedList)results.get("grouped"); NamedList colours = (NamedList)grouped.get("colour"); assertEquals(2, colours.get("matches")); DocList docs = (DocList)colours.get("doclist"); assertEquals(docs.size(), 2); DocIterator it = docs.iterator(); assertTrue(it.hasNext()); assertEquals(1, it.nextDoc()); assertTrue(it.hasNext()); assertEquals(3, it.nextDoc()); assertFalse(it.hasNext()); }
Example #17
Source File: ResponseLogComponent.java From lucene-solr with Apache License 2.0 | 5 votes |
protected void processScores(ResponseBuilder rb, DocList dl, IndexSchema schema, SolrIndexSearcher searcher) throws IOException { StringBuilder sb = new StringBuilder(); Set<String> fields = Collections.singleton(schema.getUniqueKeyField().getName()); for(DocIterator iter = dl.iterator(); iter.hasNext();) { sb.append(schema.printableUniqueKey(searcher.doc(iter.nextDoc(), fields))) .append(':') .append(iter.score()) .append(','); } if (sb.length() > 0) { rb.rsp.addToLog("responseLog", sb.substring(0, sb.length() - 1)); } }
Example #18
Source File: DummyHighlighter.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings({"unchecked", "rawtypes"}) public NamedList<Object> doHighlighting(DocList docs, Query query, SolrQueryRequest req, String[] defaultFields) throws IOException { NamedList fragments = new SimpleOrderedMap(); fragments.add("dummy", "thing1"); return fragments; }
Example #19
Source File: UnifiedSolrHighlighter.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Converts solr's DocList to the int[] docIDs */ protected int[] toDocIDs(DocList docs) { int[] docIDs = new int[docs.size()]; DocIterator iterator = docs.iterator(); for (int i = 0; i < docIDs.length; i++) { if (!iterator.hasNext()) { throw new AssertionError(); } docIDs[i] = iterator.nextDoc(); } if (iterator.hasNext()) { throw new AssertionError(); } return docIDs; }
Example #20
Source File: Cloud.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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 #21
Source File: TestSimple.java From BioSolr with Apache License 2.0 | 5 votes |
@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.docs; 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")); }
Example #22
Source File: SolrPluginUtils.java From lucene-solr with Apache License 2.0 | 5 votes |
@SuppressWarnings({"unchecked"}) public static void doStandardResultsDebug( SolrQueryRequest req, Query query, DocList results, boolean dbgResults, @SuppressWarnings({"rawtypes"})NamedList dbg) throws IOException { if (dbgResults) { SolrIndexSearcher searcher = req.getSearcher(); IndexSchema schema = searcher.getSchema(); boolean explainStruct = req.getParams().getBool(CommonParams.EXPLAIN_STRUCT, false); if (results != null) { NamedList<Explanation> explain = getExplanations(query, results, searcher, schema); dbg.add("explain", explainStruct ? explanationsToNamedLists(explain) : explanationsToStrings(explain)); } String otherQueryS = req.getParams().get(CommonParams.EXPLAIN_OTHER); if (otherQueryS != null && otherQueryS.length() > 0) { DocList otherResults = doSimpleQuery(otherQueryS, req, 0, 10); dbg.add("otherQuery", otherQueryS); NamedList<Explanation> explainO = getExplanations(query, otherResults, searcher, schema); dbg.add("explainOther", explainStruct ? explanationsToNamedLists(explainO) : explanationsToStrings(explainO)); } } }
Example #23
Source File: XJoinSearchComponent.java From BioSolr with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) private Iterator<Integer> docIterator(ResponseBuilder rb) { if (rb.grouping()) { List<Integer> docList = new ArrayList<>(); NamedList values = rb.rsp.getValues(); NamedList grouped = (NamedList)values.get("grouped"); for (String field : rb.getGroupingSpec().getFields()) { NamedList fieldResults = (NamedList)grouped.get(field); if (rb.getGroupingSpec().getResponseFormat() == Grouping.Format.grouped) { List<NamedList> groups = (List<NamedList>)fieldResults.get("groups"); for (NamedList group : groups) { for (DocIterator it = ((DocList)group.get("doclist")).iterator(); it.hasNext(); ) { docList.add(it.nextDoc()); } } } else { for (DocIterator it = ((DocList)fieldResults.get("doclist")).iterator(); it.hasNext(); ) { docList.add(it.nextDoc()); } } } return docList.iterator(); } else { return rb.getResults().docList.iterator(); } }
Example #24
Source File: SolrPluginUtils.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Pre-fetch documents into the index searcher's document cache. * * This is an entirely optional step which you might want to perform for * the following reasons: * * <ul> * <li>Locates the document-retrieval costs in one spot, which helps * detailed performance measurement</li> * * <li>Determines a priori what fields will be needed to be fetched by * various subtasks, like response writing and highlighting. This * minimizes the chance that many needed fields will be loaded lazily. * (it is more efficient to load all the field we require normally).</li> * </ul> * * If lazy field loading is disabled, this method does nothing. */ public static void optimizePreFetchDocs(ResponseBuilder rb, DocList docs, Query query, SolrQueryRequest req, SolrQueryResponse res) throws IOException { SolrIndexSearcher searcher = req.getSearcher(); if(!searcher.getDocFetcher().isLazyFieldLoadingEnabled()) { // nothing to do return; } ReturnFields returnFields = res.getReturnFields(); if(returnFields.getLuceneFieldNames() != null) { Set<String> fieldFilter = returnFields.getLuceneFieldNames(); if (rb.doHighlights) { // copy return fields list fieldFilter = new HashSet<>(fieldFilter); // add highlight fields SolrHighlighter highlighter = HighlightComponent.getHighlighter(req.getCore()); for (String field: highlighter.getHighlightFields(query, req, null)) fieldFilter.add(field); // fetch unique key if one exists. SchemaField keyField = searcher.getSchema().getUniqueKeyField(); if(null != keyField) fieldFilter.add(keyField.getName()); } // get documents DocIterator iter = docs.iterator(); for (int i=0; i<docs.size(); i++) { searcher.doc(iter.nextDoc(), fieldFilter); } } }
Example #25
Source File: PageTool.java From lucene-solr with Apache License 2.0 | 5 votes |
public PageTool(SolrQueryRequest request, SolrQueryResponse response) { String rows = request.getParams().get("rows"); if (rows != null) { results_per_page = Integer.parseInt(rows); } //TODO: Handle group by results Object docs = response.getResponse(); if (docs != null) { if (docs instanceof DocSlice) { results_found = ((DocSlice) docs).matches(); start = ((DocSlice) docs).offset(); } else if(docs instanceof ResultContext) { DocList dl = ((ResultContext) docs).getDocList(); results_found = dl.matches(); start = dl.offset(); } else if(docs instanceof SolrDocumentList) { SolrDocumentList doc_list = (SolrDocumentList) docs; results_found = doc_list.getNumFound(); start = doc_list.getStart(); } else { throw new SolrException(SolrException.ErrorCode.UNKNOWN, "Unknown response type "+docs+". Expected one of DocSlice, ResultContext or SolrDocumentList"); } } page_count = (int) Math.ceil(results_found / (double) results_per_page); current_page_number = (int) Math.ceil(start / (double) results_per_page) + (page_count > 0 ? 1 : 0); }
Example #26
Source File: ResponseLogComponent.java From lucene-solr with Apache License 2.0 | 5 votes |
protected void processIds(ResponseBuilder rb, DocList dl, IndexSchema schema, SolrIndexSearcher searcher) throws IOException { StringBuilder sb = new StringBuilder(); Set<String> fields = Collections.singleton(schema.getUniqueKeyField().getName()); for(DocIterator iter = dl.iterator(); iter.hasNext();) { sb.append(schema.printableUniqueKey(searcher.doc(iter.nextDoc(), fields))) .append(','); } if (sb.length() > 0) { rb.rsp.addToLog("responseLog", sb.substring(0, sb.length() - 1)); } }
Example #27
Source File: TestSimple.java From BioSolr with Apache License 2.0 | 5 votes |
@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.docs; 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")); }
Example #28
Source File: TextResponseWriter.java From lucene-solr with Apache License 2.0 | 5 votes |
public final void writeDocuments(String name, ResultContext res) throws IOException { DocList ids = res.getDocList(); Iterator<SolrDocument> docsStreamer = res.getProcessedDocuments(); writeStartDocumentList(name, ids.offset(), ids.size(), ids.matches(), res.wantsScores() ? ids.maxScore() : null, ids.hitCountRelation() == TotalHits.Relation.EQUAL_TO); int idx = 0; while (docsStreamer.hasNext()) { writeSolrDocument(null, docsStreamer.next(), res.getReturnFields(), idx); idx++; } writeEndDocumentList(); }
Example #29
Source File: XJoinSearchComponent.java From BioSolr with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) private Iterator<Integer> docIterator(ResponseBuilder rb) { if (rb.grouping()) { List<Integer> docList = new ArrayList<>(); NamedList values = rb.rsp.getValues(); NamedList grouped = (NamedList)values.get("grouped"); for (String field : rb.getGroupingSpec().getFields()) { NamedList fieldResults = (NamedList)grouped.get(field); if (rb.getGroupingSpec().getResponseFormat() == Grouping.Format.grouped) { List<NamedList> groups = (List<NamedList>)fieldResults.get("groups"); for (NamedList group : groups) { for (DocIterator it = ((DocList)group.get("doclist")).iterator(); it.hasNext(); ) { docList.add(it.nextDoc()); } } } else { for (DocIterator it = ((DocList)fieldResults.get("doclist")).iterator(); it.hasNext(); ) { docList.add(it.nextDoc()); } } } return docList.iterator(); } else { return rb.getResults().docList.iterator(); } }
Example #30
Source File: TestSimple.java From BioSolr with Apache License 2.0 | 5 votes |
@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")); }