Class MultiFieldQueryParser
- java.lang.Object
-
- org.apache.lucene.queryParser.QueryParser
-
- org.apache.lucene.queryParser.MultiFieldQueryParser
-
- All Implemented Interfaces:
- QueryParserConstants
public class MultiFieldQueryParser extends QueryParser
A QueryParser which constructs queries to search multiple fields.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.lucene.queryParser.QueryParser
QueryParser.Operator
-
-
Field Summary
-
Fields inherited from class org.apache.lucene.queryParser.QueryParser
AND_OPERATOR, jj_nt, lookingAhead, OR_OPERATOR, token, token_source
-
Fields inherited from interface org.apache.lucene.queryParser.QueryParserConstants
_ESCAPED_CHAR, _NUM_CHAR, _TERM_CHAR, _TERM_START_CHAR, _WHITESPACE, AND, Boost, CARAT, COLON, DEFAULT, EOF, FUZZY_SLOP, LPAREN, MINUS, NOT, NUMBER, OR, PLUS, PREFIXTERM, QUOTED, RangeEx, RANGEEX_END, RANGEEX_GOOP, RANGEEX_QUOTED, RANGEEX_START, RANGEEX_TO, RangeIn, RANGEIN_END, RANGEIN_GOOP, RANGEIN_QUOTED, RANGEIN_START, RANGEIN_TO, RPAREN, STAR, TERM, tokenImage, WILDTERM
-
-
Constructor Summary
Constructors Constructor and Description MultiFieldQueryParser(java.lang.String[] fields, Analyzer analyzer)Creates a MultiFieldQueryParser.MultiFieldQueryParser(java.lang.String[] fields, Analyzer analyzer, java.util.Map boosts)Creates a MultiFieldQueryParser.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static Queryparse(java.lang.String[] queries, java.lang.String[] fields, Analyzer analyzer)Parses a query which searches on the fields specified.static Queryparse(java.lang.String[] queries, java.lang.String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer)Parses a query, searching on the fields specified.static Queryparse(java.lang.String query, java.lang.String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer)Parses a query, searching on the fields specified.-
Methods inherited from class org.apache.lucene.queryParser.QueryParser
Clause, Conjunction, disable_tracing, enable_tracing, escape, generateParseException, getAllowLeadingWildcard, getAnalyzer, getDateResolution, getDefaultOperator, getEnablePositionIncrements, getField, getFuzzyMinSim, getFuzzyPrefixLength, getLocale, getLowercaseExpandedTerms, getNextToken, getPhraseSlop, getToken, getUseOldRangeQuery, main, Modifiers, parse, Query, ReInit, ReInit, setAllowLeadingWildcard, setDateResolution, setDateResolution, setDefaultOperator, setEnablePositionIncrements, setFuzzyMinSim, setFuzzyPrefixLength, setLocale, setLowercaseExpandedTerms, setPhraseSlop, setUseOldRangeQuery, Term, TopLevelQuery
-
-
-
-
Constructor Detail
-
MultiFieldQueryParser
public MultiFieldQueryParser(java.lang.String[] fields, Analyzer analyzer, java.util.Map boosts)Creates a MultiFieldQueryParser. Allows passing of a map with term to Boost, and the boost to apply to each term.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
titleandbody):(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.
-
MultiFieldQueryParser
public MultiFieldQueryParser(java.lang.String[] fields, Analyzer analyzer)Creates a MultiFieldQueryParser.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
titleandbody):(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.
-
-
Method Detail
-
parse
public static Query parse(java.lang.String[] queries, java.lang.String[] fields, Analyzer analyzer) throws ParseException
Parses a query which searches on the fields specified.If x fields are specified, this effectively constructs:
(field1:query1) (field2:query2) (field3:query3)...(fieldx:queryx)- Parameters:
queries- Queries strings to parsefields- Fields to search onanalyzer- Analyzer to use- Throws:
ParseException- if query parsing failsjava.lang.IllegalArgumentException- if the length of the queries array differs from the length of the fields array
-
parse
public static Query parse(java.lang.String query, java.lang.String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer) throws ParseException
Parses a query, searching on the fields specified. Use this if you need to specify certain fields as required, and others as prohibited.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)- Parameters:
query- Query string to parsefields- Fields to search onflags- Flags describing the fieldsanalyzer- Analyzer to use- Throws:
ParseException- if query parsing failsjava.lang.IllegalArgumentException- if the length of the fields array differs from the length of the flags array
-
parse
public static Query parse(java.lang.String[] queries, java.lang.String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer) throws ParseException
Parses a query, searching on the fields specified. Use this if you need to specify certain fields as required, and others as prohibited.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)- Parameters:
queries- Queries string to parsefields- Fields to search onflags- Flags describing the fieldsanalyzer- Analyzer to use- Throws:
ParseException- if query parsing failsjava.lang.IllegalArgumentException- if the length of the queries, fields, and flags array differ
-
-
DataMelt 3.0 © DataMelt by jWork.ORG