Maybe you should index your values differently? Here is what Lucene's 2.9
javadoc says:

To use this, you must first index the numeric values using
NumericField<http://lucene.apache.org/java/2_9_0/api/all/org/apache/lucene/document/NumericField.html>(expert:
NumericTokenStream<http://lucene.apache.org/java/2_9_0/api/all/org/apache/lucene/analysis/NumericTokenStream.html>).
If your terms are instead textual, you should use
TermRangeQuery<http://lucene.apache.org/java/2_9_0/api/all/org/apache/lucene/search/TermRangeQuery.html>.
NumericRangeFilter<http://lucene.apache.org/java/2_9_0/api/all/org/apache/lucene/search/NumericRangeFilter.html>is
the filter equivalent of this query.

Dmitry

On Wed, Dec 14, 2011 at 6:53 PM, Jay Luker <lb...@reallywow.com> wrote:

> I can't get NumericRangeQuery or TermQuery to work on my integer "id"
> field. I feel like I must be missing something obvious.
>
> I have a test index that has only two documents, id:9076628 and
> id:8003001. The id field is defined like so:
>
> <field name="id" type="tint" indexed="true" stored="true" required="true"
> />
>
> A MatchAllDocsQuery will return the 2 documents, but any queries I try
> on the id field return no results. For instance,
>
> public void testIdRange() throws IOException {
>    Query q = NumericRangeQuery.newIntRange("id", 1, 10000000, true, true);
>    System.out.println("query: " + q);
>    assertEquals(2, searcher.search(q, 5).totalHits);
> }
>
> public void testIdSearch() throws IOException {
>    Query q = new TermQuery(new Term("id", "9076628"));
>    System.out.println("query: " + q);
>    assertEquals(1, searcher.search(q, 5).totalHits);
> }
>
> Both tests fail with totalHits being 0. This is using solr/lucene
> trunk, but I tried also with 3.2 and got the same results.
>
> What could I be doing wrong here?
>
> Thanks,
> --jay
>

Reply via email to