public class MultiFieldQueryParser extends QueryParser
QueryParser.OperatorQueryParserBase.MethodRemovedUseAnotherjj_nt, token, token_sourceAND_OPERATOR, OR_OPERATOR_ESCAPED_CHAR, _NUM_CHAR, _QUOTED_CHAR, _TERM_CHAR, _TERM_START_CHAR, _WHITESPACE, AND, BAREOPER, Boost, CARAT, COLON, DEFAULT, EOF, FUZZY_SLOP, LPAREN, MINUS, NOT, NUMBER, OR, PLUS, PREFIXTERM, QUOTED, Range, RANGE_GOOP, RANGE_QUOTED, RANGE_TO, RANGEEX_END, RANGEEX_START, RANGEIN_END, RANGEIN_START, REGEXPTERM, RPAREN, STAR, TERM, tokenImage, WILDTERM| Constructor and Description |
|---|
MultiFieldQueryParser(Version matchVersion,
String[] fields,
Analyzer analyzer)
Creates a MultiFieldQueryParser.
|
MultiFieldQueryParser(Version matchVersion,
String[] fields,
Analyzer analyzer,
Map<String,Float> boosts)
Creates a MultiFieldQueryParser.
|
| Modifier and Type | Method and Description |
|---|---|
static Query |
parse(Version matchVersion,
String[] queries,
String[] fields,
Analyzer analyzer)
Parses a query which searches on the fields specified.
|
static Query |
parse(Version matchVersion,
String[] queries,
String[] fields,
BooleanClause.Occur[] flags,
Analyzer analyzer)
Parses a query, searching on the fields specified.
|
static Query |
parse(Version matchVersion,
String query,
String[] fields,
BooleanClause.Occur[] flags,
Analyzer analyzer)
Parses a query, searching on the fields specified.
|
Clause, Conjunction, disable_tracing, enable_tracing, generateParseException, getNextToken, getToken, Modifiers, Query, ReInit, ReInit, Term, TopLevelQueryescape, getAllowLeadingWildcard, getAnalyzeRangeTerms, getAutoGeneratePhraseQueries, getDateResolution, getDefaultOperator, getField, getFuzzyMinSim, getFuzzyPrefixLength, getLocale, getLowercaseExpandedTerms, getMultiTermRewriteMethod, getPhraseSlop, getTimeZone, init, parse, setAllowLeadingWildcard, setAnalyzeRangeTerms, setAutoGeneratePhraseQueries, setDateResolution, setDateResolution, setDefaultOperator, setFuzzyMinSim, setFuzzyPrefixLength, setLocale, setLowercaseExpandedTerms, setMultiTermRewriteMethod, setPhraseSlop, setTimeZonecreateBooleanQuery, createBooleanQuery, createMinShouldMatchQuery, createPhraseQuery, createPhraseQuery, getAnalyzer, getEnablePositionIncrements, setAnalyzer, setEnablePositionIncrementsequals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetAnalyzer, getEnablePositionIncrements, setEnablePositionIncrementspublic MultiFieldQueryParser(Version matchVersion, String[] fields, Analyzer analyzer, Map<String,Float> boosts)
It will, when parse(String query)
is called, construct a query like this (assuming the query consists of
two terms and you specify the two fields title and body):
(title:term1 body:term1) (title:term2 body:term2)
When setDefaultOperator(AND_OPERATOR) is set, the result will be:
+(title:term1 body:term1) +(title:term2 body:term2)
When you pass a boost (title=>5 body=>10) you can get
+(title:term1^5.0 body:term1^10.0) +(title:term2^5.0 body:term2^10.0)
In other words, all the query's terms must appear, but it doesn't matter in what fields they appear.
public MultiFieldQueryParser(Version matchVersion, String[] fields, Analyzer analyzer)
It will, when parse(String query)
is called, construct a query like this (assuming the query consists of
two terms and you specify the two fields title and body):
(title:term1 body:term1) (title:term2 body:term2)
When setDefaultOperator(AND_OPERATOR) is set, the result will be:
+(title:term1 body:term1) +(title:term2 body:term2)
In other words, all the query's terms must appear, but it doesn't matter in what fields they appear.
public static Query parse(Version matchVersion, String[] queries, String[] fields, Analyzer analyzer) throws ParseException
If x fields are specified, this effectively constructs:
(field1:query1) (field2:query2) (field3:query3)...(fieldx:queryx)
matchVersion - Lucene version to match; this is passed through to QueryParser.queries - Queries strings to parsefields - Fields to search onanalyzer - Analyzer to useParseException - if query parsing failsIllegalArgumentException - if the length of the queries array differs
from the length of the fields arraypublic static Query parse(Version matchVersion, String query, String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer) throws ParseException
Usage:
String[] fields = {"filename", "contents", "description"};
BooleanClause.Occur[] flags = {BooleanClause.Occur.SHOULD,
BooleanClause.Occur.MUST,
BooleanClause.Occur.MUST_NOT};
MultiFieldQueryParser.parse("query", fields, flags, analyzer);
The code above would construct a query:
(filename:query) +(contents:query) -(description:query)
matchVersion - Lucene version to match; this is passed through to QueryParser.query - Query string to parsefields - Fields to search onflags - Flags describing the fieldsanalyzer - Analyzer to useParseException - if query parsing failsIllegalArgumentException - if the length of the fields array differs
from the length of the flags arraypublic static Query parse(Version matchVersion, String[] queries, String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer) throws ParseException
Usage:
String[] query = {"query1", "query2", "query3"};
String[] fields = {"filename", "contents", "description"};
BooleanClause.Occur[] flags = {BooleanClause.Occur.SHOULD,
BooleanClause.Occur.MUST,
BooleanClause.Occur.MUST_NOT};
MultiFieldQueryParser.parse(query, fields, flags, analyzer);
The code above would construct a query:
(filename:query1) +(contents:query2) -(description:query3)
matchVersion - Lucene version to match; this is passed through to QueryParser.queries - Queries string to parsefields - Fields to search onflags - Flags describing the fieldsanalyzer - Analyzer to useParseException - if query parsing failsIllegalArgumentException - if the length of the queries, fields,
and flags array differCopyright © 2010 - 2020 Adobe. All Rights Reserved