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

The following examples show how to use org.apache.solr.common.params.SolrParams#getFieldInt() . 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: 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 2
Source File: PivotFacetField.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private PivotFacetField(ResponseBuilder rb, PivotFacetValue parent, String fieldName) {
  
  field = fieldName;
  parentValue = parent;
  
  // facet params
  SolrParams parameters = rb.req.getParams();
  facetFieldMinimumCount = parameters.getFieldInt(field, FacetParams.FACET_PIVOT_MINCOUNT, 1);
  facetFieldOffset = parameters.getFieldInt(field, FacetParams.FACET_OFFSET, 0);
  facetFieldLimit = parameters.getFieldInt(field, FacetParams.FACET_LIMIT, 100);
  String defaultSort = (facetFieldLimit > 0) ? FacetParams.FACET_SORT_COUNT : FacetParams.FACET_SORT_INDEX;
  facetFieldSort = parameters.getFieldParam(field, FacetParams.FACET_SORT, defaultSort);

  valueCollection = new PivotFacetFieldValueCollection(facetFieldMinimumCount, facetFieldOffset, facetFieldLimit, facetFieldSort);
  
  if ( (facetFieldLimit < 0) || 
       // TODO: possible refinement issue if limit=0 & mincount=0 & missing=true
       // (ie: we only want the missing count for this field)
       (facetFieldLimit <= 0 && facetFieldMinimumCount == 0) ||
       (facetFieldSort.equals(FacetParams.FACET_SORT_INDEX) && facetFieldMinimumCount <= 0) 
       ) {
    // in any of these cases, there's no need to refine this level of the pivot
    needRefinementAtThisLevel = false;
  }
}
 
Example 3
Source File: RegexFragmenter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public Fragmenter getFragmenter(String fieldName, SolrParams params )
{ 
  numRequests.inc();
  params = SolrParams.wrapDefaults(params, defaults);

  int fragsize  = params.getFieldInt(   fieldName, HighlightParams.FRAGSIZE,  LuceneRegexFragmenter.DEFAULT_FRAGMENT_SIZE );
  int increment = params.getFieldInt(   fieldName, HighlightParams.INCREMENT, LuceneRegexFragmenter.DEFAULT_INCREMENT_GAP );
  float slop    = params.getFieldFloat( fieldName, HighlightParams.SLOP,      LuceneRegexFragmenter.DEFAULT_SLOP );
  int maxchars  = params.getFieldInt(   fieldName, HighlightParams.MAX_RE_CHARS, LuceneRegexFragmenter.DEFAULT_MAX_ANALYZED_CHARS );
  String rawpat = params.getFieldParam( fieldName, HighlightParams.PATTERN,   LuceneRegexFragmenter.DEFAULT_PATTERN_RAW );

  Pattern p = rawpat == defaultPatternRaw ? defaultPattern : Pattern.compile(rawpat);

  if( fragsize <= 0 ) {
    return new NullFragmenter();
  }
  
  return new LuceneRegexFragmenter( fragsize, increment, slop, maxchars, p );
}
 
Example 4
Source File: UnifiedSolrHighlighter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public NamedList<Object> doHighlighting(DocList docs, Query query, SolrQueryRequest req, String[] defaultFields) throws IOException {
  final SolrParams params = req.getParams();

  // if highlighting isn't enabled, then why call doHighlighting?
  if (!isHighlightingEnabled(params))
    return null;

  int[] docIDs = toDocIDs(docs);

  // fetch the unique keys
  String[] keys = getUniqueKeys(req.getSearcher(), docIDs);

  // query-time parameters
  String[] fieldNames = getHighlightFields(query, req, defaultFields);

  int maxPassages[] = new int[fieldNames.length];
  for (int i = 0; i < fieldNames.length; i++) {
    maxPassages[i] = params.getFieldInt(fieldNames[i], HighlightParams.SNIPPETS, 1);
  }

  UnifiedHighlighter highlighter = getHighlighter(req);
  Map<String, String[]> snippets = highlighter.highlightFields(fieldNames, query, docIDs, maxPassages);
  return encodeSnippets(keys, fieldNames, snippets);
}
 
Example 5
Source File: FacetComponent.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected void fillParams(ResponseBuilder rb, SolrParams params, String field) {
  super.fillParams(rb, params, field);
  this.overrequestRatio
    = params.getFieldDouble(field, FacetParams.FACET_OVERREQUEST_RATIO, 1.5);
  this.overrequestCount 
    = params.getFieldInt(field, FacetParams.FACET_OVERREQUEST_COUNT, 10);
}
 
