// Path: src/main/java/org/neo4j/index/impl/lucene/LuceneUtil.java
// public abstract class LuceneUtil
// {
//     static void close( IndexWriter writer )
//     {
//         close( (Object) writer );
//     }
//     
//     static void close( IndexSearcher searcher )
//     {
//         close( (Object) searcher );
//     }
//     
//     private static void close( Object object )
//     {
//         if ( object == null )
//         {
//             return;
//         }
//         
//         try
//         {
//             if ( object instanceof IndexWriter )
//             {
//                 ((IndexWriter) object).close();
//             }
//             else if ( object instanceof IndexSearcher )
//             {
//                 // nothing to close since lucene 4.0.0
//             }
//         }
//         catch ( IOException e )
//         {
//             throw new RuntimeException( e );
//         }
//     }
// 
//     static void strictAddDocument( IndexWriter writer, Document document )
//     {
//         try
//         {
//             writer.addDocument( document );
//         }
//         catch ( IOException e )
//         {
//             throw new RuntimeException( e );
//         }
//     }
// 
//     static void strictRemoveDocument( IndexWriter writer, Query query )
//     {
//         try
//         {
//             writer.deleteDocuments( query );
//         }
//         catch ( IOException e )
//         {
//             throw new RuntimeException( e );
//         }
//     }
//     
//     /**
//      * Will create a {@link Query} with a query for numeric ranges, that is
//      * values that have been indexed using {@link 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 {@code from} and {@code to} is {@code null} then it will default
//      * to int.
//      * 
//      * @param key the property key to query.
//      * @param from the low end of the range (inclusive)
//      * @param to the high end of the range (inclusive)
//      * @param includeFrom whether or not {@code from} (the lower bound) is inclusive
//      * or not.
//      * @param includeTo whether or not {@code to} (the higher bound) is inclusive
//      * or not.
//      * @return a {@link Query} to do numeric range queries with.
//      */
//     public static Query rangeQuery( String key, Number from, Number to,
//             boolean includeFrom, boolean includeTo )
//     {
//         if ( from instanceof Long || to instanceof Long )
//         {
//             return NumericRangeQuery.newLongRange( key, from != null ? from.longValue() : 0,
//                     to != null ? to.longValue() : Long.MAX_VALUE, includeFrom, includeTo );
//         }
//         else if ( from instanceof Double || to instanceof Double )
//         {
//             return NumericRangeQuery.newDoubleRange( key, from != null ? from.doubleValue() : 0,
//                     to != null ? to.doubleValue() : Double.MAX_VALUE, includeFrom, includeTo );
//         }
//         else if ( from instanceof Float || to instanceof Float )
//         {
//             return NumericRangeQuery.newFloatRange( key, from != null ? from.floatValue() : 0,
//                     to != null ? to.floatValue() : Float.MAX_VALUE, includeFrom, includeTo );
//         }
//         else
//         {
//             return NumericRangeQuery.newIntRange( key, from != null ? from.intValue() : 0,
//                     to != null ? to.intValue() : Integer.MAX_VALUE, includeFrom, includeTo );
//         }
//     }
// }


