Java Code Examples for org.apache.solr.common.params.SolrParams#getFloat()
The following examples show how to use
org.apache.solr.common.params.SolrParams#getFloat() .
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: RankQParserPlugin.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public Query createQuery(String fieldName, SolrParams params) throws SyntaxError { Float weight = params.getFloat(WEIGHT); Float pivot = params.getFloat(PIVOT); if (pivot == null && (weight == null || Float.compare(weight.floatValue(), 1f) == 0)) { // No IAE expected in this case return FeatureField.newSaturationQuery(RankField.INTERNAL_RANK_FIELD_NAME, fieldName); } if (pivot == null) { throw new SyntaxError("A pivot value needs to be provided if the weight is not 1 on \"satu\" function"); } if (weight == null) { weight = Float.valueOf(1); } try { return FeatureField.newSaturationQuery(RankField.INTERNAL_RANK_FIELD_NAME, fieldName, weight, pivot); } catch (IllegalArgumentException iae) { throw new SyntaxError(iae.getMessage()); } }
Example 2
Source File: RankQParserPlugin.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public Query createQuery(String fieldName, SolrParams params) throws SyntaxError { float weight = params.getFloat(WEIGHT, 1f); Float pivot = params.getFloat(PIVOT); if (pivot == null) { throw new SyntaxError("A pivot value needs to be provided when using \"sigm\" function"); } Float exponent = params.getFloat(EXPONENT); if (exponent == null) { throw new SyntaxError("An exponent value needs to be provided when using \"sigm\" function"); } try { return FeatureField.newSigmoidQuery(RankField.INTERNAL_RANK_FIELD_NAME, fieldName, weight, pivot, exponent); } catch (IllegalArgumentException iae) { throw new SyntaxError(iae.getMessage()); } }
Example 3
Source File: RankQParserPlugin.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public Query createQuery(String fieldName, SolrParams params) throws SyntaxError { float weight = params.getFloat(WEIGHT, 1f); float scalingFactor = params.getFloat(SCALING_FACTOR, 1f); try { return FeatureField.newLogQuery(RankField.INTERNAL_RANK_FIELD_NAME, fieldName, weight, scalingFactor); } catch (IllegalArgumentException iae) { throw new SyntaxError(iae.getMessage()); } }
Example 4
Source File: DisMaxQParser.java From lucene-solr with Apache License 2.0 | 5 votes |
/** Adds the main query to the query argument. If it's blank then false is returned. */ protected boolean addMainQuery(BooleanQuery.Builder query, SolrParams solrParams) throws SyntaxError { Map<String, Float> phraseFields = SolrPluginUtils.parseFieldBoosts(solrParams.getParams(DisMaxParams.PF)); float tiebreaker = solrParams.getFloat(DisMaxParams.TIE, 0.0f); /* a parser for dealing with user input, which will convert * things to DisjunctionMaxQueries */ SolrPluginUtils.DisjunctionMaxQueryParser up = getParser(queryFields, DisMaxParams.QS, solrParams, tiebreaker); /* for parsing sloppy phrases using DisjunctionMaxQueries */ SolrPluginUtils.DisjunctionMaxQueryParser pp = getParser(phraseFields, DisMaxParams.PS, solrParams, tiebreaker); /* * * Main User Query * * */ parsedUserQuery = null; String userQuery = getString(); altUserQuery = null; if (StringUtils.isBlank(userQuery)) { // If no query is specified, we may have an alternate altUserQuery = getAlternateUserQuery(solrParams); if (altUserQuery == null) return false; query.add(altUserQuery, BooleanClause.Occur.MUST); } else { // There is a valid query string userQuery = SolrPluginUtils.partialEscape(SolrPluginUtils.stripUnbalancedQuotes(userQuery)).toString(); userQuery = SolrPluginUtils.stripIllegalOperators(userQuery).toString(); parsedUserQuery = getUserQuery(userQuery, up, solrParams); query.add(parsedUserQuery, BooleanClause.Occur.MUST); Query phrase = getPhraseQuery(userQuery, pp); if (null != phrase) { query.add(phrase, BooleanClause.Occur.SHOULD); } } return true; }
Example 5
Source File: BM25SimilarityFactory.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void init(SolrParams params) { super.init(params); discountOverlaps = params.getBool("discountOverlaps", true); k1 = params.getFloat("k1", 1.2f); b = params.getFloat("b", 0.75f); }
Example 6
Source File: LegacyBM25SimilarityFactory.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void init(SolrParams params) { super.init(params); discountOverlaps = params.getBool("discountOverlaps", true); k1 = params.getFloat("k1", 1.2f); b = params.getFloat("b", 0.75f); }
Example 7
Source File: TextProfileSignature.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public void init(SolrParams params) { quantRate = params.getFloat("quantRate", 0.01f); minTokenLen = params.getInt("minTokenLen", 2); }
Example 8
Source File: LMDirichletSimilarityFactory.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public void init(SolrParams params) { super.init(params); discountOverlaps = params.getBool("discountOverlaps", true); mu = params.getFloat("mu"); }
Example 9
Source File: LMJelinekMercerSimilarityFactory.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public void init(SolrParams params) { super.init(params); discountOverlaps = params.getBool("discountOverlaps", true); lambda = params.getFloat("lambda", 0.7f); }
Example 10
Source File: SweetSpotSimilarityFactory.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public void init(SolrParams params) { super.init(params); Integer ln_min = params.getInt("lengthNormMin"); Integer ln_max = params.getInt("lengthNormMax"); Float ln_steep = params.getFloat("lengthNormSteepness"); if (! allOrNoneNull(ln_min, ln_max, ln_steep)) { throw new SolrException(SERVER_ERROR, "Overriding default lengthNorm settings requires all to be specified: lengthNormMin, lengthNormMax, lengthNormSteepness"); } Float hyper_min = params.getFloat("hyperbolicTfMin"); Float hyper_max = params.getFloat("hyperbolicTfMax"); Double hyper_base = params.getDouble("hyperbolicTfBase"); Float hyper_offset = params.getFloat("hyperbolicTfOffset"); if (! allOrNoneNull(hyper_min, hyper_max, hyper_base, hyper_offset)) { throw new SolrException(SERVER_ERROR, "Overriding default hyperbolicTf settings requires all to be specified: hyperbolicTfMin, hyperbolicTfMax, hyperbolicTfBase, hyperbolicTfOffset"); } Float baseline_base = params.getFloat("baselineTfBase"); Float baseline_min = params.getFloat("baselineTfMin"); if (! allOrNoneNull(baseline_min, baseline_base)) { throw new SolrException(SERVER_ERROR, "Overriding default baselineTf settings requires all to be specified: baselineTfBase, baselineTfMin"); } // sanity check that they aren't trying to use two diff tf impls if ((null != hyper_min) && (null != baseline_min)) { throw new SolrException(SERVER_ERROR, "Can not mix hyperbolicTf settings with baselineTf settings"); } // pick Similarity impl based on whether hyper tf settings are set sim = (null != hyper_min) ? new HyperbolicSweetSpotSimilarity() : new SweetSpotSimilarity(); if (null != ln_min) { // overlaps already handled by super factory sim.setLengthNormFactors(ln_min, ln_max, ln_steep, this.discountOverlaps); } if (null != hyper_min) { sim.setHyperbolicTfFactors(hyper_min, hyper_max, hyper_base, hyper_offset); } if (null != baseline_min) { sim.setBaselineTfFactors(baseline_base, baseline_min); } }
Example 11
Source File: SpellCheckComponent.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override @SuppressWarnings("unchecked") public void process(ResponseBuilder rb) throws IOException { SolrParams params = rb.req.getParams(); if (!params.getBool(COMPONENT_NAME, false) || spellCheckers.isEmpty()) { return; } boolean shardRequest = "true".equals(params.get(ShardParams.IS_SHARD)); String q = params.get(SPELLCHECK_Q); SolrSpellChecker spellChecker = getSpellChecker(params); Collection<Token> tokens = null; if (q != null) { //we have a spell check param, tokenize it with the query analyzer applicable for this spellchecker tokens = getTokens(q, spellChecker.getQueryAnalyzer()); } else { q = rb.getQueryString(); if (q == null) { q = params.get(CommonParams.Q); } tokens = queryConverter.convert(q); } if (tokens != null && tokens.isEmpty() == false) { if (spellChecker != null) { int count = params.getInt(SPELLCHECK_COUNT, 1); boolean onlyMorePopular = params.getBool(SPELLCHECK_ONLY_MORE_POPULAR, DEFAULT_ONLY_MORE_POPULAR); boolean extendedResults = params.getBool(SPELLCHECK_EXTENDED_RESULTS, false); boolean collate = params.getBool(SPELLCHECK_COLLATE, false); float accuracy = params.getFloat(SPELLCHECK_ACCURACY, Float.MIN_VALUE); int alternativeTermCount = params.getInt(SpellingParams.SPELLCHECK_ALTERNATIVE_TERM_COUNT, 0); //If specified, this can be a discrete # of results, or a percentage of fq results. Integer maxResultsForSuggest = maxResultsForSuggest(rb); ModifiableSolrParams customParams = new ModifiableSolrParams(); for (String checkerName : getDictionaryNames(params)) { customParams.add(getCustomParams(checkerName, params)); } Number hitsLong = (Number) rb.rsp.getToLog().get("hits"); long hits = 0; if (hitsLong == null) { hits = rb.getNumberDocumentsFound(); } else { hits = hitsLong.longValue(); } SpellingResult spellingResult = null; if (maxResultsForSuggest == null || hits <= maxResultsForSuggest) { SuggestMode suggestMode = SuggestMode.SUGGEST_WHEN_NOT_IN_INDEX; if (onlyMorePopular) { suggestMode = SuggestMode.SUGGEST_MORE_POPULAR; } else if (alternativeTermCount > 0) { suggestMode = SuggestMode.SUGGEST_ALWAYS; } IndexReader reader = rb.req.getSearcher().getIndexReader(); SpellingOptions options = new SpellingOptions(tokens, reader, count, alternativeTermCount, suggestMode, extendedResults, accuracy, customParams); spellingResult = spellChecker.getSuggestions(options); } else { spellingResult = new SpellingResult(); } boolean isCorrectlySpelled = hits > (maxResultsForSuggest==null ? 0 : maxResultsForSuggest); @SuppressWarnings({"rawtypes"}) NamedList response = new SimpleOrderedMap(); @SuppressWarnings({"rawtypes"}) NamedList suggestions = toNamedList(shardRequest, spellingResult, q, extendedResults); response.add("suggestions", suggestions); if (extendedResults) { response.add("correctlySpelled", isCorrectlySpelled); } if (collate) { addCollationsToResponse(params, spellingResult, rb, q, response, spellChecker.isSuggestionsMayOverlap()); } if (shardRequest) { addOriginalTermsToResponse(response, tokens); } rb.rsp.add("spellcheck", response); } else { throw new SolrException(SolrException.ErrorCode.NOT_FOUND, "Specified dictionaries do not exist: " + getDictionaryNameAsSingleString(getDictionaryNames(params))); } } }
Example 12
Source File: DirectSolrSpellChecker.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override @SuppressWarnings({"unchecked"}) public String init(@SuppressWarnings({"rawtypes"})NamedList config, SolrCore core) { SolrParams params = config.toSolrParams(); log.info("init: {}", config); String name = super.init(config, core); Comparator<SuggestWord> comp = SuggestWordQueue.DEFAULT_COMPARATOR; String compClass = (String) config.get(COMPARATOR_CLASS); if (compClass != null) { if (compClass.equalsIgnoreCase(SCORE_COMP)) comp = SuggestWordQueue.DEFAULT_COMPARATOR; else if (compClass.equalsIgnoreCase(FREQ_COMP)) comp = new SuggestWordFrequencyComparator(); else //must be a FQCN comp = (Comparator<SuggestWord>) core.getResourceLoader().newInstance(compClass, Comparator.class); } StringDistance sd = DirectSpellChecker.INTERNAL_LEVENSHTEIN; String distClass = (String) config.get(STRING_DISTANCE); if (distClass != null && !distClass.equalsIgnoreCase(INTERNAL_DISTANCE)) sd = core.getResourceLoader().newInstance(distClass, StringDistance.class); float minAccuracy = DEFAULT_ACCURACY; Float accuracy = params.getFloat(ACCURACY); if (accuracy != null) minAccuracy = accuracy; int maxEdits = DEFAULT_MAXEDITS; Integer edits = params.getInt(MAXEDITS); if (edits != null) maxEdits = edits; int minPrefix = DEFAULT_MINPREFIX; Integer prefix = params.getInt(MINPREFIX); if (prefix != null) minPrefix = prefix; int maxInspections = DEFAULT_MAXINSPECTIONS; Integer inspections = params.getInt(MAXINSPECTIONS); if (inspections != null) maxInspections = inspections; float minThreshold = DEFAULT_THRESHOLD_TOKEN_FREQUENCY; Float threshold = params.getFloat(THRESHOLD_TOKEN_FREQUENCY); if (threshold != null) minThreshold = threshold; int minQueryLength = DEFAULT_MINQUERYLENGTH; Integer queryLength = params.getInt(MINQUERYLENGTH); if (queryLength != null) minQueryLength = queryLength; int maxQueryLength = DEFAULT_MAXQUERYLENGTH; Integer overriddenMaxQueryLength = params.getInt(MAXQUERYLENGTH); if (overriddenMaxQueryLength != null) maxQueryLength = overriddenMaxQueryLength; float maxQueryFrequency = DEFAULT_MAXQUERYFREQUENCY; Float queryFreq = params.getFloat(MAXQUERYFREQUENCY); if (queryFreq != null) maxQueryFrequency = queryFreq; checker.setComparator(comp); checker.setDistance(sd); checker.setMaxEdits(maxEdits); checker.setMinPrefix(minPrefix); checker.setAccuracy(minAccuracy); checker.setThresholdFrequency(minThreshold); checker.setMaxInspections(maxInspections); checker.setMinQueryLength(minQueryLength); checker.setMaxQueryLength(maxQueryLength); checker.setMaxQueryFrequency(maxQueryFrequency); checker.setLowerCaseTerms(false); return name; }