Save This Page
Home » lucene-2.3.2-src » org.apache » lucene » queryParser » [javadoc | source]
org.apache.lucene.queryParser
public class: MultiFieldQueryParser [javadoc | source]
java.lang.Object
   org.apache.lucene.queryParser.QueryParser
      org.apache.lucene.queryParser.MultiFieldQueryParser

All Implemented Interfaces:
    QueryParserConstants

A QueryParser which constructs queries to search multiple fields.
Field Summary
protected  String[] fields     
protected  Map boosts     
Fields inherited from org.apache.lucene.queryParser.QueryParser:
AND_OPERATOR,  OR_OPERATOR,  lowercaseExpandedTerms,  useOldRangeQuery,  allowLeadingWildcard,  enablePositionIncrements,  analyzer,  field,  phraseSlop,  fuzzyMinSim,  fuzzyPrefixLength,  locale,  dateResolution,  fieldToDateResolution,  token_source,  token,  jj_nt,  lookingAhead
Constructor:
 public MultiFieldQueryParser(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 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 MultiFieldQueryParser(String[] fields,
    Analyzer analyzer,
    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 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.

Method from org.apache.lucene.queryParser.MultiFieldQueryParser Summary:
getFieldQuery,   getFieldQuery,   getFuzzyQuery,   getPrefixQuery,   getRangeQuery,   getWildcardQuery,   parse,   parse,   parse
Methods from org.apache.lucene.queryParser.QueryParser:
Clause,   Conjunction,   Modifiers,   Query,   ReInit,   ReInit,   Term,   TopLevelQuery,   addClause,   disable_tracing,   enable_tracing,   escape,   generateParseException,   getAllowLeadingWildcard,   getAnalyzer,   getBooleanQuery,   getBooleanQuery,   getDateResolution,   getDefaultOperator,   getEnablePositionIncrements,   getField,   getFieldQuery,   getFieldQuery,   getFuzzyMinSim,   getFuzzyPrefixLength,   getFuzzyQuery,   getLocale,   getLowercaseExpandedTerms,   getNextToken,   getPhraseSlop,   getPrefixQuery,   getRangeQuery,   getToken,   getUseOldRangeQuery,   getWildcardQuery,   main,   parse,   setAllowLeadingWildcard,   setDateResolution,   setDateResolution,   setDefaultOperator,   setEnablePositionIncrements,   setFuzzyMinSim,   setFuzzyPrefixLength,   setLocale,   setLowercaseExpandedTerms,   setPhraseSlop,   setUseOldRangeQuery
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.lucene.queryParser.MultiFieldQueryParser Detail:
 protected Query getFieldQuery(String field,
    String queryText) throws ParseException 
 protected Query getFieldQuery(String field,
    String queryText,
    int slop) throws ParseException 
 protected Query getFuzzyQuery(String field,
    String termStr,
    float minSimilarity) throws ParseException 
 protected Query getPrefixQuery(String field,
    String termStr) throws ParseException 
 protected Query getRangeQuery(String field,
    String part1,
    String part2,
    boolean inclusive) throws ParseException 
 protected Query getWildcardQuery(String field,
    String termStr) throws ParseException 
 public static Query parse(String[] queries,
    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)
    
    
 public static Query parse(String query,
    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)
    
    
 public static Query parse(String[] queries,
    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)