本文整理汇总了Java中org.apache.solr.parser.QueryParser类的典型用法代码示例。如果您正苦于以下问题:Java QueryParser类的具体用法?Java QueryParser怎么用?Java QueryParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
QueryParser类属于org.apache.solr.parser包,在下文中一共展示了QueryParser类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getLuceneQuery
import org.apache.solr.parser.QueryParser; //导入依赖的package包/类
/**
* Returns the Lucene query for the given locale and query text.
*
* @param searchString
* the text query for the Lucene query parser
* @param mId
* the marketplace id
* @param locale
* the locale for the analyzer to use
* @param isDefaultLocaleHandling
* @return the Lucene query for the given locale and query text
* @throws ParseException
* in case the query cannot be parsed
*/
private org.apache.lucene.search.Query getLuceneQuery(String searchString,
String mId, String locale, boolean isDefaultLocaleHandling)
throws SyntaxError, QueryNodeException {
// construct wildcard query for the actual search part
org.apache.lucene.search.Query textQuery = LuceneQueryBuilder
.getServiceQuery(searchString, locale, DEFAULT_LOCALE,
isDefaultLocaleHandling);
// build mId part
TermQuery mIdQuery = new TermQuery(new Term(ProductClassBridge.MP_ID,
QueryParser.escape(mId).toLowerCase()));
// now construct final query
BooleanQuery query = new BooleanQuery();
query.add(mIdQuery, Occur.MUST);
query.add(textQuery, Occur.MUST);
return query;
}
开发者ID:servicecatalog,项目名称:oscm,代码行数:34,代码来源:SearchServiceBean.java
示例2: getLuceneQuery
import org.apache.solr.parser.QueryParser; //导入依赖的package包/类
/**
* Returns the Lucene query for the given locale and query text.
*
* @param searchString
* the text query for the Lucene query parser
* @param mId
* the marketplace id
* @param locale
* the locale for the analyzer to use
* @param isDefaultLocaleHandling
* @return the Lucene query for the given locale and query text
* @throws ParseException
* in case the query cannot be parsed
*/
private org.apache.lucene.search.Query getLuceneQuery(String searchString,
String mId, String locale,
boolean isDefaultLocaleHandling) throws SyntaxError, QueryNodeException {
// construct wildcard query for the actual search part
org.apache.lucene.search.Query textQuery = LuceneQueryBuilder
.getServiceQuery(searchString, locale, DEFAULT_LOCALE,
isDefaultLocaleHandling);
// build mId part
TermQuery mIdQuery = new TermQuery(new Term(ProductClassBridge.MP_ID,
QueryParser.escape(mId).toLowerCase()));
// now construct final query
BooleanQuery query = new BooleanQuery();
query.add(mIdQuery, Occur.MUST);
query.add(textQuery, Occur.MUST);
return query;
}
开发者ID:servicecatalog,项目名称:development,代码行数:34,代码来源:SearchServiceBean.java
示例3: parse
import org.apache.solr.parser.QueryParser; //导入依赖的package包/类
@Override
public Query parse() throws SyntaxError {
String qstr = getString();
String defaultField = getParam(CommonParams.DF);
if (defaultField == null) {
defaultField = getReq().getSchema().getDefaultSearchFieldName();
}
lparser = new ComplexPhraseQueryParser(defaultField, getReq().getSchema().getQueryAnalyzer());
if (localParams != null)
inOrder = localParams.getBool("inOrder", inOrder);
lparser.setInOrder(inOrder);
QueryParser.Operator defaultOperator = QueryParsing.getQueryParserDefaultOperator(getReq().getSchema(), getParam(QueryParsing.OP));
if (QueryParser.Operator.AND.equals(defaultOperator))
lparser.setDefaultOperator(org.apache.lucene.queryparser.classic.QueryParser.Operator.AND);
else
lparser.setDefaultOperator(org.apache.lucene.queryparser.classic.QueryParser.Operator.OR);
try {
return lparser.parse(qstr);
} catch (ParseException pe) {
throw new SyntaxError(pe);
}
}
开发者ID:europeana,项目名称:search,代码行数:30,代码来源:ComplexPhraseQParserPlugin.java
示例4: escapeQuery
import org.apache.solr.parser.QueryParser; //导入依赖的package包/类
/**
* Escape special characters and Solr reserved words.
*/
public static String escapeQuery(String value) {
if (value.equals(QueryParser.Operator.AND.name()) || value.equals(QueryParser.Operator.OR.name())
|| value.equals(SolrConstants.SOLR_NOT_OP)) {
return toPhraseQuery(ClientUtils.escapeQueryChars(value));
}
return ClientUtils.escapeQueryChars(value);
}
开发者ID:gbif,项目名称:common-search,代码行数:11,代码来源:QueryUtils.java
示例5: SpanQParser
import org.apache.solr.parser.QueryParser; //导入依赖的package包/类
public SpanQParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req){
super(qstr, localParams, params, req);
IndexSchema schema = req.getSchema();
//preamble to initializing the parser
Analyzer analyzer;
defaultFieldName = getDefaultField(schema);
SchemaField sf = schema.getField(defaultFieldName);
if(sf != null && sf.getType() != null)
analyzer = sf.getType().getQueryAnalyzer();
else
analyzer = schema.getQueryAnalyzer(); //default analyzer?
//initialize the parser
parser = new SolrSpanQueryParser(defaultFieldName, analyzer, schema, this);
//now set the params
SolrParams solrParams = SolrParams.wrapDefaults(localParams, params);
parser.setAllowLeadingWildcard(solrParams.getBool(ALLOW_LEADING_WILDCARD, true));
// parser.setAnalyzeRangeTerms(solrParams.getBool(ANALYZE_RANGE_TERMS, true));
parser.setAutoGeneratePhraseQueries(solrParams.getBool(AUTO_GENERATE_PHRASE, false));
QueryParser.Operator defaultOp =
QueryParsing.getQueryParserDefaultOperator(req.getSchema(), solrParams.get(QueryParsing.OP));
if (defaultOp == QueryParser.Operator.AND) {
parser.setDefaultOperator(Operator.AND);
}
parser.setFuzzyMaxEdits(solrParams.getInt(MAX_FUZZY_EDITS, 2));
parser.setFuzzyPrefixLength(solrParams.getInt(PREFIX_LENGTH, 0));
parser.setPhraseSlop(solrParams.getInt(PHRASE_SLOP, 0));
parser.setSpanNearMaxDistance(solrParams.getInt(NEAR_MAX, -1));
parser.setSpanNotNearMaxDistance(solrParams.getInt(NOT_NEAR_MAX, -1));
}
开发者ID:tballison,项目名称:lucene-addons,代码行数:39,代码来源:SpanQParser.java
示例6: SimpleQParser
import org.apache.solr.parser.QueryParser; //导入依赖的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);
}
}
开发者ID:europeana,项目名称:search,代码行数:63,代码来源:SimpleQParserPlugin.java
示例7: ExtendedSolrQueryParser
import org.apache.solr.parser.QueryParser; //导入依赖的package包/类
public ExtendedSolrQueryParser(QParser parser, String defaultField) {
super(parser, defaultField);
// don't trust that our parent class won't ever change it's default
setDefaultOperator(QueryParser.Operator.OR);
}
开发者ID:europeana,项目名称:search,代码行数:6,代码来源:ExtendedDismaxQParser.java
示例8: DisjunctionMaxQueryParser
import org.apache.solr.parser.QueryParser; //导入依赖的package包/类
public DisjunctionMaxQueryParser(QParser qp, String defaultField) {
super(qp,defaultField);
// don't trust that our parent class won't ever change it's default
setDefaultOperator(QueryParser.Operator.OR);
}
开发者ID:europeana,项目名称:search,代码行数:6,代码来源:SolrPluginUtils.java
示例9: SimpleQParser
import org.apache.solr.parser.QueryParser; //导入依赖的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);
}
}
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:63,代码来源:SimpleQParserPlugin.java
示例10: parseMinShouldMatch
import org.apache.solr.parser.QueryParser; //导入依赖的package包/类
/**
* Applies the appropriate default rules for the "mm" param based on the
* effective value of the "q.op" param
*
* @see QueryParsing#getQueryParserDefaultOperator
* @see QueryParsing#OP
* @see DisMaxParams#MM
*/
public static String parseMinShouldMatch(final IndexSchema schema,
final SolrParams params) {
org.apache.solr.parser.QueryParser.Operator op = QueryParsing.getQueryParserDefaultOperator
(schema, params.get(QueryParsing.OP));
return params.get(DisMaxParams.MM,
op.equals(QueryParser.Operator.AND) ? "100%" : "0%");
}
开发者ID:europeana,项目名称:search,代码行数:16,代码来源:DisMaxQParser.java
示例11: getQueryParserDefaultOperator
import org.apache.solr.parser.QueryParser; //导入依赖的package包/类
/**
* Returns the "preferred" default operator for use by Query Parsers,
* based on the settings in the IndexSchema which may be overridden using
* an optional String override value.
*
* @see IndexSchema#getQueryParserDefaultOperator()
* @see #OP
*/
public static QueryParser.Operator getQueryParserDefaultOperator(final IndexSchema sch,
final String override) {
String val = override;
if (null == val) val = sch.getQueryParserDefaultOperator();
return "AND".equals(val) ? QueryParser.Operator.AND : QueryParser.Operator.OR;
}
开发者ID:europeana,项目名称:search,代码行数:15,代码来源:QueryParsing.java
注:本文中的org.apache.solr.parser.QueryParser类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论