org.apache.lucene.search.MultiCollector Java Examples
The following examples show how to use
org.apache.lucene.search.MultiCollector.
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: Grouping.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override protected Collector createFirstPassCollector() throws IOException { DocSet groupFilt = searcher.getDocSet(query); int groupDocsToCollect = getMax(groupOffset, docsPerGroup, maxDoc); Collector subCollector; if (withinGroupSort == null || withinGroupSort.equals(Sort.RELEVANCE)) { subCollector = topCollector = TopScoreDocCollector.create(groupDocsToCollect, Integer.MAX_VALUE); } else { topCollector = TopFieldCollector.create(searcher.weightSort(withinGroupSort), groupDocsToCollect, Integer.MAX_VALUE); if (needScores) { maxScoreCollector = new MaxScoreCollector(); subCollector = MultiCollector.wrap(topCollector, maxScoreCollector); } else { subCollector = topCollector; } } collector = new FilterCollector(groupFilt, subCollector); return collector; }
Example #2
Source File: CommandHandler.java From lucene-solr with Apache License 2.0 | 6 votes |
private DocSet computeGroupedDocSet(Query query, ProcessedFilter filter, List<Collector> collectors) throws IOException { @SuppressWarnings({"rawtypes"}) Command firstCommand = commands.get(0); String field = firstCommand.getKey(); SchemaField sf = searcher.getSchema().getField(field); FieldType fieldType = sf.getType(); @SuppressWarnings({"rawtypes"}) final AllGroupHeadsCollector allGroupHeadsCollector; if (fieldType.getNumberType() != null) { ValueSource vs = fieldType.getValueSource(sf, null); allGroupHeadsCollector = AllGroupHeadsCollector.newCollector(new ValueSourceGroupSelector(vs, new HashMap<>()), firstCommand.getWithinGroupSort()); } else { allGroupHeadsCollector = AllGroupHeadsCollector.newCollector(new TermGroupSelector(firstCommand.getKey()), firstCommand.getWithinGroupSort()); } if (collectors.isEmpty()) { searchWithTimeLimiter(query, filter, allGroupHeadsCollector); } else { collectors.add(allGroupHeadsCollector); searchWithTimeLimiter(query, filter, MultiCollector.wrap(collectors.toArray(new Collector[collectors.size()]))); } return new BitDocSet(allGroupHeadsCollector.retrieveGroupHeads(searcher.maxDoc())); }
Example #3
Source File: QueryCommand.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public List<Collector> create() throws IOException { Collector subCollector; if (sort == null || sort.equals(Sort.RELEVANCE)) { subCollector = topDocsCollector = TopScoreDocCollector.create(docsToCollect, Integer.MAX_VALUE); } else { topDocsCollector = TopFieldCollector.create(sort, docsToCollect, Integer.MAX_VALUE); if (needScores) { maxScoreCollector = new MaxScoreCollector(); subCollector = MultiCollector.wrap(topDocsCollector, maxScoreCollector); } else { subCollector = topDocsCollector; } } filterCollector = new FilterCollector(docSet, subCollector); return Arrays.asList((Collector) filterCollector); }
Example #4
Source File: CommandHandler.java From lucene-solr with Apache License 2.0 | 5 votes |
private DocSet computeDocSet(Query query, ProcessedFilter filter, List<Collector> collectors) throws IOException { int maxDoc = searcher.maxDoc(); final DocSetCollector docSetCollector = new DocSetCollector(maxDoc); List<Collector> allCollectors = new ArrayList<>(collectors); allCollectors.add(docSetCollector); searchWithTimeLimiter(query, filter, MultiCollector.wrap(allCollectors)); return DocSetUtil.getDocSet( docSetCollector, searcher ); }
Example #5
Source File: CommandHandler.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Invokes search with the specified filter and collector. * If a time limit has been specified then wrap the collector in the TimeLimitingCollector */ private void searchWithTimeLimiter(Query query, ProcessedFilter filter, Collector collector) throws IOException { if (queryCommand.getTimeAllowed() > 0 ) { collector = new TimeLimitingCollector(collector, TimeLimitingCollector.getGlobalCounter(), queryCommand.getTimeAllowed()); } TotalHitCountCollector hitCountCollector = new TotalHitCountCollector(); if (includeHitCount) { collector = MultiCollector.wrap(collector, hitCountCollector); } query = QueryUtils.combineQueryAndFilter(query, filter.filter); if (filter.postFilter != null) { filter.postFilter.setLastDelegate(collector); collector = filter.postFilter; } try { searcher.search(query, collector); } catch (TimeLimitingCollector.TimeExceededException | ExitableDirectoryReader.ExitingReaderException x) { partialResults = true; log.warn("Query: {}; {}", query, x.getMessage()); } if (includeHitCount) { totalHitCount = hitCountCollector.getTotalHits(); } }
Example #6
Source File: FacetStorageTest.java From lumongo with Apache License 2.0 | 5 votes |
/** User runs a query and counts facets. */ private List<FacetResult> search() throws IOException { DirectoryReader indexReader = DirectoryReader.open(directory); IndexSearcher searcher = new IndexSearcher(indexReader); SortedSetDocValuesReaderState state = new DefaultSortedSetDocValuesReaderState(indexReader); // Aggregates the facet counts FacetsCollector fc = new FacetsCollector(); // MatchAllDocsQuery is for "browsing" (counts facets // for all non-deleted docs in the index); normally // you'd use a "normal" query: //FacetsCollector.search(searcher, new MatchAllDocsQuery(), 10, fc); TotalHitCountCollector collector = new TotalHitCountCollector(); searcher.search(new MatchAllDocsQuery(), MultiCollector.wrap(collector, fc)); // Retrieve results Facets facets = new SortedSetDocValuesFacetCounts(state, fc); List<FacetResult> results = new ArrayList<>(); results.add(facets.getTopChildren(10, "Author")); results.add(facets.getTopChildren(10, "Publish Year")); indexReader.close(); return results; }
Example #7
Source File: LindenDocsCollector.java From linden with Apache License 2.0 | 4 votes |
public void wrap(Collector collector) { wrappedCollector = MultiCollector.wrap(collector, wrappedCollector); }
Example #8
Source File: GroupingSearch.java From lucene-solr with Apache License 2.0 | 4 votes |
@SuppressWarnings({"unchecked", "rawtypes"}) protected TopGroups groupByFieldOrFunction(IndexSearcher searcher, Query query, int groupOffset, int groupLimit) throws IOException { int topN = groupOffset + groupLimit; final FirstPassGroupingCollector firstPassCollector = new FirstPassGroupingCollector(grouper, groupSort, topN); final AllGroupsCollector allGroupsCollector = allGroups ? new AllGroupsCollector(grouper) : null; final AllGroupHeadsCollector allGroupHeadsCollector = allGroupHeads ? AllGroupHeadsCollector.newCollector(grouper, sortWithinGroup) : null; final Collector firstRound = MultiCollector.wrap(firstPassCollector, allGroupsCollector, allGroupHeadsCollector); CachingCollector cachedCollector = null; if (maxCacheRAMMB != null || maxDocsToCache != null) { if (maxCacheRAMMB != null) { cachedCollector = CachingCollector.create(firstRound, cacheScores, maxCacheRAMMB); } else { cachedCollector = CachingCollector.create(firstRound, cacheScores, maxDocsToCache); } searcher.search(query, cachedCollector); } else { searcher.search(query, firstRound); } matchingGroups = allGroups ? allGroupsCollector.getGroups() : Collections.emptyList(); matchingGroupHeads = allGroupHeads ? allGroupHeadsCollector.retrieveGroupHeads(searcher.getIndexReader().maxDoc()) : new Bits.MatchNoBits(searcher.getIndexReader().maxDoc()); Collection<SearchGroup> topSearchGroups = firstPassCollector.getTopGroups(groupOffset); if (topSearchGroups == null) { return new TopGroups(new SortField[0], new SortField[0], 0, 0, new GroupDocs[0], Float.NaN); } int topNInsideGroup = groupDocsOffset + groupDocsLimit; TopGroupsCollector secondPassCollector = new TopGroupsCollector(grouper, topSearchGroups, groupSort, sortWithinGroup, topNInsideGroup, includeMaxScore); if (cachedCollector != null && cachedCollector.isCached()) { cachedCollector.replay(secondPassCollector); } else { searcher.search(query, secondPassCollector); } if (allGroups) { return new TopGroups(secondPassCollector.getTopGroups(groupDocsOffset), matchingGroups.size()); } else { return secondPassCollector.getTopGroups(groupDocsOffset); } }
Example #9
Source File: TopGroupsCollector.java From lucene-solr with Apache License 2.0 | 4 votes |
public TopDocsAndMaxScoreCollector(boolean sortedByScore, TopDocsCollector<?> topDocsCollector, MaxScoreCollector maxScoreCollector) { super(MultiCollector.wrap(topDocsCollector, maxScoreCollector)); this.sortedByScore = sortedByScore; this.topDocsCollector = topDocsCollector; this.maxScoreCollector = maxScoreCollector; }