org.neo4j.index.lucene
Class QueryContext

java.lang.Object
  extended by org.neo4j.index.lucene.QueryContext

public class QueryContext
extends Object

This class has the extra query configuration to use with Index.query(Object) and Index.query(String, Object). It allows a query to have sorting, default operators, and allows the engine to turn of searching of modifications made inside a transaction, to gain performance.


Constructor Summary
QueryContext(Object queryOrQueryObject)
           
 
Method Summary
 QueryContext defaultOperator(org.apache.lucene.queryParser.QueryParser.Operator defaultOperator)
          Lucenes default operator is OR.
 org.apache.lucene.queryParser.QueryParser.Operator getDefaultOperator()
           
 Object getQueryOrQueryObject()
           
 org.apache.lucene.search.Sort getSorting()
           
 int getTop()
           
 boolean getTradeCorrectnessForSpeed()
           
 QueryContext sort(org.apache.lucene.search.Sort sorting)
          Returns a QueryContext with sorting added to it.
 QueryContext sort(String key, String... additionalKeys)
          Returns a QueryContext with sorting added to it.
 QueryContext sortByScore()
           
 QueryContext top(int numberOfTopHits)
          Makes use of Searcher.search(org.apache.lucene.search.Query, int), alt.
 QueryContext tradeCorrectnessForSpeed()
          Adding to or removing from an index affects results from query methods inside the same transaction, even before those changes are committed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QueryContext

public QueryContext(Object queryOrQueryObject)
Method Detail

getQueryOrQueryObject

public Object getQueryOrQueryObject()
Returns:
the query (or query object) specified in the constructor.

sort

public QueryContext sort(org.apache.lucene.search.Sort sorting)
Returns a QueryContext with sorting added to it.

Parameters:
sorting - The sorting to be used
Returns:
A QueryContext with the sorting applied.

sort

public QueryContext sort(String key,
                         String... additionalKeys)
Returns a QueryContext with sorting added to it.

Parameters:
key - The key to sort on.
additionalKeys - Any additional keys to sort on.
Returns:
A QueryContext with sorting added to it.

sortByScore

public QueryContext sortByScore()
Returns:
a QueryContext with sorting by relevance, i.e. sorted after which score each hit has.

getSorting

public org.apache.lucene.search.Sort getSorting()
Returns:
the sorting set with one of the sort methods, f.ex sort(Sort) or sortByScore()

defaultOperator

public QueryContext defaultOperator(org.apache.lucene.queryParser.QueryParser.Operator defaultOperator)
Lucenes default operator is OR. Using this method, the default operator can be changed for the query.

Parameters:
defaultOperator - The new operator to use.
Returns:
A QueryContext with the new default operator applied.

getDefaultOperator

public org.apache.lucene.queryParser.QueryParser.Operator getDefaultOperator()
Returns:
the default QueryParser.Operator specified with #defaultOperator(Operator) or "OR" if none specified.

tradeCorrectnessForSpeed

public QueryContext tradeCorrectnessForSpeed()
Adding to or removing from an index affects results from query methods inside the same transaction, even before those changes are committed. To let those modifications be visible in query results, some rather heavy operations may have to be done, which can be slow to complete. The default behaviour is that these modifications are visible, but using this method will tell the query to not strive to include the absolutely latest modifications, so that such a performance penalty can be avoided.

Returns:
A QueryContext which doesn't necessarily include the latest transaction modifications in the results, but may perform faster.

getTradeCorrectnessForSpeed

public boolean getTradeCorrectnessForSpeed()
Returns:
whether or not tradeCorrectnessForSpeed() has been called.

top

public QueryContext top(int numberOfTopHits)
Makes use of Searcher.search(org.apache.lucene.search.Query, int), alt. Searcher.search(org.apache.lucene.search.Query, org.apache.lucene.search.Filter, int, Sort) where only the top numberOfTopHits hits are returned. Default behavior is to return all hits, although lazily retrieved from lucene all the way up to the IndexHits iterator.

Parameters:
numberOfTopHits - the maximum number of top hits to return.
Returns:
A QueryContext with the number of top hits set.

getTop

public int getTop()
Returns:
the top hits set with top(int).


Copyright © 2011 The Neo4j Graph Database Project. All Rights Reserved.