本文整理汇总了Java中org.apache.solr.util.SolrPluginUtils.parseFieldBoosts方法的典型用法代码示例。如果您正苦于以下问题:Java SolrPluginUtils.parseFieldBoosts方法的具体用法?Java SolrPluginUtils.parseFieldBoosts怎么用?Java SolrPluginUtils.parseFieldBoosts使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.solr.util.SolrPluginUtils
的用法示例。
在下文中一共展示了SolrPluginUtils.parseFieldBoosts方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBoostFunctions
import org.apache.solr.util.SolrPluginUtils; //导入方法依赖的package包/类
/**
* Parses all function queries
*/
protected List<Query> getBoostFunctions() throws SyntaxError {
List<Query> boostFunctions = new LinkedList<>();
if (config.hasBoostFunctions()) {
for (String boostFunc : config.boostFuncs) {
if(null == boostFunc || "".equals(boostFunc)) continue;
Map<String,Float> ff = SolrPluginUtils.parseFieldBoosts(boostFunc);
for (String f : ff.keySet()) {
Query fq = subQuery(f, FunctionQParserPlugin.NAME).getQuery();
Float b = ff.get(f);
if (null != b) {
fq.setBoost(b);
}
boostFunctions.add(fq);
}
}
}
return boostFunctions;
}
示例2: addAliasesFromRequest
import org.apache.solr.util.SolrPluginUtils; //导入方法依赖的package包/类
/**
* Extracts all the aliased fields from the requests and adds them to up
*/
private void addAliasesFromRequest(ExtendedSolrQueryParser up, float tiebreaker) {
Iterator<String> it = config.solrParams.getParameterNamesIterator();
while(it.hasNext()) {
String param = it.next();
if(param.startsWith("f.") && param.endsWith(".qf")) {
// Add the alias
String fname = param.substring(2,param.length()-3);
String qfReplacement = config.solrParams.get(param);
Map<String,Float> parsedQf = SolrPluginUtils.parseFieldBoosts(qfReplacement);
if(parsedQf.size() == 0)
return;
up.addAlias(fname, tiebreaker, parsedQf);
}
}
}
示例3: addBoostFunctions
import org.apache.solr.util.SolrPluginUtils; //导入方法依赖的package包/类
protected void addBoostFunctions(BooleanQuery query, SolrParams solrParams) throws SyntaxError {
String[] boostFuncs = solrParams.getParams(DisMaxParams.BF);
if (null != boostFuncs && 0 != boostFuncs.length) {
for (String boostFunc : boostFuncs) {
if (null == boostFunc || "".equals(boostFunc)) continue;
Map<String, Float> ff = SolrPluginUtils.parseFieldBoosts(boostFunc);
for (String f : ff.keySet()) {
Query fq = subQuery(f, FunctionQParserPlugin.NAME).getQuery();
Float b = ff.get(f);
if (null != b) {
fq.setBoost(b);
}
query.add(fq, BooleanClause.Occur.SHOULD);
}
}
}
}
示例4: getBoostFunctions
import org.apache.solr.util.SolrPluginUtils; //导入方法依赖的package包/类
/**
* Parses all function queries
*/
protected List<Query> getBoostFunctions() throws SyntaxError {
List<Query> boostFunctions = new LinkedList<Query>();
if (config.hasBoostFunctions()) {
for (String boostFunc : config.boostFuncs) {
if(null == boostFunc || "".equals(boostFunc)) continue;
Map<String,Float> ff = SolrPluginUtils.parseFieldBoosts(boostFunc);
for (String f : ff.keySet()) {
Query fq = subQuery(f, FunctionQParserPlugin.NAME).getQuery();
Float b = ff.get(f);
if (null != b) {
fq.setBoost(b);
}
boostFunctions.add(fq);
}
}
}
return boostFunctions;
}
示例5: parseQueryFields
import org.apache.solr.util.SolrPluginUtils; //导入方法依赖的package包/类
/**
* Uses {@link SolrPluginUtils#parseFieldBoosts(String)} with the 'qf' parameter. Falls back to the 'df' parameter
* or {@link org.apache.solr.schema.IndexSchema#getDefaultSearchFieldName()}.
*/
public static Map<String, Float> parseQueryFields(final IndexSchema indexSchema, final SolrParams solrParams)
throws SyntaxError {
Map<String, Float> queryFields = SolrPluginUtils.parseFieldBoosts(solrParams.getParams(DisMaxParams.QF));
if (queryFields.isEmpty()) {
String df = QueryParsing.getDefaultField(indexSchema, solrParams.get(CommonParams.DF));
if (df == null) {
throw new SyntaxError("Neither "+DisMaxParams.QF+", "+CommonParams.DF +", nor the default search field are present.");
}
queryFields.put(df, 1.0f);
}
return queryFields;
}
示例6: addMainQuery
import org.apache.solr.util.SolrPluginUtils; //导入方法依赖的package包/类
/** Adds the main query to the query argument. If its blank then false is returned. */
protected boolean addMainQuery(BooleanQuery 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 (userQuery == null || userQuery.trim().length() < 1) {
// 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;
}
示例7: MoreLikeThisHelper
import org.apache.solr.util.SolrPluginUtils; //导入方法依赖的package包/类
public MoreLikeThisHelper( SolrParams params, SolrIndexSearcher searcher )
{
this.searcher = searcher;
this.reader = searcher.getIndexReader();
this.uniqueKeyField = searcher.getSchema().getUniqueKeyField();
this.needDocSet = params.getBool(FacetParams.FACET,false);
SolrParams required = params.required();
String[] fields = splitList.split( required.get(MoreLikeThisParams.SIMILARITY_FIELDS) );
if( fields.length < 1 ) {
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
"MoreLikeThis requires at least one similarity field: "+MoreLikeThisParams.SIMILARITY_FIELDS );
}
this.mlt = new MoreLikeThis( reader ); // TODO -- after LUCENE-896, we can use , searcher.getSimilarity() );
mlt.setFieldNames(fields);
mlt.setAnalyzer( searcher.getSchema().getIndexAnalyzer() );
// configurable params
mlt.setMinTermFreq( params.getInt(MoreLikeThisParams.MIN_TERM_FREQ, MoreLikeThis.DEFAULT_MIN_TERM_FREQ));
mlt.setMinDocFreq( params.getInt(MoreLikeThisParams.MIN_DOC_FREQ, MoreLikeThis.DEFAULT_MIN_DOC_FREQ));
mlt.setMaxDocFreq( params.getInt(MoreLikeThisParams.MAX_DOC_FREQ, MoreLikeThis.DEFAULT_MAX_DOC_FREQ));
mlt.setMinWordLen( params.getInt(MoreLikeThisParams.MIN_WORD_LEN, MoreLikeThis.DEFAULT_MIN_WORD_LENGTH));
mlt.setMaxWordLen( params.getInt(MoreLikeThisParams.MAX_WORD_LEN, MoreLikeThis.DEFAULT_MAX_WORD_LENGTH));
mlt.setMaxQueryTerms( params.getInt(MoreLikeThisParams.MAX_QUERY_TERMS, MoreLikeThis.DEFAULT_MAX_QUERY_TERMS));
mlt.setMaxNumTokensParsed(params.getInt(MoreLikeThisParams.MAX_NUM_TOKENS_PARSED, MoreLikeThis.DEFAULT_MAX_NUM_TOKENS_PARSED));
mlt.setBoost( params.getBool(MoreLikeThisParams.BOOST, false ) );
boostFields = SolrPluginUtils.parseFieldBoosts(params.getParams(MoreLikeThisParams.QF));
}
示例8: MultilanguageDismaxConfiguration
import org.apache.solr.util.SolrPluginUtils; //导入方法依赖的package包/类
public MultilanguageDismaxConfiguration(SolrParams localParams,
SolrParams params, SolrQueryRequest req) {
super(localParams, params, req);
String language = params.get("language");
if(language != null) {
super.queryFields = SolrPluginUtils.parseFieldBoosts(solrParams.getParams("qf_" + language));
}
}
示例9: MoreLikeThisHelper
import org.apache.solr.util.SolrPluginUtils; //导入方法依赖的package包/类
public MoreLikeThisHelper( SolrParams params, SolrIndexSearcher searcher )
{
this.searcher = searcher;
this.reader = searcher.getIndexReader();
this.uniqueKeyField = searcher.getSchema().getUniqueKeyField();
this.needDocSet = params.getBool(FacetParams.FACET,false);
SolrParams required = params.required();
String[] fields = splitList.split( required.get(MoreLikeThisParams.SIMILARITY_FIELDS) );
if( fields.length < 1 ) {
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
"MoreLikeThis requires at least one similarity field: "+MoreLikeThisParams.SIMILARITY_FIELDS );
}
this.mlt = new MoreLikeThis( reader ); // TODO -- after LUCENE-896, we can use , searcher.getSimilarity() );
mlt.setFieldNames(fields);
mlt.setAnalyzer( searcher.getSchema().getAnalyzer() );
// configurable params
mlt.setMinTermFreq( params.getInt(MoreLikeThisParams.MIN_TERM_FREQ, MoreLikeThis.DEFAULT_MIN_TERM_FREQ));
mlt.setMinDocFreq( params.getInt(MoreLikeThisParams.MIN_DOC_FREQ, MoreLikeThis.DEFAULT_MIN_DOC_FREQ));
mlt.setMaxDocFreq( params.getInt(MoreLikeThisParams.MAX_DOC_FREQ, MoreLikeThis.DEFAULT_MAX_DOC_FREQ));
mlt.setMinWordLen( params.getInt(MoreLikeThisParams.MIN_WORD_LEN, MoreLikeThis.DEFAULT_MIN_WORD_LENGTH));
mlt.setMaxWordLen( params.getInt(MoreLikeThisParams.MAX_WORD_LEN, MoreLikeThis.DEFAULT_MAX_WORD_LENGTH));
mlt.setMaxQueryTerms( params.getInt(MoreLikeThisParams.MAX_QUERY_TERMS, MoreLikeThis.DEFAULT_MAX_QUERY_TERMS));
mlt.setMaxNumTokensParsed(params.getInt(MoreLikeThisParams.MAX_NUM_TOKENS_PARSED, MoreLikeThis.DEFAULT_MAX_NUM_TOKENS_PARSED));
mlt.setBoost( params.getBool(MoreLikeThisParams.BOOST, false ) );
boostFields = SolrPluginUtils.parseFieldBoosts(params.getParams(MoreLikeThisParams.QF));
}
示例10: SimpleQParser
import org.apache.solr.util.SolrPluginUtils; //导入方法依赖的package包/类
public SimpleQParser (String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {
super(qstr, localParams, params, req);
// Some of the parameters may come in through localParams, so combine them with params.
SolrParams defaultParams = SolrParams.wrapDefaults(localParams, params);
// This will be used to specify what fields and boosts will be used by SimpleQueryParser.
Map<String, Float> queryFields = SolrPluginUtils.parseFieldBoosts(defaultParams.get(SimpleParams.QF));
if (queryFields.isEmpty()) {
// It qf is not specified setup up the queryFields map to use the defaultField.
String defaultField = QueryParsing.getDefaultField(req.getSchema(), defaultParams.get(CommonParams.DF));
if (defaultField == null) {
// A query cannot be run without having a field or set of fields to run against.
throw new IllegalStateException("Neither " + SimpleParams.QF + ", " + CommonParams.DF
+ ", nor the default search field are present.");
}
queryFields.put(defaultField, 1.0F);
}
else {
for (Map.Entry<String, Float> queryField : queryFields.entrySet()) {
if (queryField.getValue() == null) {
// Some fields may be specified without a boost, so default the boost to 1.0 since a null value
// will not be accepted by SimpleQueryParser.
queryField.setValue(1.0F);
}
}
}
// Setup the operations that are enabled for the query.
int enabledOps = 0;
String opParam = defaultParams.get(SimpleParams.QO);
if (opParam == null) {
// All operations will be enabled.
enabledOps = -1;
} else {
// Parse the specified enabled operations to be used by the query.
String[] operations = opParam.split(",");
for (String operation : operations) {
Integer enabledOp = OPERATORS.get(operation.trim().toUpperCase(Locale.ROOT));
if (enabledOp != null) {
enabledOps |= enabledOp;
}
}
}
// Create a SimpleQueryParser using the analyzer from the schema.
final IndexSchema schema = req.getSchema();
parser = new SolrSimpleQueryParser(req.getSchema().getQueryAnalyzer(), queryFields, enabledOps, this, schema);
// Set the default operator to be either 'AND' or 'OR' for the query.
QueryParser.Operator defaultOp = QueryParsing.getQueryParserDefaultOperator(req.getSchema(), defaultParams.get(QueryParsing.OP));
if (defaultOp == QueryParser.Operator.AND) {
parser.setDefaultOperator(BooleanClause.Occur.MUST);
}
}
示例11: SafariQueryParser
import org.apache.solr.util.SolrPluginUtils; //导入方法依赖的package包/类
public SafariQueryParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {
super(qstr, localParams, params, req);
SolrParams solrParams = SolrParams.wrapDefaults(localParams, params);
phraseFields = SolrPluginUtils.parseFieldBoosts(solrParams.getParams(PQF));
}
示例12: TermInspectingDismaxQueryConfiguration
import org.apache.solr.util.SolrPluginUtils; //导入方法依赖的package包/类
TermInspectingDismaxQueryConfiguration(SolrParams localParams, SolrParams params) {
solrParams = SolrParams.wrapDefaults(localParams, params);
queryFields = SolrPluginUtils.parseFieldBoosts(solrParams.get(DisMaxParams.QF));
tiebreaker = solrParams.getFloat(DisMaxParams.TIE, 0.0f);
inspectTerms = solrParams.getBool(BmaxQueryParser.PARAM_INSPECT_TERMS, false);
}
示例13: SimpleQParser
import org.apache.solr.util.SolrPluginUtils; //导入方法依赖的package包/类
public SimpleQParser (String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {
super(qstr, localParams, params, req);
// Some of the parameters may come in through localParams, so combine them with params.
SolrParams defaultParams = SolrParams.wrapDefaults(localParams, params);
// This will be used to specify what fields and boosts will be used by SimpleQueryParser.
Map<String, Float> queryFields = SolrPluginUtils.parseFieldBoosts(defaultParams.get(SimpleParams.QF));
if (queryFields.isEmpty()) {
// It qf is not specified setup up the queryFields map to use the defaultField.
String defaultField = QueryParsing.getDefaultField(req.getSchema(), defaultParams.get(CommonParams.DF));
if (defaultField == null) {
// A query cannot be run without having a field or set of fields to run against.
throw new IllegalStateException("Neither " + SimpleParams.QF + ", " + CommonParams.DF
+ ", nor the default search field are present.");
}
queryFields.put(defaultField, 1.0F);
}
else {
for (Map.Entry<String, Float> queryField : queryFields.entrySet()) {
if (queryField.getValue() == null) {
// Some fields may be specified without a boost, so default the boost to 1.0 since a null value
// will not be accepted by SimpleQueryParser.
queryField.setValue(1.0F);
}
}
}
// Setup the operations that are enabled for the query.
int enabledOps = 0;
String opParam = defaultParams.get(SimpleParams.QO);
if (opParam == null) {
// All operations will be enabled.
enabledOps = -1;
} else {
// Parse the specified enabled operations to be used by the query.
String[] operations = opParam.split(",");
for (String operation : operations) {
Integer enabledOp = OPERATORS.get(operation.trim().toUpperCase(Locale.ROOT));
if (enabledOp != null) {
enabledOps |= enabledOp;
}
}
}
// Create a SimpleQueryParser using the analyzer from the schema.
final IndexSchema schema = req.getSchema();
parser = new SolrSimpleQueryParser(req.getSchema().getAnalyzer(), queryFields, enabledOps, this, schema);
// Set the default operator to be either 'AND' or 'OR' for the query.
QueryParser.Operator defaultOp = QueryParsing.getQueryParserDefaultOperator(req.getSchema(), defaultParams.get(QueryParsing.OP));
if (defaultOp == QueryParser.Operator.AND) {
parser.setDefaultOperator(BooleanClause.Occur.MUST);
}
}