Search in sources :

Example 6 with NumberType

use of org.apache.solr.schema.NumberType in project lucene-solr by apache.

the class FacetField method createFacetProcessor.

@Override
public FacetProcessor createFacetProcessor(FacetContext fcontext) {
    SchemaField sf = fcontext.searcher.getSchema().getField(field);
    FieldType ft = sf.getType();
    boolean multiToken = sf.multiValued() || ft.multiValuedFieldCache();
    if (fcontext.facetInfo != null) {
        // refinement... we will end up either skipping the entire facet, or doing calculating only specific facet buckets
        return new FacetFieldProcessorByArrayDV(fcontext, this, sf);
    }
    NumberType ntype = ft.getNumberType();
    // ensure we can support the requested options for numeric faceting:
    if (ntype != null) {
        if (prefix != null) {
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Doesn't make sense to set facet prefix on a numeric field");
        }
        if (mincount == 0) {
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Numeric fields do not support facet mincount=0; try indexing as terms");
        // TODO if indexed=true then we could add support
        }
    }
    // TODO auto-pick ENUM/STREAM SOLR-9351 when index asc and DocSet cardinality is *not* much smaller than term cardinality
    if (method == FacetMethod.ENUM) {
        // at the moment these two are the same
        method = FacetMethod.STREAM;
    }
    if (method == FacetMethod.STREAM && sf.indexed() && "index".equals(sortVariable) && sortDirection == SortDirection.asc) {
        return new FacetFieldProcessorByEnumTermsStream(fcontext, this, sf);
    }
    if (!multiToken) {
        if (mincount > 0 && prefix == null && (ntype != null || method == FacetMethod.DVHASH)) {
            //   or if we don't know cardinality but DocSet size is very small
            return new FacetFieldProcessorByHashDV(fcontext, this, sf);
        } else if (ntype == null) {
            // single valued string...
            return new FacetFieldProcessorByArrayDV(fcontext, this, sf);
        } else {
            throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Couldn't pick facet algorithm for field " + sf);
        }
    }
    if (sf.hasDocValues() || method == FacetMethod.DV) {
        // single and multi-valued string docValues
        return new FacetFieldProcessorByArrayDV(fcontext, this, sf);
    }
    // Top-level multi-valued field cache (UIF)
    return new FacetFieldProcessorByArrayUIF(fcontext, this, sf);
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) NumberType(org.apache.solr.schema.NumberType) SolrException(org.apache.solr.common.SolrException) FieldType(org.apache.solr.schema.FieldType)

Aggregations

NumberType (org.apache.solr.schema.NumberType)6 FieldType (org.apache.solr.schema.FieldType)5 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)4 NumericDocValues (org.apache.lucene.index.NumericDocValues)4 BytesRef (org.apache.lucene.util.BytesRef)4 SchemaField (org.apache.solr.schema.SchemaField)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 SortedNumericDocValues (org.apache.lucene.index.SortedNumericDocValues)3 DocIterator (org.apache.solr.search.DocIterator)3 HashMap (java.util.HashMap)2 DocValuesType (org.apache.lucene.index.DocValuesType)2 FilterNumericDocValues (org.apache.lucene.index.FilterNumericDocValues)2 LeafReader (org.apache.lucene.index.LeafReader)2 SortedDocValues (org.apache.lucene.index.SortedDocValues)2 CharsRefBuilder (org.apache.lucene.util.CharsRefBuilder)2 NamedList (org.apache.solr.common.util.NamedList)2 IntHashSet (com.carrotsearch.hppc.IntHashSet)1 IntObjectHashMap (com.carrotsearch.hppc.IntObjectHashMap)1 LongHashSet (com.carrotsearch.hppc.LongHashSet)1