org.compass.core
Interface CompassQuery

All Known Subinterfaces:
CompassQuery.CompassSpanQuery
All Known Implementing Classes:
DefaultCompassQuery, DefaultCompassQuery.DefaultCompassSpanQuey

public interface CompassQuery

An object representing a Compass query. The query is created using the CompassQueryBuilder, and used to get the matching CompassHits.

The query be sorted as well using one of the addSort operations. Note that adding sorting is only applicable for the query that will execute the hits() operation.

Author:
kimchy

Nested Class Summary
static interface CompassQuery.CompassSpanQuery
          An extension to the CompassQuery interface.
static class CompassQuery.SortDirection
          Used to set the sort direction for the query.
static class CompassQuery.SortImplicitType
          Implicit types that the hits can be sorted by.
static class CompassQuery.SortPropertyType
          Used to define the type of the property that will be sorted.
 
Method Summary
 CompassQuery addSort(CompassQuery.SortImplicitType implicitType)
          Adds sorting on implicit types, which are not direct properties values.
 CompassQuery addSort(CompassQuery.SortImplicitType implicitType, CompassQuery.SortDirection direction)
          Adds sorting on implicit types, which are not direct properties values.
 CompassQuery addSort(String propertyName)
          Adds sorting on the given property name.
 CompassQuery addSort(String propertyName, CompassQuery.SortDirection direction)
          Adds sorting on the given property name.
 CompassQuery addSort(String propertyName, CompassQuery.SortPropertyType type)
          Adds sorting on the given property name, and using the given property type.
 CompassQuery addSort(String propertyName, CompassQuery.SortPropertyType type, CompassQuery.SortDirection direction)
          Adds sorting on the given property name, and using the given property type.
 CompassQuery addSort(String propertyName, Locale locale)
          Adds sorting on the given property name, and using the given locale.
 CompassQuery addSort(String propertyName, Locale locale, CompassQuery.SortDirection direction)
          Adds sorting on the given property name, and using the given locale.
 Object clone()
          Clones the given query.
 long count()
          Returns the count of hits that match this query.
 long count(float minimumScore)
          Returns the count of hits that match this query and are higher than the given score.
 CompassQueryFilter getFilter()
          Returns the filter set using setFilter(CompassQueryFilter).
 CompassQuery getSuggestedQuery()
          Returns the suggested query (based on spell check).
 CompassHits hits()
          Performs the search and returns the hits that match the qeury.
 boolean isSuggested()
          Returns true if this is a suggested query.
 CompassQuery rewrite()
          Causes the query to be rewritten before executed to search.
 CompassQuery setAliases(String... aliases)
          Narrows down the query to be executed only against the given aliases.
 CompassQuery setBoost(float boost)
          Sets the boost for this query to boost.
 CompassQuery setFilter(CompassQueryFilter filter)
          Sets a filter to the query.
 CompassQuery setSubIndexes(String... subIndexes)
          Narrows down the query to be executed only against the given sub indexes.
 CompassQuery setTypes(Class... types)
          Narrows down the query to be executed only against the given types.
 

Method Detail

setBoost

CompassQuery setBoost(float boost)
Sets the boost for this query to boost. Hits matching this query will (in addition to the normal weightings) have their score multiplied by boost.


addSort

