org.apache.lucene.queryParser

Class MultiFieldQueryParser

public class MultiFieldQueryParser extends QueryParser

A QueryParser which constructs queries to search multiple fields.

Version: $Revision: 1.4 $

Author: Kelvin Tan

Field Summary
static intNORMAL_FIELD
static intPROHIBITED_FIELD
static intREQUIRED_FIELD
Constructor Summary
MultiFieldQueryParser(QueryParserTokenManager tm)
MultiFieldQueryParser(CharStream stream)
MultiFieldQueryParser(String f, Analyzer a)
Method Summary
static Queryparse(String query, String[] fields, Analyzer analyzer)

Parses a query which searches on the fields specified.

static Queryparse(String query, String[] fields, int[] flags, Analyzer analyzer)

Parses a query, searching on the fields specified.

Field Detail

NORMAL_FIELD

public static final int NORMAL_FIELD

PROHIBITED_FIELD

public static final int PROHIBITED_FIELD

REQUIRED_FIELD

public static final int REQUIRED_FIELD

Constructor Detail

MultiFieldQueryParser

public MultiFieldQueryParser(QueryParserTokenManager tm)

MultiFieldQueryParser

public MultiFieldQueryParser(CharStream stream)

MultiFieldQueryParser

public MultiFieldQueryParser(String f, Analyzer a)

Method Detail

parse

public static Query parse(String query, String[] fields, Analyzer analyzer)

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

parse

public static Query parse(String query, String[] fields, int[] flags, Analyzer analyzer)

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

Copyright © 2000-2007 Apache Software Foundation. All Rights Reserved.