Java Code Examples for org.apache.solr.schema.SchemaField#isUninvertible()

The following examples show how to use org.apache.solr.schema.SchemaField#isUninvertible() . 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: FacetFieldProcessorByArrayUIF.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
FacetFieldProcessorByArrayUIF(FacetContext fcontext, FacetField freq, SchemaField sf) {
  super(fcontext, freq, sf);
  if (! sf.isUninvertible()) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
                            getClass()+" can not be used on fields where uninvertible='false'");
  }
}
 
Example 2
Source File: SimpleFacets.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/**
 * This method will force the appropriate facet method even if the user provided a different one as a request parameter
 *
 * N.B. this method could overwrite what you passed as request parameter. Be Extra careful
 *
 * @param field field we are faceting
 * @param method the facet method passed as a request parameter
 * @param mincount the minimum value a facet should have to be returned
 * @return the FacetMethod to use
 */
 static FacetMethod selectFacetMethod(SchemaField field, FacetMethod method, Integer mincount) {

   FieldType type = field.getType();
   if (type.isPointField()) {
     // Only FCS is supported for PointFields for now
     return FacetMethod.FCS;
   }

   /*The user did not specify any preference*/
   if (method == null) {
     /* Always use filters for booleans if not DocValues only... we know the number of values is very small. */
     if (type instanceof BoolField && (field.indexed() == true || field.hasDocValues() == false)) {
       method = FacetMethod.ENUM;
     } else if (type.getNumberType() != null && !field.multiValued()) {
      /* the per-segment approach is optimal for numeric field types since there
         are no global ords to merge and no need to create an expensive
         top-level reader */
       method = FacetMethod.FCS;
     } else {
       // TODO: default to per-segment or not?
       method = FacetMethod.FC;
     }
   }

   /* FC without docValues does not support single valued numeric facets */
   if (method == FacetMethod.FC
       && type.getNumberType() != null && !field.multiValued()) {
     method = FacetMethod.FCS;
   }

   /* UIF without DocValues can't deal with mincount=0, the reason is because
       we create the buckets based on the values present in the result set.
       So we are not going to see facet values which are not in the result set */
   if (method == FacetMethod.UIF
       && !field.hasDocValues() && mincount == 0) {
     method = field.multiValued() ? FacetMethod.FC : FacetMethod.FCS;
   }

   /* Unless isUninvertible() is true, we prohibit any use of UIF...
      Here we just force FC(S) instead, and trust that the DocValues faceting logic will
      do the right thing either way (with or w/o docvalues) */
   if (FacetMethod.UIF == method && ! field.isUninvertible()) {
     method = field.multiValued() ? FacetMethod.FC : FacetMethod.FCS;
   }
   
   /* ENUM can't deal with trie fields that index several terms per value */
   if (method == FacetMethod.ENUM
       && TrieField.getMainValuePrefix(type) != null) {
     method = field.multiValued() ? FacetMethod.FC : FacetMethod.FCS;
   }

   /* FCS can't deal with multi token fields */
   final boolean multiToken = field.multiValued() || type.multiValuedFieldCache();
   if (method == FacetMethod.FCS
       && multiToken) {
     method = FacetMethod.FC;
   }

   return method;
}
 
Example 3
Source File: FacetField.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("rawtypes")
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
    if (multiToken && !sf.hasDocValues() && method!=FacetMethod.DV && sf.isUninvertible()) {
      // Match the access method from the first phase.
      // It won't always matter, but does currently for an all-values bucket
      return new FacetFieldProcessorByArrayUIF(fcontext, this, sf);
    }
    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() && !ft.isPointField() &&
      // wether we can use stream processing depends on wether this is a shard request, wether
      // re-sorting has been requested, and if the effective sort during collection is "index asc"
      ( fcontext.isShard()
        // for a shard request, the effective per-shard sort must be index asc
        ? FacetSort.INDEX_ASC.equals(null == prelim_sort ? sort : prelim_sort)
        // for a non-shard request, we can only use streaming if there is no pre-sorting
        : (null == prelim_sort && FacetSort.INDEX_ASC.equals( sort ) ) ) ) {
        
    return new FacetFieldProcessorByEnumTermsStream(fcontext, this, sf);
  }

  // TODO if method=UIF and not single-valued numerics then simply choose that now? TODO add FieldType.getDocValuesType()

  if (!multiToken) {
    if (mincount > 0 && prefix == null && (ntype != null || method == FacetMethod.DVHASH)) {
      // TODO can we auto-pick for strings when term cardinality is much greater than DocSet cardinality?
      //   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() && sf.getType().isPointField()) {
    return new FacetFieldProcessorByHashDV(fcontext, this, sf);
  }

  // multi-valued after this point

  if (sf.hasDocValues() || method == FacetMethod.DV || !sf.isUninvertible()) {
    // 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);
}