org.neo4j.index.lucene

Class QueryContext

    • 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.
      • sortNumeric

        public QueryContext sortNumeric(String key,
                                        boolean reversed)
        Sort the results of a numeric range query if the query in this context is a NumericRangeQuery, see numericRange(String, Number, Number), Otherwise an IllegalStateException will be thrown.
        Parameters:
        key - the key to sort on.
        reversed - if the sort order should be reversed or not. true for lowest first (ascending), false for highest first (descending)
        Returns:
        a QueryContext with sorting by numeric value.
      • getSorting

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

        public QueryContext defaultOperator(org.apache.lucene.queryparser.classic.QueryParser.Operator defaultOperator)
        Changes the the default operator used between terms in compound queries, default is OR.
        Parameters:
        defaultOperator - The new operator to use.
        Returns:
        A QueryContext with the new default operator applied.
      • getDefaultOperator

        public org.apache.lucene.queryparser.classic.QueryParser.Operator getDefaultOperator()
        Returns the default operator used between terms in compound queries.
        Returns:
        the default QueryParser.Operator specified with defaultOperator 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 behavior 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 true if this context is set to prioritize speed over the inclusion of transactional state in the results.
        Returns:
        whether or not tradeCorrectnessForSpeed() has been called.
      • top

        public QueryContext top(int numberOfTopHits)
        Makes use of IndexSearcher.search(org.apache.lucene.search.Query, int), alternatively IndexSearcher.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()
        Return the max number of results to be returned.
        Returns:
        the top hits set with top(int).
      • numericRange

        public static QueryContext numericRange(String key,
                                                Number from,
                                                Number to)
        Will create a QueryContext with a query for numeric ranges, that is values that have been indexed using ValueContext.indexNumeric(). from (lower) and to (higher) bounds are inclusive. It will match the type of numbers supplied to the type of values that are indexed in the index, f.ex. long, int, float and double. If both from and to is null then it will default to int.
        Parameters:
        key - the property key to query.
        from - the low end of the range (inclusive)
        to - the high end of the range (inclusive)
        Returns:
        a QueryContext to do numeric range queries with.
      • numericRange

        public static QueryContext numericRange(String key,
                                                Number from,
                                                Number to,
                                                boolean includeFrom,
                                                boolean includeTo)
        Will create a QueryContext with a query for numeric ranges, that is values that have been indexed using ValueContext.indexNumeric(). It will match the type of numbers supplied to the type of values that are indexed in the index, f.ex. long, int, float and double. If both from and to is null then it will default to int.
        Parameters:
        key - the property key to query.
        from - the low end of the range (inclusive)
        to - the high end of the range (inclusive)
        includeFrom - whether or not from (the lower bound) is inclusive or not.
        includeTo - whether or not to (the higher bound) is inclusive or not.
        Returns:
        a QueryContext to do numeric range queries with.

Copyright © 2002–2017 The Neo4j Graph Database Project. All rights reserved.