Java Code Examples for org.apache.solr.common.params.SolrParams#getFieldBool()

The following examples show how to use org.apache.solr.common.params.SolrParams#getFieldBool() . 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: SimpleFacets.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new bytes ref filter for filtering facet terms. If more than one filter is
 * applicable the applicable filters will be returned as an {@link Predicate#and(Predicate)}
 * of all such filters.
 *
 * @param field the field to check for facet term filters
 * @param params the request parameter object
 * @return A predicate for filtering terms or null if no filters are applicable.
 */
protected Predicate<BytesRef> newBytesRefFilter(String field, SolrParams params) {
  final String contains = params.getFieldParam(field, FacetParams.FACET_CONTAINS);

  Predicate<BytesRef> finalFilter = null;

  if (contains != null) {
    final boolean containsIgnoreCase = params.getFieldBool(field, FacetParams.FACET_CONTAINS_IGNORE_CASE, false);
    finalFilter = new SubstringBytesRefFilter(contains, containsIgnoreCase);
  }

  final String regex = params.getFieldParam(field, FacetParams.FACET_MATCHES);
  if (regex != null) {
    final RegexBytesRefFilter regexBytesRefFilter = new RegexBytesRefFilter(regex);
    finalFilter = (finalFilter == null) ? regexBytesRefFilter : finalFilter.and(regexBytesRefFilter);
  }

  final Predicate<BytesRef> excludeFilter = newExcludeBytesRefFilter(field, params);
  if (excludeFilter != null) {
    finalFilter = (finalFilter == null) ? excludeFilter : finalFilter.and(excludeFilter);
  }

  return finalFilter;
}
 
Example 2
Source File: FacetComponent.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
protected void fillParams(ResponseBuilder rb, SolrParams params, String field) {
  this.field = field;
  this.ftype = rb.req.getSchema().getFieldTypeNoEx(this.field);
  this.offset = params.getFieldInt(field, FacetParams.FACET_OFFSET, 0);
  this.limit = params.getFieldInt(field, FacetParams.FACET_LIMIT, 100);
  Integer mincount = params.getFieldInt(field, FacetParams.FACET_MINCOUNT);
  if (mincount == null) {
    Boolean zeros = params.getFieldBool(field, FacetParams.FACET_ZEROS);
    // mincount = (zeros!=null && zeros) ? 0 : 1;
    mincount = (zeros != null && !zeros) ? 1 : 0;
    // current default is to include zeros.
  }
  this.minCount = mincount;
  this.missing = params.getFieldBool(field, FacetParams.FACET_MISSING, false);
  // default to sorting by count if there is a limit.
  this.sort = params.getFieldParam(field, FacetParams.FACET_SORT,
                                   (limit > 0 ? 
                                    FacetParams.FACET_SORT_COUNT
                                    : FacetParams.FACET_SORT_INDEX));
  if (this.sort.equals(FacetParams.FACET_SORT_COUNT_LEGACY)) {
    this.sort = FacetParams.FACET_SORT_COUNT;
  } else if (this.sort.equals(FacetParams.FACET_SORT_INDEX_LEGACY)) {
    this.sort = FacetParams.FACET_SORT_INDEX;
  }
  this.prefix = params.getFieldParam(field, FacetParams.FACET_PREFIX);
}
 
Example 3
Source File: FacetComponent.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
void parse(SolrParams params, ResponseBuilder rb) {
  queryFacets = new LinkedHashMap<>();
  facets = new LinkedHashMap<>();

  String[] facetQs = params.getParams(FacetParams.FACET_QUERY);
  if (facetQs != null) {
    for (String query : facetQs) {
      QueryFacet queryFacet = new QueryFacet(rb, query);
      queryFacets.put(queryFacet.getKey(), queryFacet);
    }
  }
  
  String[] facetFs = params.getParams(FacetParams.FACET_FIELD);
  if (facetFs != null) {
    
    for (String field : facetFs) {
      final DistribFieldFacet ff;
      
      if (params.getFieldBool(field, FacetParams.FACET_EXISTS, false)) {
        // cap facet count by 1 with this method
        ff = new DistribFacetExistsField(rb, field);
      } else {
        ff = new DistribFieldFacet(rb, field);
      }
      facets.put(ff.getKey(), ff);
    }
  }

  // Develop Pivot Facet Information
  String[] facetPFs = params.getParams(FacetParams.FACET_PIVOT);
  if (facetPFs != null) {
    for (String fieldGroup : facetPFs) {
      PivotFacet pf = new PivotFacet(rb, fieldGroup);
      pivotFacets.add(pf.getKey(), pf);
    }
  }

  heatmapFacets = SpatialHeatmapFacets.distribParse(params, rb);
}
 
Example 4
Source File: DefaultSolrHighlighter.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Determines if we should use the FastVectorHighlighter for this field.
 */
protected boolean useFastVectorHighlighter(SolrParams params, SchemaField schemaField) {
  boolean methodFvh =
          HighlightComponent.HighlightMethod.FAST_VECTOR.getMethodName().equals(
                  params.getFieldParam(schemaField.getName(), HighlightParams.METHOD))
                  || params.getFieldBool(schemaField.getName(), USE_FVH, false);
  if (!methodFvh) return false;
  boolean termPosOff = schemaField.storeTermPositions() && schemaField.storeTermOffsets();
  if (!termPosOff) {
    log.warn("Solr will use the standard Highlighter instead of FastVectorHighlighter because the {} field {}"
            , "does not store TermVectors with TermPositions and TermOffsets.", schemaField.getName());
  }
  return termPosOff;
}
 
Example 5
Source File: RangeFacetRequest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public RangeFacetRequest(ResponseBuilder rb, String f) {
  super(rb, FacetParams.FACET_RANGE, f);

  IndexSchema schema = rb.req.getSchema();
  this.schemaField = schema.getField(facetOn);

  SolrParams params = SolrParams.wrapDefaults(localParams, rb.req.getParams());
  SolrParams required = new RequiredSolrParams(params);

  String methodStr = params.get(FacetParams.FACET_RANGE_METHOD);
  FacetParams.FacetRangeMethod method = (methodStr == null ? FacetParams.FacetRangeMethod.getDefault() : FacetParams.FacetRangeMethod.get(methodStr));

  if ((schemaField.getType() instanceof DateRangeField) && method.equals(FacetParams.FacetRangeMethod.DV)) {
    // the user has explicitly selected the FacetRangeMethod.DV method
    log.warn("Range facet method '{}' is not supported together with field type '{}'. Will use method '{}' instead"
        , FacetParams.FacetRangeMethod.DV, DateRangeField.class, FacetParams.FacetRangeMethod.FILTER);
    method = FacetParams.FacetRangeMethod.FILTER;
  }
  if (method.equals(FacetParams.FacetRangeMethod.DV) && !schemaField.hasDocValues() && (schemaField.getType().isPointField())) {
    log.warn("Range facet method '{}' is not supported on PointFields without docValues. Will use method '{}' instead"
        , FacetParams.FacetRangeMethod.DV
        , FacetParams.FacetRangeMethod.FILTER);
    method = FacetParams.FacetRangeMethod.FILTER;
  }

  this.start = required.getFieldParam(facetOn, FacetParams.FACET_RANGE_START);
  this.end = required.getFieldParam(facetOn, FacetParams.FACET_RANGE_END);


  this.gap = required.getFieldParam(facetOn, FacetParams.FACET_RANGE_GAP);
  this.minCount = params.getFieldInt(facetOn, FacetParams.FACET_MINCOUNT, 0);

  this.include = FacetParams.FacetRangeInclude.parseParam
      (params.getFieldParams(facetOn, FacetParams.FACET_RANGE_INCLUDE));

  this.hardEnd = params.getFieldBool(facetOn, FacetParams.FACET_RANGE_HARD_END, false);

  this.others = EnumSet.noneOf(FacetParams.FacetRangeOther.class);
  final String[] othersP = params.getFieldParams(facetOn, FacetParams.FACET_RANGE_OTHER);
  if (othersP != null && othersP.length > 0) {
    for (final String o : othersP) {
      others.add(FacetParams.FacetRangeOther.get(o));
    }
  }

  this.groupFacet = params.getBool(GroupParams.GROUP_FACET, false);
  if (groupFacet && method.equals(FacetParams.FacetRangeMethod.DV)) {
    // the user has explicitly selected the FacetRangeMethod.DV method
    log.warn("Range facet method '{}' is not supported together with '{}'. Will use method '{}' instead"
        , FacetParams.FacetRangeMethod.DV, GroupParams.GROUP_FACET, FacetParams.FacetRangeMethod.FILTER);
    method = FacetParams.FacetRangeMethod.FILTER;
  }

  this.method = method;

  RangeEndpointCalculator<? extends Comparable<?>> calculator = createCalculator();
  this.facetRanges = calculator.computeRanges();
  this.gapObj = calculator.getGap();
  this.startObj = calculator.getStart();
  this.endObj = calculator.getComputedEnd();
}
 
Example 6
Source File: DefaultSolrHighlighter.java    From lucene-solr with Apache License 2.0 2 votes vote down vote up
/**
 * Return whether adjacent fragments should be merged.
 *
 * @param fieldName The name of the field
 * @param params    The params controlling Highlighting
 */
protected boolean isMergeContiguousFragments(String fieldName, SolrParams params) {
  return params.getFieldBool(fieldName, HighlightParams.MERGE_CONTIGUOUS_FRAGMENTS, false);
}