Package org.apache.solr.request
Class SimpleFacets
- java.lang.Object
-
- org.apache.solr.request.SimpleFacets
-
- Direct Known Subclasses:
PivotFacetProcessor
,RangeFacetProcessor
public class SimpleFacets extends Object
A class that generates simple Facet information for a request.More advanced facet implementations may compose or subclass this class to leverage any of its functionality.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SimpleFacets.CountPair<K extends Comparable<? super K>,V extends Comparable<? super V>>
A simple key=>val pair whose natural order is such that higher vals come before lower vals.protected static class
SimpleFacets.ParsedParams
-
Field Summary
Fields Modifier and Type Field Description protected DocSet
docsOrig
The main set of documents all facet counts should be relative toprotected FacetDebugInfo
fdebug
protected FacetDebugInfo
fdebugParent
protected SolrParams
global
Configuration params behavior should be driven byprotected ResponseBuilder
rb
protected SolrQueryRequest
req
protected SolrIndexSearcher
searcher
Searcher to use for all calculations
-
Constructor Summary
Constructors Constructor Description SimpleFacets(SolrQueryRequest req, DocSet docs, SolrParams params)
SimpleFacets(SolrQueryRequest req, DocSet docs, SolrParams params, ResponseBuilder rb)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
checkMincountOnExists(String fieldName, int mincount)
protected DocSet
computeDocSet(DocSet baseDocSet, List<String> excludeTagList)
DocSet
getDocsOrig()
NamedList<Object>
getFacetFieldCounts()
Returns a list of value constraints and the associated facet counts for each facet field specified in the params.NamedList<Object>
getFacetIntervalCounts()
Returns aNamedList
with each entry having the "key" of the interval as name and the count of docs in that interval as value.void
getFacetQueryCount(SimpleFacets.ParsedParams parsed, NamedList<Integer> res)
NamedList<Integer>
getFacetQueryCounts()
Returns a list of facet counts for each of the facet queries specified in the paramsNamedList<Integer>
getFacetTermEnumCounts(SolrIndexSearcher searcher, DocSet docs, String field, int offset, int limit, int mincount, boolean missing, String sort, String prefix, String contains, boolean ignoreCase, boolean intersectsCheck)
Works likegetFacetTermEnumCounts(SolrIndexSearcher, DocSet, String, int, int, int, boolean, String, String, Predicate, boolean)
but takes a substring directly for the contains check rather than aPredicate
instance.NamedList<Integer>
getFacetTermEnumCounts(SolrIndexSearcher searcher, DocSet docs, String field, int offset, int limit, int mincount, boolean missing, String sort, String prefix, Predicate<org.apache.lucene.util.BytesRef> termFilter, boolean intersectsCheck)
Returns a list of terms in the specified field along with the corresponding count of documents in the set that match that constraint.static int
getFieldMissingCount(SolrIndexSearcher searcher, DocSet docs, String fieldName)
Returns a count of the documents in the set which do not have any terms for for the specified field.SolrParams
getGlobalParams()
NamedList<Integer>
getGroupedCounts(SolrIndexSearcher searcher, DocSet base, String field, boolean multiToken, int offset, int limit, int mincount, boolean missing, String sort, String prefix, Predicate<org.apache.lucene.util.BytesRef> termFilter)
int
getGroupedFacetQueryCount(org.apache.lucene.search.Query facetQuery, DocSet docSet)
Returns a grouped facet count for the facet queryNamedList<Object>
getHeatmapCounts()
protected NamedList<Integer>
getListedTermCounts(String field, SimpleFacets.ParsedParams parsed, List<String> terms)
Computes the term->count counts for the specified term values relative to theSolrQueryRequest
getRequest()
ResponseBuilder
getResponseBuilder()
NamedList<Integer>
getTermCounts(String field, SimpleFacets.ParsedParams parsed)
Term counts for use in field faceting that resepects the appropriate mincountNamedList<Integer>
getTermCountsForPivots(String field, SimpleFacets.ParsedParams parsed)
Term counts for use in pivot faceting that resepcts the appropriate mincountprotected Predicate<org.apache.lucene.util.BytesRef>
newBytesRefFilter(String field, SolrParams params)
Create a new bytes ref filter for filtering facet terms.protected Predicate<org.apache.lucene.util.BytesRef>
newExcludeBytesRefFilter(String field, SolrParams params)
Create a new bytes ref filter for excluding facet terms.protected SimpleFacets.ParsedParams
parseParams(String type, String param)
void
setFacetDebugInfo(FacetDebugInfo fdebugParent)
-
-
-
Field Detail
-
docsOrig
protected DocSet docsOrig
The main set of documents all facet counts should be relative to
-
global
protected final SolrParams global
Configuration params behavior should be driven by
-
searcher
protected final SolrIndexSearcher searcher
Searcher to use for all calculations
-
req
protected final SolrQueryRequest req
-
rb
protected final ResponseBuilder rb
-
fdebugParent
protected FacetDebugInfo fdebugParent
-
fdebug
protected FacetDebugInfo fdebug
-
-
Constructor Detail
-
SimpleFacets
public SimpleFacets(SolrQueryRequest req, DocSet docs, SolrParams params)
-
SimpleFacets
public SimpleFacets(SolrQueryRequest req, DocSet docs, SolrParams params, ResponseBuilder rb)
-
-
Method Detail
-
setFacetDebugInfo
public void setFacetDebugInfo(FacetDebugInfo fdebugParent)
-
parseParams
protected SimpleFacets.ParsedParams parseParams(String type, String param) throws SyntaxError, IOException
- Throws:
SyntaxError
IOException
-
computeDocSet
protected DocSet computeDocSet(DocSet baseDocSet, List<String> excludeTagList) throws SyntaxError, IOException
- Throws:
SyntaxError
IOException
-
getFacetQueryCounts
public NamedList<Integer> getFacetQueryCounts() throws IOException, SyntaxError
Returns a list of facet counts for each of the facet queries specified in the params- Throws:
IOException
SyntaxError
- See Also:
FacetParams.FACET_QUERY
-
getFacetQueryCount
public void getFacetQueryCount(SimpleFacets.ParsedParams parsed, NamedList<Integer> res) throws SyntaxError, IOException
- Throws:
SyntaxError
IOException
-
getGroupedFacetQueryCount
public int getGroupedFacetQueryCount(org.apache.lucene.search.Query facetQuery, DocSet docSet) throws IOException
Returns a grouped facet count for the facet query- Throws:
IOException
- See Also:
FacetParams.FACET_QUERY
-
newExcludeBytesRefFilter
protected Predicate<org.apache.lucene.util.BytesRef> newExcludeBytesRefFilter(String field, SolrParams params)
Create a new bytes ref filter for excluding facet terms.This method by default uses the
FacetParams.FACET_EXCLUDETERMS
parameter but custom SimpleFacets classes could use a different implementation.- Parameters:
field
- the field to check for facet term filtersparams
- the request parameter object- Returns:
- A predicate for filtering terms or null if no filters are applicable.
-
newBytesRefFilter
protected Predicate<org.apache.lucene.util.BytesRef> newBytesRefFilter(String field, SolrParams params)
Create a new bytes ref filter for filtering facet terms. If more than one filter is applicable the applicable filters will be returned as anPredicate.and(Predicate)
of all such filters.- Parameters:
field
- the field to check for facet term filtersparams
- the request parameter object- Returns:
- A predicate for filtering terms or null if no filters are applicable.
-
getTermCountsForPivots
public NamedList<Integer> getTermCountsForPivots(String field, SimpleFacets.ParsedParams parsed) throws IOException
Term counts for use in pivot faceting that resepcts the appropriate mincount- Throws:
IOException
- See Also:
FacetParams.FACET_PIVOT_MINCOUNT
-
getTermCounts
public NamedList<Integer> getTermCounts(String field, SimpleFacets.ParsedParams parsed) throws IOException
Term counts for use in field faceting that resepects the appropriate mincount- Throws:
IOException
- See Also:
FacetParams.FACET_MINCOUNT
-
getGroupedCounts
public NamedList<Integer> getGroupedCounts(SolrIndexSearcher searcher, DocSet base, String field, boolean multiToken, int offset, int limit, int mincount, boolean missing, String sort, String prefix, Predicate<org.apache.lucene.util.BytesRef> termFilter) throws IOException
- Throws:
IOException
-
getFacetFieldCounts
public NamedList<Object> getFacetFieldCounts() throws IOException, SyntaxError
Returns a list of value constraints and the associated facet counts for each facet field specified in the params.- Throws:
IOException
SyntaxError
- See Also:
FacetParams.FACET_FIELD
,getFieldMissingCount(org.apache.solr.search.SolrIndexSearcher, org.apache.solr.search.DocSet, java.lang.String)
,getFacetTermEnumCounts(org.apache.solr.search.SolrIndexSearcher, org.apache.solr.search.DocSet, java.lang.String, int, int, int, boolean, java.lang.String, java.lang.String, java.lang.String, boolean, boolean)
-
getListedTermCounts
protected NamedList<Integer> getListedTermCounts(String field, SimpleFacets.ParsedParams parsed, List<String> terms) throws IOException
Computes the term->count counts for the specified term values relative to the- Parameters:
field
- the name of the field to compute term counts againstparsed
- contains the docset to compute term counts relative toterms
- a list of term values (in the specified field) to compute the counts for- Throws:
IOException
-
getFieldMissingCount
public static int getFieldMissingCount(SolrIndexSearcher searcher, DocSet docs, String fieldName) throws IOException
Returns a count of the documents in the set which do not have any terms for for the specified field.- Throws:
IOException
- See Also:
FacetParams.FACET_MISSING
-
getFacetTermEnumCounts
public NamedList<Integer> getFacetTermEnumCounts(SolrIndexSearcher searcher, DocSet docs, String field, int offset, int limit, int mincount, boolean missing, String sort, String prefix, String contains, boolean ignoreCase, boolean intersectsCheck) throws IOException
Works likegetFacetTermEnumCounts(SolrIndexSearcher, DocSet, String, int, int, int, boolean, String, String, Predicate, boolean)
but takes a substring directly for the contains check rather than aPredicate
instance.- Throws:
IOException
-
getFacetTermEnumCounts
public NamedList<Integer> getFacetTermEnumCounts(SolrIndexSearcher searcher, DocSet docs, String field, int offset, int limit, int mincount, boolean missing, String sort, String prefix, Predicate<org.apache.lucene.util.BytesRef> termFilter, boolean intersectsCheck) throws IOException
Returns a list of terms in the specified field along with the corresponding count of documents in the set that match that constraint. This method uses the FilterCache to get the intersection count betweendocs
and the DocSet for each term in the filter.- Throws:
IOException
- See Also:
FacetParams.FACET_LIMIT
,FacetParams.FACET_ZEROS
,FacetParams.FACET_MISSING
-
checkMincountOnExists
public static void checkMincountOnExists(String fieldName, int mincount)
-
getFacetIntervalCounts
public NamedList<Object> getFacetIntervalCounts() throws IOException, SyntaxError
Returns aNamedList
with each entry having the "key" of the interval as name and the count of docs in that interval as value. All intervals added in the request are included in the returnedNamedList
(included those with 0 count), and it's required that the order of the intervals is deterministic and equals in all shards of a distributed request, otherwise the collation of results will fail.- Throws:
IOException
SyntaxError
-
getHeatmapCounts
public NamedList<Object> getHeatmapCounts() throws IOException, SyntaxError
- Throws:
IOException
SyntaxError
-
getGlobalParams
public SolrParams getGlobalParams()
-
getDocsOrig
public DocSet getDocsOrig()
-
getRequest
public SolrQueryRequest getRequest()
-
getResponseBuilder
public ResponseBuilder getResponseBuilder()
-
-