Class GroupingSearch
java.lang.Object
org.apache.lucene.search.grouping.GroupingSearch
Convenience class to perform grouping in a non distributed environment.
- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
Constructor Summary
ConstructorDescriptionGroupingSearch
(String groupField) Constructs aGroupingSearch
instance that groups documents by index terms using DocValues.GroupingSearch
(ValueSource groupFunction, Map<Object, Object> valueSourceContext) Constructs aGroupingSearch
instance that groups documents by function using aValueSource
instance.GroupingSearch
(GroupSelector<?> groupSelector) Constructs aGroupingSearch
instance that groups documents using aGroupSelector
GroupingSearch
(Query groupEndDocs) Constructor for grouping documents by doc block. -
Method Summary
Modifier and TypeMethodDescriptionDisables any enabled cache.Returns the matching group heads ifsetAllGroupHeads(boolean)
was set to true or an empty bit set.<T> Collection<T>
IfsetAllGroups(boolean)
was set totrue
then all matching groups are returned, otherwise an empty collection is returned.protected TopGroups<?>
groupByDocBlock
(IndexSearcher searcher, Query query, int groupOffset, int groupLimit) protected TopGroups
groupByFieldOrFunction
(IndexSearcher searcher, Query query, int groupOffset, int groupLimit) <T> TopGroups<T>
search
(IndexSearcher searcher, Query query, int groupOffset, int groupLimit) Executes a grouped search.setAllGroupHeads
(boolean allGroupHeads) Whether to compute all group heads (most relevant document per group) matching the query.setAllGroups
(boolean allGroups) Whether to also compute all groups matching the query.setCaching
(int maxDocsToCache, boolean cacheScores) Enables caching for the second pass search.setCachingInMB
(double maxCacheRAMMB, boolean cacheScores) Enables caching for the second pass search.setGroupDocsLimit
(int groupDocsLimit) Specifies the number of documents to return inside a group from the specified groupDocsOffset.setGroupDocsOffset
(int groupDocsOffset) Specifies the offset for documents inside a group.setGroupSort
(Sort groupSort) Specifies how groups are sorted.setIncludeMaxScore
(boolean includeMaxScore) Whether to include the score of the most relevant document per group.setSortWithinGroup
(Sort sortWithinGroup) Specified how documents inside a group are sorted.
-
Constructor Details
-
GroupingSearch
Constructs aGroupingSearch
instance that groups documents by index terms using DocValues. The group field can only have one token per document. This means that the field must not be analysed.- Parameters:
groupField
- The name of the field to group by.
-
GroupingSearch
Constructs aGroupingSearch
instance that groups documents using aGroupSelector
- Parameters:
groupSelector
- aGroupSelector
that defines groups for this GroupingSearch
-
GroupingSearch
Constructs aGroupingSearch
instance that groups documents by function using aValueSource
instance.- Parameters:
groupFunction
- The function to group by specified asValueSource
valueSourceContext
- The context of the specified groupFunction
-
GroupingSearch
Constructor for grouping documents by doc block. This constructor can only be used when documents belonging in a group are indexed in one block.- Parameters:
groupEndDocs
- The query that marks the last document in all doc blocks
-
-
Method Details
-
search
public <T> TopGroups<T> search(IndexSearcher searcher, Query query, int groupOffset, int groupLimit) throws IOException Executes a grouped search. Both the first pass and second pass are executed on the specified searcher.- Parameters:
searcher
- TheIndexSearcher
instance to execute the grouped search on.query
- The query to execute with the groupinggroupOffset
- The group offsetgroupLimit
- The number of groups to return from the specified group offset- Returns:
- the grouped result as a
TopGroups
instance - Throws:
IOException
- If any I/O related errors occur
-
groupByFieldOrFunction
protected TopGroups groupByFieldOrFunction(IndexSearcher searcher, Query query, int groupOffset, int groupLimit) throws IOException - Throws:
IOException
-
groupByDocBlock
protected TopGroups<?> groupByDocBlock(IndexSearcher searcher, Query query, int groupOffset, int groupLimit) throws IOException - Throws:
IOException
-
setCachingInMB
Enables caching for the second pass search. The cache will not grow over a specified limit in MB. The cache is filled during the first pass searched and then replayed during the second pass searched. If the cache grows beyond the specified limit, then the cache is purged and not used in the second pass search.- Parameters:
maxCacheRAMMB
- The maximum amount in MB the cache is allowed to holdcacheScores
- Whether to cache the scores- Returns:
this
-
setCaching
Enables caching for the second pass search. The cache will not contain more than the maximum specified documents. The cache is filled during the first pass searched and then replayed during the second pass searched. If the cache grows beyond the specified limit, then the cache is purged and not used in the second pass search.- Parameters:
maxDocsToCache
- The maximum number of documents the cache is allowed to holdcacheScores
- Whether to cache the scores- Returns:
this
-
disableCaching
Disables any enabled cache.- Returns:
this
-
setGroupSort
Specifies how groups are sorted. Defaults toSort.RELEVANCE
.- Parameters:
groupSort
- The sort for the groups.- Returns:
this
-
setSortWithinGroup
Specified how documents inside a group are sorted. Defaults toSort.RELEVANCE
.- Parameters:
sortWithinGroup
- The sort for documents inside a group- Returns:
this
-
setGroupDocsOffset
Specifies the offset for documents inside a group.- Parameters:
groupDocsOffset
- The offset for documents inside a- Returns:
this
-
setGroupDocsLimit
Specifies the number of documents to return inside a group from the specified groupDocsOffset.- Parameters:
groupDocsLimit
- The number of documents to return inside a group- Returns:
this
-
setIncludeMaxScore
Whether to include the score of the most relevant document per group.- Parameters:
includeMaxScore
- Whether to include the score of the most relevant document per group- Returns:
this
-
setAllGroups
Whether to also compute all groups matching the query. This can be used to determine the number of groups, which can be used for accurate pagination.When grouping by doc block the number of groups are automatically included in the
TopGroups
and this option doesn't have any influence.- Parameters:
allGroups
- to also compute all groups matching the query- Returns:
this
-
getAllMatchingGroups
IfsetAllGroups(boolean)
was set totrue
then all matching groups are returned, otherwise an empty collection is returned.- Type Parameters:
T
- The group value type. This can be aBytesRef
or aMutableValue
instance. If grouping by doc block this the group value is alwaysnull
.- Returns:
- all matching groups are returned, or an empty collection
-
setAllGroupHeads
Whether to compute all group heads (most relevant document per group) matching the query.This feature isn't enabled when grouping by doc block.
- Parameters:
allGroupHeads
- Whether to compute all group heads (most relevant document per group) matching the query- Returns:
this
-
getAllGroupHeads
Returns the matching group heads ifsetAllGroupHeads(boolean)
was set to true or an empty bit set.- Returns:
- The matching group heads if
setAllGroupHeads(boolean)
was set to true or an empty bit set
-