Java Code Examples for org.apache.solr.common.params.SolrParams#getFieldParam()
The following examples show how to use
org.apache.solr.common.params.SolrParams#getFieldParam() .
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 |
/** * 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: RegexFragmenter.java From lucene-solr with Apache License 2.0 | 6 votes |
@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 3
Source File: PivotFacetField.java From lucene-solr with Apache License 2.0 | 6 votes |
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 4
Source File: FacetComponent.java From lucene-solr with Apache License 2.0 | 6 votes |
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 5
Source File: SimpleFacets.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * Create a new bytes ref filter for excluding facet terms. * * This method by default uses the {@link FacetParams#FACET_EXCLUDETERMS} parameter * but custom SimpleFacets classes could use a different implementation. * * @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> newExcludeBytesRefFilter(String field, SolrParams params) { final String exclude = params.getFieldParam(field, FacetParams.FACET_EXCLUDETERMS); if (exclude == null) { return null; } final Set<String> excludeTerms = new HashSet<>(StrUtils.splitSmart(exclude, ",", true)); return new Predicate<BytesRef>() { @Override public boolean test(BytesRef bytesRef) { return !excludeTerms.contains(bytesRef.utf8ToString()); } }; }
Example 6
Source File: BreakIteratorBoundaryScanner.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override protected BoundaryScanner get(String fieldName, SolrParams params) { // construct Locale String language = params.getFieldParam(fieldName, HighlightParams.BS_LANGUAGE); String country = params.getFieldParam(fieldName, HighlightParams.BS_COUNTRY); if(country != null && language == null){ throw new SolrException(ErrorCode.BAD_REQUEST, HighlightParams.BS_LANGUAGE + " parameter cannot be null when you specify " + HighlightParams.BS_COUNTRY); } Locale locale = null; if(language != null){ locale = country == null ? new Locale(language) : new Locale(language, country); } else { locale = Locale.ROOT; } // construct BreakIterator String type = params.getFieldParam(fieldName, HighlightParams.BS_TYPE, "WORD").toLowerCase(Locale.ROOT); BreakIterator bi = null; if(type.equals("character")){ bi = BreakIterator.getCharacterInstance(locale); } else if(type.equals("word")){ bi = BreakIterator.getWordInstance(locale); } else if(type.equals("line")){ bi = BreakIterator.getLineInstance(locale); } else if(type.equals("sentence")){ bi = BreakIterator.getSentenceInstance(locale); } else throw new SolrException(ErrorCode.BAD_REQUEST, type + " is invalid for parameter " + HighlightParams.BS_TYPE); return new org.apache.lucene.search.vectorhighlight.BreakIteratorBoundaryScanner(bi); }
Example 7
Source File: SolrFragmentsBuilder.java From lucene-solr with Apache License 2.0 | 5 votes |
private String[] getTags( SolrParams params, String paramName, String fieldName, String def ){ params = SolrParams.wrapDefaults(params, defaults); String value = null; if( fieldName == null ) value = params.get( paramName, def ); else value = params.getFieldParam( fieldName, paramName, def ); String[] tags = value.split( "," ); for( int i = 0; i < tags.length; i++ ){ tags[i] = tags[i].trim(); } return tags; }
Example 8
Source File: DefaultSolrHighlighter.java From lucene-solr with Apache License 2.0 | 5 votes |
protected FragListBuilder getFragListBuilder(String fieldName, SolrParams params) { String flb = params.getFieldParam(fieldName, HighlightParams.FRAG_LIST_BUILDER); SolrFragListBuilder solrFlb = fragListBuilders.get(flb); if (solrFlb == null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unknown fragListBuilder: " + flb); } return solrFlb.getFragListBuilder(params); }
Example 9
Source File: DefaultSolrHighlighter.java From lucene-solr with Apache License 2.0 | 5 votes |
protected SolrFragmentsBuilder getSolrFragmentsBuilder(String fieldName, SolrParams params) { String fb = params.getFieldParam(fieldName, HighlightParams.FRAGMENTS_BUILDER); SolrFragmentsBuilder solrFb = fragmentsBuilders.get(fb); if (solrFb == null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unknown fragmentsBuilder: " + fb); } return solrFb; }
Example 10
Source File: DefaultSolrHighlighter.java From lucene-solr with Apache License 2.0 | 5 votes |
protected BoundaryScanner getBoundaryScanner(String fieldName, SolrParams params) { String bs = params.getFieldParam(fieldName, HighlightParams.BOUNDARY_SCANNER); SolrBoundaryScanner solrBs = boundaryScanners.get(bs); if (solrBs == null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unknown boundaryScanner: " + bs); } return solrBs.getBoundaryScanner(fieldName, params); }
Example 11
Source File: SimpleBoundaryScanner.java From lucene-solr with Apache License 2.0 | 5 votes |
@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 12
Source File: HtmlFormatter.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public Formatter getFormatter(String fieldName, SolrParams params ) { numRequests.inc(); params = SolrParams.wrapDefaults(params, defaults); return new SimpleHTMLFormatter( params.getFieldParam(fieldName, HighlightParams.SIMPLE_PRE, "<em>" ), params.getFieldParam(fieldName, HighlightParams.SIMPLE_POST, "</em>")); }
Example 13
Source File: RangeFacetRequest.java From lucene-solr with Apache License 2.0 | 4 votes |
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 14
Source File: FacetComponent.java From lucene-solr with Apache License 2.0 | 4 votes |
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 15
Source File: DefaultSolrHighlighter.java From lucene-solr with Apache License 2.0 | 3 votes |
/** * Return a {@link org.apache.lucene.search.highlight.Formatter} appropriate for this field. If a formatter * has not been configured for this field, fall back to the configured * default or the solr default ({@link org.apache.lucene.search.highlight.SimpleHTMLFormatter}). * * @param fieldName The name of the field * @param params The params controlling Highlighting * @return An appropriate {@link org.apache.lucene.search.highlight.Formatter}. */ protected Formatter getFormatter(String fieldName, SolrParams params) { String str = params.getFieldParam(fieldName, HighlightParams.FORMATTER); SolrFormatter formatter = formatters.get(str); if (formatter == null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unknown formatter: " + str); } return formatter.getFormatter(fieldName, params); }
Example 16
Source File: DefaultSolrHighlighter.java From lucene-solr with Apache License 2.0 | 3 votes |
/** * Return an {@link org.apache.lucene.search.highlight.Encoder} appropriate for this field. If an encoder * has not been configured for this field, fall back to the configured * default or the solr default ({@link org.apache.lucene.search.highlight.DefaultEncoder}). * * @param fieldName The name of the field * @param params The params controlling Highlighting * @return An appropriate {@link org.apache.lucene.search.highlight.Encoder}. */ protected Encoder getEncoder(String fieldName, SolrParams params) { String str = params.getFieldParam(fieldName, HighlightParams.ENCODER); SolrEncoder encoder = encoders.get(str); if (encoder == null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unknown encoder: " + str); } return encoder.getEncoder(fieldName, params); }
Example 17
Source File: DefaultSolrHighlighter.java From lucene-solr with Apache License 2.0 | 3 votes |
/** * Return a {@link org.apache.lucene.search.highlight.Fragmenter} appropriate for this field. If a fragmenter * has not been configured for this field, fall back to the configured * default or the solr default ({@link GapFragmenter}). * * @param fieldName The name of the field * @param params The params controlling Highlighting * @return An appropriate {@link org.apache.lucene.search.highlight.Fragmenter}. */ protected Fragmenter getFragmenter(String fieldName, SolrParams params) { String fmt = params.getFieldParam(fieldName, HighlightParams.FRAGMENTER); SolrFragmenter frag = fragmenters.get(fmt); if (frag == null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unknown fragmenter: " + fmt); } return frag.getFragmenter(fieldName, params); }