org.compass.core
Interface CompassQueryBuilder

All Known Implementing Classes:
DefaultCompassQueryBuilder

public interface CompassQueryBuilder

The query builder is used to construct CompassQueryBuilder.ToCompassQuery programmatically. Simple queries, like le(String,Object), will generate a CompassQueryBuilder.ToCompassQuery. More complex ones, will return their respective builder to continue and bulid them (like multiPhrase(String)). Combining CompassQueryBuilder.ToCompassQuerys can be done using the bool() operation.

An example of building a query using the query builder:

 CompassQueryBuilder queryBuilder = session.queryBuilder();
 queryBuilder.bool().addMust(queryBuilder.term("name", "jack")).addMust(queryBuilder.lt("birthdate", "19500101"))
      .toQuery().hits();
 

Author:
kimchy

Nested Class Summary
static interface CompassQueryBuilder.CompassBooleanQueryBuilder
          A boolean query builder.
static interface CompassQueryBuilder.CompassMoreLikeThisQuery
          A more like this query builder (maps to Lucene MoreLikeThis feature withing the contrib queries package).
static interface CompassQueryBuilder.CompassMultiPhraseQueryBuilder
          A query builder that constructs a phrase query.
static interface CompassQueryBuilder.CompassMultiPropertyQueryStringBuilder
          Parses the query string into terms, which all of them are used against the given resource property name / meta-data.
static interface CompassQueryBuilder.CompassQuerySpanNearBuilder
          A span near query builder.
static interface CompassQueryBuilder.CompassQuerySpanOrBuilder
          Creates a span or query builder.
