org.apache.lucene.search

Class Query

Implemented Interfaces:
Cloneable, Serializable
Known Direct Subclasses:
BooleanQuery, ConstantScoreQuery, ConstantScoreRangeQuery, DisjunctionMaxQuery, FilteredQuery, MatchAllDocsQuery, MultiPhraseQuery, MultiTermQuery, PhrasePrefixQuery, PhraseQuery, PrefixQuery, RangeQuery, SpanQuery, TermQuery

public abstract class Query
extends Object
implements Serializable, Cloneable

The abstract base class for queries.

Instantiable subclasses are:

A parser for queries is contained in:

See Also:
Serialized Form

Method Summary

Object
clone()
Returns a clone of this query.
Query
combine(Query[] queries)
Expert: called when re-writing queries under MultiSearcher.
protected Weight
createWeight(Searcher searcher)
Expert: Constructs an appropriate Weight implementation for this query.
void
extractTerms(Set terms)
Expert: adds all terms occuring in this query to the terms set.
float
getBoost()
Gets the boost for this clause.
Similarity
getSimilarity(Searcher searcher)
Expert: Returns the Similarity implementation to be used for this query.
static Query
mergeBooleanQueries(Query[] queries)
Expert: merges the clauses of a set of BooleanQuery's into a single BooleanQuery.
Query
rewrite(IndexReader reader)
Expert: called to re-write queries into primitive queries.
void
setBoost(float b)
Sets the boost for this query clause to b.
String
toString()
Prints a query to a string.
abstract String
toString(String field)
Prints a query to a string, with field as the default field for terms.
Weight
weight(Searcher searcher)
Expert: Constructs and initializes a Weight for a top-level query.

Method Details

clone

public Object clone()
Returns a clone of this query.

combine

public Query combine(Query[] queries)
Expert: called when re-writing queries under MultiSearcher. Create a single query suitable for use by all subsearchers (in 1-1 correspondence with queries). This is an optimization of the OR of all queries. We handle the common optimization cases of equal queries and overlapping clauses of boolean OR queries (as generated by MultiTermQuery.rewrite() and RangeQuery.rewrite()). Be careful overriding this method as queries[0] determines which method will be called and is not necessarily of the same type as the other queries.

createWeight

protected Weight createWeight(Searcher searcher)
            throws IOException
Expert: Constructs an appropriate Weight implementation for this query.

Only implemented by primitive queries, which re-write to themselves.


extractTerms

public void extractTerms(Set terms)

getBoost

public float getBoost()
Gets the boost for this clause. Documents matching this clause will (in addition to the normal weightings) have their score multiplied by b. The boost is 1.0 by default.

getSimilarity

public Similarity getSimilarity(Searcher searcher)
Expert: Returns the Similarity implementation to be used for this query. Subclasses may override this method to specify their own Similarity implementation, perhaps one that delegates through that of the Searcher. By default the Searcher's Similarity implementation is returned.

mergeBooleanQueries

public static Query mergeBooleanQueries(Query[] queries)
Expert: merges the clauses of a set of BooleanQuery's into a single BooleanQuery.

A utility for use by combine(Query[]) implementations.


rewrite

public Query rewrite(IndexReader reader)
            throws IOException
Expert: called to re-write queries into primitive queries. For example, a PrefixQuery will be rewritten into a BooleanQuery that consists of TermQuerys.

setBoost

public void setBoost(float b)
Sets the boost for this query clause to b. Documents matching this clause will (in addition to the normal weightings) have their score multiplied by b.

toString

public String toString()
Prints a query to a string.

toString

public abstract String toString(String field)
Prints a query to a string, with field as the default field for terms.

The representation used is one that is supposed to be readable by QueryParser. However, there are the following limitations:

  • If the query was created by the parser, the printed representation may not be exactly what was parsed. For example, characters that need to be escaped will be represented without the required backslash.
  • Some of the more complicated queries (e.g. span queries) don't have a representation that can be parsed by QueryParser.

weight

public Weight weight(Searcher searcher)
            throws IOException
Expert: Constructs and initializes a Weight for a top-level query.

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