Example 6
Source File: SimpleBoundaryScanner.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
protected BoundaryScanner get(String fieldName, SolrParams params) {
  int maxScan = params.getFieldInt(fieldName, HighlightParams.BS_MAX_SCAN, 10);
  String str = params.getFieldParam(fieldName, HighlightParams.BS_CHARS, ".,!? \t\n");
  Character[] chars = new Character[str.length()];
  for(int i = 0; i < str.length(); i++){
    chars[i] = str.charAt(i);
  }
  return new org.apache.lucene.search.vectorhighlight.SimpleBoundaryScanner(maxScan, chars);
}
 
Example 7
Source File: GapFragmenter.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public Fragmenter getFragmenter(String fieldName, SolrParams params )
{
  numRequests.inc();
  params = SolrParams.wrapDefaults(params, defaults);
  
  int fragsize = params.getFieldInt( fieldName, HighlightParams.FRAGSIZE, 100 );
  return (fragsize <= 0) ? new NullFragmenter() : new LuceneGapFragmenter(fragsize);
}
 
Example 8
Source File: FacetComponent.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private void modifyRequestForIndividualPivotFacets(ResponseBuilder rb, ShardRequest sreq, 
                                                   String fieldToOverRequest) {

  final SolrParams originalParams = rb.req.getParams();
  final String paramStart = "f." + fieldToOverRequest + ".";

  final int requestedLimit = originalParams.getFieldInt(fieldToOverRequest,
                                                        FacetParams.FACET_LIMIT, 100);
  sreq.params.remove(paramStart + FacetParams.FACET_LIMIT);

  final int offset = originalParams.getFieldInt(fieldToOverRequest,
                                                FacetParams.FACET_OFFSET, 0);
  sreq.params.remove(paramStart + FacetParams.FACET_OFFSET);
  
  final double overRequestRatio = originalParams.getFieldDouble
    (fieldToOverRequest, FacetParams.FACET_OVERREQUEST_RATIO, 1.5);
  sreq.params.remove(paramStart + FacetParams.FACET_OVERREQUEST_RATIO);
  
  final int overRequestCount = originalParams.getFieldInt
    (fieldToOverRequest, FacetParams.FACET_OVERREQUEST_COUNT, 10);
  sreq.params.remove(paramStart + FacetParams.FACET_OVERREQUEST_COUNT);
  
  final int requestedMinCount = originalParams.getFieldInt
    (fieldToOverRequest, FacetParams.FACET_PIVOT_MINCOUNT, 1);
  sreq.params.remove(paramStart + FacetParams.FACET_PIVOT_MINCOUNT);

  final String defaultSort = (requestedLimit > 0)
    ? FacetParams.FACET_SORT_COUNT : FacetParams.FACET_SORT_INDEX;
  final String sort = originalParams.getFieldParam
    (fieldToOverRequest, FacetParams.FACET_SORT, defaultSort);

  int shardLimit = requestedLimit + offset;
  int shardMinCount = Math.min(requestedMinCount, 1);

  // per-shard mincount & overrequest
  if ( FacetParams.FACET_SORT_INDEX.equals(sort) && 
       1 < requestedMinCount && 
       0 < requestedLimit) {

    // We can divide the mincount by num shards rounded up, because unless 
    // a single shard has at least that many it can't compete...
    shardMinCount = (int) Math.ceil((double) requestedMinCount / rb.slices.length);

    // ...but we still need to overrequest to reduce chances of missing something
    shardLimit = doOverRequestMath(shardLimit, overRequestRatio, overRequestCount);

    // (for mincount <= 1, no overrequest needed)

  } else if ( FacetParams.FACET_SORT_COUNT.equals(sort) ) {
    if ( 0 < requestedLimit ) {
      shardLimit = doOverRequestMath(shardLimit, overRequestRatio, overRequestCount);
    }
  } 
  sreq.params.set(paramStart + FacetParams.FACET_LIMIT, shardLimit);
  sreq.params.set(paramStart + FacetParams.FACET_PIVOT_MINCOUNT, shardMinCount);
}
 
Example 9
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 10
Source File: DefaultSolrHighlighter.java    From lucene-solr with Apache License 2.0 2 votes vote down vote up
/**
 * Return the max number of snippets for this field. If this has not
 * been configured for this field, fall back to the configured default
 * or the solr default.
 *
 * @param fieldName The name of the field
 * @param params    The params controlling Highlighting
 */
protected int getMaxSnippets(String fieldName, SolrParams params) {
  return params.getFieldInt(fieldName, HighlightParams.SNIPPETS, 1);
}