static interface CompassQueryBuilder.CompassQueryStringBuilder
          A query builder used to construct a query from a query string (i.e.
static interface CompassQueryBuilder.ToCompassQuery
          A general interface for internal builders that will create a CompassQuery.
 
Method Summary
 CompassQueryBuilder addAliasQueryIfNeeded(boolean addAliasQueryIfNeeded)
          Should the query builder wrap automatically any query that has dot path notation (such as alias.property) with specific narrowing to match the given alias.
 CompassQuery alias(String aliasValue)
          Returns a query that exactly match the given alias.
 CompassQuery between(String name, Object low, Object high, boolean inclusive)
          Creates a query where the resource property is between the given values.
 CompassQuery between(String name, Object low, Object high, boolean inclusive, boolean constantScore)
          Creates a query where the resource property is between the given values.
 CompassQueryBuilder.CompassBooleanQueryBuilder bool()
          Constructs a boolean query builder.
 CompassQueryBuilder.CompassBooleanQueryBuilder bool(boolean disableCoord)
          Constructs a boolean query builder, with coord disabled.
 CompassQueryBuilder convertOnlyWithDotPath(boolean convertOnlyWithDotPath)
          Should Compass use a converter for value passed even if there is no specific direct dot path notation to it.
 CompassQuery fuzzy(String name, String value)
          Creates a fuzzy query for the given resource property and the value.
 CompassQuery fuzzy(String name, String value, float minimumSimilarity)
          Creates a fuzzy query for the given resource property and the value.
 CompassQuery fuzzy(String name, String value, float minimumSimilarity, int prefixLength)
          Creates a fuzzy query for the given resource property and the value.
 CompassQuery ge(String name, Object value)
          Creates a query where the resource property is greater or equal (>=) to the given value.
 CompassQuery gt(String name, Object value)
          Creates a query where the resource property is greater than (>) to the given value.
 CompassQuery le(String name, Object value)
          Creates a query where the resource property is less or equal (<=) to the given value.
 CompassQuery lt(String name, Object value)
          Creates a query where the resource property is less than (<) the given value.
 CompassQuery matchAll()
          Creates a query that match all documents.
 CompassQueryBuilder.CompassMoreLikeThisQuery moreLikeThis(Reader reader)
          Constructs a more like this query to find hits that are similar to the give text represented by the reader.
 CompassQueryBuilder.CompassMoreLikeThisQuery moreLikeThis(String alias, Serializable id)
          Constructs a more like this query.
 CompassQueryBuilder.CompassMultiPhraseQueryBuilder multiPhrase(String name)
          Constructs a multi phrase query builder for the given resource property / meta-data name.
 CompassQueryBuilder.CompassMultiPropertyQueryStringBuilder multiPropertyQueryString(String queryString)
          Constructs a multi property query string builder, allowing to execute query strings against several resource property names.
 CompassQuery polyAlias(String aliasValue)
          Returns a query that match the given alias or any extedning aliases.
 CompassQuery prefix(String name, String prefix)
          Creates a query where the resource property values starts with the given prefix.
 CompassQueryBuilder.CompassQueryStringBuilder queryString(String queryString)
          Constructs a query string query builder.
 CompassQuery.CompassSpanQuery spanEq(String name, Object value)
          Creates a span query where the resource property must match the given value.
 CompassQuery.CompassSpanQuery spanFirst(CompassQuery.CompassSpanQuery spanQuery, int end)
          Creates a span query.
 CompassQuery.CompassSpanQuery spanFirst(String name, Object value, int end)
          Creates a span query where the span occur within the first end positions.
 CompassQueryBuilder.CompassQuerySpanNearBuilder spanNear(String name)
          Constructs a span near query builder.
 CompassQuery.CompassSpanQuery spanNot(CompassQuery.CompassSpanQuery include, CompassQuery.CompassSpanQuery exclude)
          Creates a span query that excludes matches where one CompassQuery.CompassSpanQuery overlaps with another.
 CompassQueryBuilder.CompassQuerySpanOrBuilder spanOr()
          Constructs a span or query builder.
 CompassQuery term(String name, Object value)
          Creates a query where the resource property must have the given value.
 CompassQuery wildcard(String name, String wildcard)
          Creates a query where the resource property values match the given wildcard.
 

Method Detail

convertOnlyWithDotPath

CompassQueryBuilder convertOnlyWithDotPath(boolean convertOnlyWithDotPath)
Should Compass use a converter for value passed even if there is no specific direct dot path notation to it. It will try and derive the best converter to use. Defaults to false.

See Also:
ResourcePropertyLookup.setConvertOnlyWithDotPath(boolean)

addAliasQueryIfNeeded

CompassQueryBuilder addAliasQueryIfNeeded(boolean addAliasQueryIfNeeded)
Should the query builder wrap automatically any query that has dot path notation (such as alias.property) with specific narrowing to match the given alias. Default to true.


bool

CompassQueryBuilder.CompassBooleanQueryBuilder bool()
Constructs a boolean query builder.


bool

CompassQueryBuilder.CompassBooleanQueryBuilder bool(boolean disableCoord)
Constructs a boolean query builder, with coord disabled.


multiPhrase

CompassQueryBuilder.CompassMultiPhraseQueryBuilder multiPhrase(String name)
Constructs a multi phrase query builder for the given resource property / meta-data name.

The name can either be the actual resource property or meta-data value, or the path to the given resource property (alias.rProperty), or the class property (alias.cProperty) or the path to the meta-data (alias.cProperty.metaData)

Parameters:
name - The name of the resource property / meta-data.
Returns:
The multi phrase query builder.

queryString

CompassQueryBuilder.CompassQueryStringBuilder queryString(String queryString)
Constructs a query string query builder.

Parameters:
queryString - The query string (i.e. +jack +london).
Returns:
The query string query builder.

multiPropertyQueryString

CompassQueryBuilder.CompassMultiPropertyQueryStringBuilder multiPropertyQueryString(String queryString)
Constructs a multi property query string builder, allowing to execute query strings against several resource property names.

Parameters:
queryString - The query string (i.e. +jack +london)
Returns:
The multi property string query builder.

alias

CompassQuery alias(String aliasValue)
Returns a query that exactly match the given alias.

Note, this will not narrow down the search to specific sub indxes. In order to do that, please use CompassQuery.setAliases(String[]).

Parameters:
aliasValue - The alias value to match to.
Returns:
The generated query.

polyAlias

CompassQuery polyAlias(String aliasValue)
Returns a query that match the given alias or any extedning aliases.

Note, this will not narrow down the search to specific sub indxes. In order to do that, please use CompassQuery.setAliases(String[]).

Parameters:
aliasValue - The alias value to match to or any extending aliases.
Returns:
The generated query.

term

CompassQuery term(String name,
                  Object value)

Creates a query where the resource property must have the given value. Note, that the value itself will not be analyzed, but the text that was indexed might have been (if indexed). The search is case sensative.

The name can either be the actual resource property or meta-data value, or the path to the given resource property (alias.rProperty), or the class property (alias.cProperty) or the path to the meta-data (alias.cProperty.metaData)

Parameters:
name - The resource property name
value - The value that must match
Returns:
The generated query

matchAll

CompassQuery matchAll()
Creates a query that match all documents.

Returns:
The generated query

between

CompassQuery between(String name,
                     Object low,
                     Object high,
                     boolean inclusive,
                     boolean constantScore)

Creates a query where the resource property is between the given values.

The name can either be the actual resource property or meta-data value, or the path to the given resource property (alias.rProperty), or the class property (alias.cProperty) or the path to the meta-data (alias.cProperty.metaData)

Parameters:
name - The resource property name
low - The low value limit
high - The high value limit
inclusive - If the values are inclusive or exclusive.
constantScore - If the query will affect the score of the results. With all other range queries it will default to true.
Returns:
The generated query

between

CompassQuery between(String name,
                     Object low,
                     Object high,
                     boolean inclusive)

Creates a query where the resource property is between the given values.

The name can either be the actual resource property or meta-data value, or the path to the given resource property (alias.rProperty), or the class property (alias.cProperty) or the path to the meta-data (alias.cProperty.metaData)

Parameters:
name - The resource property name
low - The low value limit
high - The high value limit
inclusive - If the values are inclusive or exclusive.
Returns:
The generated query

lt

CompassQuery lt(String name,
                Object value)

Creates a query where the resource property is less than (<) the given value.

The name can either be the actual resource property or meta-data value, or the path to the given resource property (alias.rProperty), or the class property (alias.cProperty) or the path to the meta-data (alias.cProperty.metaData)

Parameters:
name - The resource property name
value - The high limit value
Returns:
The generated query

le

CompassQuery le(String name,
                Object value)

Creates a query where the resource property is less or equal (<=) to the given value.

The name can either be the actual resource property or meta-data value, or the path to the given resource property (alias.rProperty), or the class property (alias.cProperty) or the path to the meta-data (alias.cProperty.metaData)

Parameters:
name - The resource property name
value - The high limit value
Returns:
The generated query

gt

CompassQuery gt(String name,
                Object value)

Creates a query where the resource property is greater than (>) to the given value.

The name can either be the actual resource property or meta-data value, or the path to the given resource property (alias.rProperty), or the class property (alias.cProperty) or the path to the meta-data (alias.cProperty.metaData)

Parameters:
name - The resource property name
value - The low limit value
Returns:
The generated query

ge

CompassQuery ge(String name,
                Object value)

Creates a query where the resource property is greater or equal (>=) to the given value.

The name can either be the actual resource property or meta-data value, or the path to the given resource property (alias.rProperty), or the class property (alias.cProperty) or the path to the meta-data (alias.cProperty.metaData)

Parameters:
name - The resource property name
value - The low limit value
Returns:
The generated query

prefix

CompassQuery prefix(String name,
                    String prefix)

Creates a query where the resource property values starts with the given prefix.

The name can either be the actual resource property or meta-data value, or the path to the given resource property (alias.rProperty), or the class property (alias.cProperty) or the path to the meta-data (alias.cProperty.metaData)

Parameters:
name - the resource property name
prefix - The prefix value
Returns:
The generated query

wildcard

CompassQuery wildcard(String name,
                      String wildcard)
Creates a query where the resource property values match the given wildcard. Supported wildcards are *, which matches any character sequence (including the empty one), and ?, which matches any single character. Note this query can be slow, as it needs to iterate over many terms. In order to prevent extremely slow WildcardQueries, a Wildcard term should not start with one of the wildcards * or ?.

Parameters:
name - The name
wildcard - The wildcard expression
Returns:
The generated query

fuzzy

CompassQuery fuzzy(String name,
                   String value)

Creates a fuzzy query for the given resource property and the value. The similiarity measurement is based on the Levenshtein (edit distance) algorithm. The minimumSimilarity defaults to 0.5 and prefixLength defaults to 0.

The name can either be the actual resource property or meta-data value, or the path to the given resource property (alias.rProperty), or the class property (alias.cProperty) or the path to the meta-data (alias.cProperty.metaData)

Parameters:
name - The name
value - The value
Returns:
The generated query

fuzzy

CompassQuery fuzzy(String name,
                   String value,
                   float minimumSimilarity)

Creates a fuzzy query for the given resource property and the value. The similiarity measurement is based on the Levenshtein (edit distance) algorithm. The prefixLength defaults to 0.

The name can either be the actual resource property or meta-data value, or the path to the given resource property (alias.rProperty), or the class property (alias.cProperty) or the path to the meta-data (alias.cProperty.metaData)

Parameters:
name - The name
value - The value
minimumSimilarity - The minimum similarity, a value between 0.0 and 1.0
Returns:
The generated query

fuzzy

CompassQuery fuzzy(String name,
                   String value,
                   float minimumSimilarity,
                   int prefixLength)

Creates a fuzzy query for the given resource property and the value. The similiarity measurement is based on the Levenshtein (edit distance) algorithm.

The name can either be the actual resource property or meta-data value, or the path to the given resource property (alias.rProperty), or the class property (alias.cProperty) or the path to the meta-data (alias.cProperty.metaData)

Parameters:
name - The name
value - The value
minimumSimilarity - The minimum similarity, a value between 0.0 and 1.0
prefixLength - The length of common (non-fuzzy) prefix
Returns:
The generated query

spanEq

CompassQuery.CompassSpanQuery spanEq(String name,
                                     Object value)

Creates a span query where the resource property must match the given value.

The name can either be the actual resource property or meta-data value, or the path to the given resource property (alias.rProperty), or the class property (alias.cProperty) or the path to the meta-data (alias.cProperty.metaData)

Parameters:
name - The name
value - The value
Returns:
The span query

spanFirst

CompassQuery.CompassSpanQuery spanFirst(String name,
                                        Object value,
                                        int end)

Creates a span query where the span occur within the first end positions.

The name can either be the actual resource property or meta-data value, or the path to the given resource property (alias.rProperty), or the class property (alias.cProperty) or the path to the meta-data (alias.cProperty.metaData)

Parameters:
name - The name
value - The value
end - The limit on the position from the start.
Returns:
The span query

spanFirst

CompassQuery.CompassSpanQuery spanFirst(CompassQuery.CompassSpanQuery spanQuery,
                                        int end)

Creates a span query.

Parameters:
end - The limit on the position from the start.
Returns:
The span query

spanNear

CompassQueryBuilder.CompassQuerySpanNearBuilder spanNear(String name)

Constructs a span near query builder.

The name can either be the actual resource property or meta-data value, or the path to the given resource property (alias.rProperty), or the class property (alias.cProperty) or the path to the meta-data (alias.cProperty.metaData)

Parameters:
name - The name
Returns:
The span near query builder

spanNot

CompassQuery.CompassSpanQuery spanNot(CompassQuery.CompassSpanQuery include,
                                      CompassQuery.CompassSpanQuery exclude)

Creates a span query that excludes matches where one CompassQuery.CompassSpanQuery overlaps with another.

Construct a span query matching spans from include which have no overlap with spans from exclude.

Parameters:
include - The span query to include.
exclude - The span query to exclude.
Returns:
The span query

spanOr

CompassQueryBuilder.CompassQuerySpanOrBuilder spanOr()
Constructs a span or query builder.

Returns:
The span query builder

moreLikeThis

CompassQueryBuilder.CompassMoreLikeThisQuery moreLikeThis(String alias,
                                                          Serializable id)
Constructs a more like this query. The id can be an object of the class (with the id attributes set), an array of id objects, or the actual id object. Throws an exception if the resource is not found.


moreLikeThis

CompassQueryBuilder.CompassMoreLikeThisQuery moreLikeThis(Reader reader)
Constructs a more like this query to find hits that are similar to the give text represented by the reader.



Copyright (c) 2004-2008 The Compass Project.