org.apache.lucene.queryParser
public class MultiFieldQueryParser extends QueryParser
Version: $Revision: 1.4 $
| Field Summary | |
|---|---|
| static int | NORMAL_FIELD |
| static int | PROHIBITED_FIELD |
| static int | REQUIRED_FIELD |
| Constructor Summary | |
|---|---|
| MultiFieldQueryParser(QueryParserTokenManager tm) | |
| MultiFieldQueryParser(CharStream stream) | |
| MultiFieldQueryParser(String f, Analyzer a) | |
| Method Summary | |
|---|---|
| static Query | parse(String query, String[] fields, Analyzer analyzer) Parses a query which searches on the fields specified. |
| static Query | parse(String query, String[] fields, int[] flags, Analyzer analyzer) Parses a query, searching on the fields specified. |
Parses a query which searches on the fields specified.
If x fields are specified, this effectively constructs:
(field1:query) (field2:query) (field3:query)...(fieldx:query)
Parameters: query Query string to parse fields Fields to search on analyzer Analyzer to use
Throws: ParseException if query parsing fails TokenMgrError if query parsing fails
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"};
int[] flags = {MultiFieldQueryParser.NORMAL FIELD,
MultiFieldQueryParser.REQUIRED FIELD,
MultiFieldQueryParser.PROHIBITED FIELD,};
parse(query, fields, flags, analyzer);
The code above would construct a query:
(filename:query) +(contents:query) -(description:query)
Parameters: query Query string to parse fields Fields to search on flags Flags describing the fields analyzer Analyzer to use
Throws: ParseException if query parsing fails TokenMgrError if query parsing fails