org.apache.lucene.queryParser
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.
- Version:
- $Revision: 1.2 $
- Author:
- Kelvin Tan
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, LPAREN, MINUS, NOT, NUMBER, OR, PLUS, PREFIXTERM, QUOTED, RANGEEX, RANGEIN, RPAREN, SLOP, TERM, tokenImage, WILDTERM |
Methods inherited from class org.apache.lucene.queryParser.QueryParser |
Clause, Conjunction, disable_tracing, enable_tracing, generateParseException, getNextToken, getPhraseSlop, getToken, main, Modifiers, parse, parse, Query, ReInit, ReInit, setPhraseSlop, Term |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
NORMAL_FIELD
public static final int NORMAL_FIELD
REQUIRED_FIELD
public static final int REQUIRED_FIELD
PROHIBITED_FIELD
public static final int PROHIBITED_FIELD
MultiFieldQueryParser
public MultiFieldQueryParser(QueryParserTokenManager tm)
MultiFieldQueryParser
public MultiFieldQueryParser(CharStream stream)
MultiFieldQueryParser
public MultiFieldQueryParser(String f,
Analyzer a)
parse
public static Query parse(String query,
String[] fields,
Analyzer analyzer)
throws ParseException
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 parsefields
- Fields to search onanalyzer
- Analyzer to use- Throws:
ParserException
- if query parsing failsTokenMgrError
- if query parsing fails
parse
public static Query parse(String query,
String[] fields,
int[] 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"};
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 parsefields
- Fields to search onflags
- Flags describing the fieldsanalyzer
- Analyzer to use- Throws:
ParserException
- if query parsing failsTokenMgrError
- if query parsing fails
Copyright © 2000-2002 Apache Software Foundation. All Rights Reserved.