import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.NumericRangeQuery;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
import org.neo4j.graphdb.index.Index;
import org.neo4j.graphdb.index.IndexHits;
import org.neo4j.index.impl.lucene.LuceneUtil;
     * @param key the property key to query.
     * @param from the low end of the range (inclusive)
     * @param to the high end of the range (inclusive)
     * @return a {@link QueryContext} to do numeric range queries with.
     */
    public static QueryContext numericRange( String key, Number from, Number to )
    {
        return numericRange( key, from, to, true, true );
    }
    
    /**
     * Will create a {@link QueryContext} with a query for numeric ranges, that is
     * values that have been indexed using {@link 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 {@code from} and {@code to} is {@code null} then it will default
     * to int.
     * 
     * @param key the property key to query.
     * @param from the low end of the range (inclusive)
     * @param to the high end of the range (inclusive)
     * @param includeFrom whether or not {@code from} (the lower bound) is inclusive
     * or not.
     * @param includeTo whether or not {@code to} (the higher bound) is inclusive
     * or not.
     * @return a {@link QueryContext} to do numeric range queries with.
     */
    public static QueryContext numericRange( String key, Number from, Number to,
            boolean includeFrom, boolean includeTo )
    {
// Path: src/main/java/org/neo4j/index/impl/lucene/LuceneUtil.java
// public abstract class LuceneUtil
// {
//     static void close( IndexWriter writer )
//     {
//         close( (Object) writer );
//     }
//     
//     static void close( IndexSearcher searcher )
//     {
//         close( (Object) searcher );
//     }
//     
//     private static void close( Object object )
//     {
//         if ( object == null )
//         {
//             return;
//         }
//         
//         try
//         {
//             if ( object instanceof IndexWriter )
//             {
//                 ((IndexWriter) object).close();
//             }
//             else if ( object instanceof IndexSearcher )
//             {
//                 // nothing to close since lucene 4.0.0
//             }
//         }
//         catch ( IOException e )
//         {
//             throw new RuntimeException( e );
//         }
//     }
// 
//     static void strictAddDocument( IndexWriter writer, Document document )
//     {
//         try
//         {
//             writer.addDocument( document );
//         }
//         catch ( IOException e )
//         {
//             throw new RuntimeException( e );
//         }
//     }
// 
//     static void strictRemoveDocument( IndexWriter writer, Query query )
//     {
//         try
//         {
//             writer.deleteDocuments( query );
//         }
//         catch ( IOException e )
//         {
//             throw new RuntimeException( e );
//         }
//     }
//     
//     /**
//      * Will create a {@link Query} with a query for numeric ranges, that is
//      * values that have been indexed using {@link 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 {@code from} and {@code to} is {@code null} then it will default
//      * to int.
//      * 
//      * @param key the property key to query.
//      * @param from the low end of the range (inclusive)
//      * @param to the high end of the range (inclusive)
//      * @param includeFrom whether or not {@code from} (the lower bound) is inclusive
//      * or not.
//      * @param includeTo whether or not {@code to} (the higher bound) is inclusive
//      * or not.
//      * @return a {@link Query} to do numeric range queries with.
//      */
//     public static Query rangeQuery( String key, Number from, Number to,
//             boolean includeFrom, boolean includeTo )
//     {
//         if ( from instanceof Long || to instanceof Long )
//         {
//             return NumericRangeQuery.newLongRange( key, from != null ? from.longValue() : 0,
//                     to != null ? to.longValue() : Long.MAX_VALUE, includeFrom, includeTo );
//         }
//         else if ( from instanceof Double || to instanceof Double )
//         {
//             return NumericRangeQuery.newDoubleRange( key, from != null ? from.doubleValue() : 0,
//                     to != null ? to.doubleValue() : Double.MAX_VALUE, includeFrom, includeTo );
//         }
//         else if ( from instanceof Float || to instanceof Float )
//         {
//             return NumericRangeQuery.newFloatRange( key, from != null ? from.floatValue() : 0,
//                     to != null ? to.floatValue() : Float.MAX_VALUE, includeFrom, includeTo );
//         }
//         else
//         {
//             return NumericRangeQuery.newIntRange( key, from != null ? from.intValue() : 0,
//                     to != null ? to.intValue() : Integer.MAX_VALUE, includeFrom, includeTo );
//         }
//     }
// }


// Path: src/main/java/org/neo4j/index/lucene/QueryContext.java
import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.NumericRangeQuery;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
import org.neo4j.graphdb.index.Index;
import org.neo4j.graphdb.index.IndexHits;
import org.neo4j.index.impl.lucene.LuceneUtil;

     * @param key the property key to query.
     * @param from the low end of the range (inclusive)
     * @param to the high end of the range (inclusive)
     * @return a {@link QueryContext} to do numeric range queries with.
     */
    public static QueryContext numericRange( String key, Number from, Number to )
    {
        return numericRange( key, from, to, true, true );
    }
    
    /**
     * Will create a {@link QueryContext} with a query for numeric ranges, that is
     * values that have been indexed using {@link 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 {@code from} and {@code to} is {@code null} then it will default
     * to int.
     * 
     * @param key the property key to query.
     * @param from the low end of the range (inclusive)
     * @param to the high end of the range (inclusive)
     * @param includeFrom whether or not {@code from} (the lower bound) is inclusive
     * or not.
     * @param includeTo whether or not {@code to} (the higher bound) is inclusive
     * or not.
     * @return a {@link QueryContext} to do numeric range queries with.
     */
    public static QueryContext numericRange( String key, Number from, Number to,
            boolean includeFrom, boolean includeTo )
    {
        return new QueryContext( LuceneUtil.rangeQuery( key, from, to, includeFrom, includeTo ) );