org.compass.core.impl
Class DefaultCompassQueryBuilder

java.lang.Object
  extended by org.compass.core.impl.DefaultCompassQueryBuilder
All Implemented Interfaces:
CompassQueryBuilder

public class DefaultCompassQueryBuilder
extends Object
implements CompassQueryBuilder

Author:
kimchy

Nested Class Summary
 class DefaultCompassQueryBuilder.DefaultCompassBooleanQueryBuilder
           
 class DefaultCompassQueryBuilder.DefaultCompassMoreLikeThisQuery
           
 class DefaultCompassQueryBuilder.DefaultCompassMultiPhraseQueryBuilder
           
 class DefaultCompassQueryBuilder.DefaultCompassMultiPropertyQueryStringBuilder
           
 class DefaultCompassQueryBuilder.DefaultCompassQuerySpanNearBuilder
           
 class DefaultCompassQueryBuilder.DefaultCompassQuerySpanOrBuilder
           
 class DefaultCompassQueryBuilder.DefaultCompassQueryStringBuilder
           
 
Nested classes/interfaces inherited from interface org.compass.core.CompassQueryBuilder
CompassQueryBuilder.CompassBooleanQueryBuilder, CompassQueryBuilder.CompassMoreLikeThisQuery, CompassQueryBuilder.CompassMultiPhraseQueryBuilder, CompassQueryBuilder.CompassMultiPropertyQueryStringBuilder, CompassQueryBuilder.CompassQuerySpanNearBuilder, CompassQueryBuilder.CompassQuerySpanOrBuilder, CompassQueryBuilder.CompassQueryStringBuilder, CompassQueryBuilder.ToCompassQuery
 
Constructor Summary
DefaultCompassQueryBuilder(SearchEngineQueryBuilder queryBuilder, InternalCompassSession session)
           
 
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultCompassQueryBuilder

public DefaultCompassQueryBuilder(SearchEngineQueryBuilder queryBuilder,
                                  InternalCompassSession session)
Method Detail

convertOnlyWithDotPath

public CompassQueryBuilder convertOnlyWithDotPath(boolean convertOnlyWithDotPath)
Description copied from interface: CompassQueryBuilder
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.

Specified by:
convertOnlyWithDotPath in interface CompassQueryBuilder
See Also:
ResourcePropertyLookup.setConvertOnlyWithDotPath(boolean)

addAliasQueryIfNeeded

public CompassQueryBuilder addAliasQueryIfNeeded(boolean addAliasQueryIfNeeded)
Description copied from interface: CompassQueryBuilder
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.

Specified by:
addAliasQueryIfNeeded in interface CompassQueryBuilder

bool

public CompassQueryBuilder.CompassBooleanQueryBuilder bool()
Description copied from interface: CompassQueryBuilder
Constructs a boolean query builder.

Specified by:
bool in interface CompassQueryBuilder

bool

public CompassQueryBuilder.CompassBooleanQueryBuilder bool(boolean disableCoord)
Description copied from interface: CompassQueryBuilder
Constructs a boolean query builder, with coord disabled.

Specified by:
bool in interface CompassQueryBuilder

multiPhrase

public CompassQueryBuilder.CompassMultiPhraseQueryBuilder multiPhrase(String name)
Description copied from interface: CompassQueryBuilder
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)

Specified by:
multiPhrase in interface CompassQueryBuilder
Parameters:
name - The name of the resource property / meta-data.
Returns:
The multi phrase query builder.

queryString

public CompassQueryBuilder.CompassQueryStringBuilder queryString(String queryString)
Description copied from interface: CompassQueryBuilder
Constructs a query string query builder.

Specified by:
queryString in interface CompassQueryBuilder
Parameters:
queryString - The query string (i.e. +jack +london).
Returns:
The query string query builder.

multiPropertyQueryString

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

Specified by:
multiPropertyQueryString in interface CompassQueryBuilder
Parameters:
queryString - The query string (i.e. +jack +london)
Returns:
The multi property string query builder.

alias

public CompassQuery alias(String aliasValue)
Description copied from interface: CompassQueryBuilder
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[]).

Specified by:
alias in interface CompassQueryBuilder
Parameters:
aliasValue - The alias value to match to.
Returns:
The generated query.

polyAlias

public CompassQuery polyAlias(String aliasValue)
Description copied from interface: CompassQueryBuilder
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[]).

Specified by:
polyAlias in interface CompassQueryBuilder
Parameters:
aliasValue - The alias value to match to or any extending aliases.
Returns:
The generated query.

term

public CompassQuery term(String name,
                         Object value)
Description copied from interface: CompassQueryBuilder

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)

Specified by:
term in interface CompassQueryBuilder
Parameters:
name - The resource property name
value - The value that must match
Returns:
The generated query

matchAll

public CompassQuery matchAll()
Description copied from interface: CompassQueryBuilder
Creates a query that match all documents.

Specified by:
matchAll in interface CompassQueryBuilder
Returns:
The generated query

between

public CompassQuery between(String name,
                            Object low,
                            Object high,
                            boolean inclusive,
                            boolean constantScore)