CompassQuery addSort(String propertyName)
Adds sorting on the given property name. The type of sorting will be identified automatically (though it is preferable to specify it in advance using the addSort(String,SortPropertyType).

Note that the property must be UN_TOKENIZED, and stored.

Note, that the sort option will only work on the outer most query (i.e. the one that the hits is called on).

Parameters:
propertyName - The property name that will be sorted.

addSort

CompassQuery addSort(String propertyName,
                     CompassQuery.SortDirection direction)
Adds sorting on the given property name. The type of sorting will be identified automatically (though it is preferable to specify it in advance using the addSort(String,SortPropertyType).

Note that the property must be UN_TOKENIZED, and stored.

Note, that the sort option will only work on the outer most query (i.e. the one that the hits is called on).

Parameters:
propertyName - The property name that will be sorted.
direction - The direction for the sorting.
Returns:
the query

addSort

CompassQuery addSort(String propertyName,
                     CompassQuery.SortPropertyType type)
Adds sorting on the given property name, and using the given property type. Note that INT has the lowest memorty requirements and STRING the most.

Note that the property must be UN_TOKENIZED, and stored.

Note, that the sort option will only work on the outer most query (i.e. the one that the hits is called on).

Parameters:
propertyName - The property name that will be sorted.
type - The type of the propert.
Returns:
the query

addSort

CompassQuery addSort(String propertyName,
                     CompassQuery.SortPropertyType type,
                     CompassQuery.SortDirection direction)
Adds sorting on the given property name, and using the given property type. Note that INT has the lowest memorty requirements and STRING the most.

Note that the property must be UN_TOKENIZED, and stored.

Note, that the sort option will only work on the outer most query (i.e. the one that the hits is called on).

Parameters:
propertyName - The property name that will be sorted.
type - The type of the propert.
direction - The direction of the sorting.
Returns:
the query

addSort

CompassQuery addSort(CompassQuery.SortImplicitType implicitType)
Adds sorting on implicit types, which are not direct properties values.

Note, that the sort option will only work on the outer most query (i.e. the one that the hits is called on).

Parameters:
implicitType - The implicit type to add sorting on.

addSort

CompassQuery addSort(CompassQuery.SortImplicitType implicitType,
                     CompassQuery.SortDirection direction)
Adds sorting on implicit types, which are not direct properties values.

Note, that the sort option will only work on the outer most query (i.e. the one that the hits is called on).

Parameters:
implicitType - The implicit type to add sorting on.
direction - The direction of the sorting.

addSort

CompassQuery addSort(String propertyName,
                     Locale locale,
                     CompassQuery.SortDirection direction)
Adds sorting on the given property name, and using the given locale. Note, that the sort option will only work on the outer most query (i.e. the one that the hits is called on).

Parameters:
propertyName - The property name that will be sorted.
locale - The locale.
direction - The direction of the sorting.
Returns:
the query

addSort

CompassQuery addSort(String propertyName,
                     Locale locale)
Adds sorting on the given property name, and using the given locale.

Parameters:
propertyName - The property name that will be sorted.
locale - The locale.
Returns:
the query

setSubIndexes

CompassQuery setSubIndexes(String... subIndexes)
Narrows down the query to be executed only against the given sub indexes. If set to null, will use all sub indexes.

Parameters:
subIndexes - sub indexes the query will be executed against
Returns:
The query

setAliases

CompassQuery setAliases(String... aliases)
Narrows down the query to be executed only against the given aliases. If set to null, will use all aliases.

Parameters:
aliases - aliases the query will be executed against
Returns:
th query

setTypes

CompassQuery setTypes(Class... types)
Narrows down the query to be executed only against the given types. Internally will translate the classes to the relevant root aliases and call setAliases(String[]).

Parameters:
types - class types the query will be executed against
Returns:
the query

setFilter

CompassQuery setFilter(CompassQueryFilter filter)
Sets a filter to the query. Please see CompassQueryFilterBuilder.

Parameters:
filter - The filter for the query
Returns:
the query

getFilter

CompassQueryFilter getFilter()
Returns the filter set using setFilter(CompassQueryFilter). null if none is set.

Returns:
The filter set using setFilter(CompassQueryFilter)

rewrite

CompassQuery rewrite()
Causes the query to be rewritten before executed to search.


getSuggestedQuery

CompassQuery getSuggestedQuery()
Returns the suggested query (based on spell check). If spell check is disabled the same query is returned.

In order to know if the query was actually replaced with a suggested one, call isSuggested().


isSuggested

boolean isSuggested()
Returns true if this is a suggested query. For example, when performing a search query with spell check enabled, then it will return true if the query was modified to correct some spelling mistakes.


hits

CompassHits hits()
                 throws CompassException
Performs the search and returns the hits that match the qeury.

Throws:
CompassException

count

long count()
Returns the count of hits that match this query. Note, this will be faster than CompassHitsOperations.length().

Same as calling count(0.0f).


count

long count(float minimumScore)
Returns the count of hits that match this query and are higher than the given score. Note, this will be faster than CompassHitsOperations.length().


clone

Object clone()
             throws CloneNotSupportedException
Clones the given query.

Throws:
CloneNotSupportedException


Copyright (c) 2004-2008 The Compass Project.