lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matthew Petersen <>
Subject Problem with numeric range query syntax in lucene 4.4.0
Date Thu, 20 Mar 2014 20:43:38 GMT

I'm trying to submit a lucene query string to my index to return a data
based on a numeric range.  I'm using the syntax provided in the Query
Parser Syntax document but the results I get indicate that the query is not
working correctly.  Below is a unit test that proves that the range query
does not work, at least in this configuration.

    public void test_lucene_numeric_range_query() throws IOException,
ParseException {
        Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_44);
        IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_44,
        Directory directory = new RAMDirectory();
        IndexWriter writer = new IndexWriter(directory, config);

        Field longField1 = new LongField("longField1", 0L, Field.Store.YES);
        Field longField2 = new LongField("longField2", 0L, Field.Store.YES);

        for (long i = 1; i < 101; i++)
            Document doc = new Document();



        IndexReader reader =, false);
        IndexSearcher searcher = new IndexSearcher(reader);

        Query query = new QueryParser(Version.LUCENE_44, "",
analyzer).parse("longField1:[51 TO 75]");

        TopDocs docs =, 100);

        Assert.assertEquals(docs.totalHits, 25);


Is there something wrong with the query I'm submitting, or the way I'm
setting up the searcher, or something else?  Or does submitting a query in
this way for a numeric field not work?

Thanks in advance,

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message