Description copied from interface: CompassQueryBuilder

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)

Specified by:
between in interface CompassQueryBuilder
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

public CompassQuery between(String name,
                            Object low,
                            Object high,
                            boolean inclusive)
Description copied from interface: CompassQueryBuilder

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)

Specified by:
between in interface CompassQueryBuilder
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

public CompassQuery lt(String name,
                       Object value)
Description copied from interface: CompassQueryBuilder

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)

Specified by:
lt in interface CompassQueryBuilder
Parameters:
name - The resource property name
value - The high limit value
Returns:
The generated query

le

public CompassQuery le(String name,
                       Object value)
Description copied from interface: CompassQueryBuilder

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)

Specified by:
le in interface CompassQueryBuilder
Parameters:
name - The resource property name
value - The high limit value
Returns:
The generated query

gt

public CompassQuery gt(String name,
                       Object value)
Description copied from interface: CompassQueryBuilder

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)

Specified by:
gt in interface CompassQueryBuilder
Parameters:
name - The resource property name
value - The low limit value
Returns:
The generated query

ge

public CompassQuery ge(String name,
                       Object value)
Description copied from interface: CompassQueryBuilder

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)

Specified by:
ge in interface CompassQueryBuilder
Parameters:
name - The resource property name
value - The low limit value
Returns:
The generated query

prefix

public CompassQuery prefix(String name,
                           String prefix)
Description copied from interface: CompassQueryBuilder

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)

Specified by:
prefix in interface CompassQueryBuilder
Parameters:
name - the resource property name
prefix - The prefix value
Returns:
The generated query

wildcard

public CompassQuery wildcard(String name,
                             String wildcard)
Description copied from interface: CompassQueryBuilder
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 ?.

Specified by:
wildcard in interface CompassQueryBuilder
Parameters:
name - The name
wildcard - The wildcard expression
Returns:
The generated query

fuzzy

public CompassQuery fuzzy(String name,
                          String value,
                          float minimumSimilarity)
Description copied from interface: CompassQueryBuilder

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)

Specified by:
fuzzy in interface CompassQueryBuilder
Parameters:
name - The name
value - The value
minimumSimilarity - The minimum similarity, a value between 0.0 and 1.0
Returns:
The generated query

fuzzy

public CompassQuery fuzzy(String name,
                          String value,
                          float minimumSimilarity,
                          int prefixLength)
Description copied from interface: CompassQueryBuilder

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)

Specified by:
fuzzy in interface CompassQueryBuilder
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

fuzzy

public CompassQuery fuzzy(String name,
                          String value)
Description copied from interface: CompassQueryBuilder

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)

Specified by:
fuzzy in interface CompassQueryBuilder
Parameters:
name - The name
value - The value
Returns:
The generated query

spanEq

public CompassQuery.CompassSpanQuery spanEq(String name,
                                            Object value)
Description copied from interface: CompassQueryBuilder

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)

Specified by:
spanEq in interface CompassQueryBuilder
Parameters:
name - The name
value - The value
Returns:
The span query

spanFirst

public CompassQuery.CompassSpanQuery spanFirst(String name,
                                               Object value,
                                               int end)
Description copied from interface: CompassQueryBuilder

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)

Specified by:
spanFirst in interface CompassQueryBuilder
Parameters:
name - The name
value - The value
end - The limit on the position from the start.
Returns:
The span query

spanFirst

public CompassQuery.CompassSpanQuery spanFirst(CompassQuery.CompassSpanQuery spanQuery,
                                               int end)
Description copied from interface: CompassQueryBuilder

Creates a span query.

Specified by:
spanFirst in interface CompassQueryBuilder
end - The limit on the position from the start.
Returns:
The span query

spanNear

public CompassQueryBuilder.CompassQuerySpanNearBuilder spanNear(String name)
Description copied from interface: CompassQueryBuilder

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)

Specified by:
spanNear in interface CompassQueryBuilder
Parameters:
name - The name
Returns:
The span near query builder

spanNot

public CompassQuery.CompassSpanQuery spanNot(CompassQuery.CompassSpanQuery include,
                                             CompassQuery.CompassSpanQuery exclude)
Description copied from interface: CompassQueryBuilder

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.

Specified by:
spanNot in interface CompassQueryBuilder
Parameters:
include - The span query to include.
exclude - The span query to exclude.
Returns:
The span query

spanOr

public CompassQueryBuilder.CompassQuerySpanOrBuilder spanOr()
Description copied from interface: CompassQueryBuilder
Constructs a span or query builder.

Specified by:
spanOr in interface CompassQueryBuilder
Returns:
The span query builder

moreLikeThis

public CompassQueryBuilder.CompassMoreLikeThisQuery moreLikeThis(String alias,
                                                                 Serializable id)
Description copied from interface: CompassQueryBuilder
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.

Specified by:
moreLikeThis in interface CompassQueryBuilder

moreLikeThis

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

Specified by:
moreLikeThis in interface CompassQueryBuilder


Copyright (c) 2004-2008 The Compass Project.