You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by "m.harig" <m....@gmail.com> on 2008/08/13 11:55:48 UTC

Number range search

hi all.

  am indexing a price field by 

doc.add(new Field("price", "1450", Field.Store.YES,
					Field.Index.TOKENIZED));
doc.add(new Field("price", "3800", Field.Store.YES,
					Field.Index.TOKENIZED));
doc.add(new Field("price", "2500", Field.Store.YES,
					Field.Index.TOKENIZED));
doc.add(new Field("price", "7020", Field.Store.YES,
					Field.Index.TOKENIZED));
doc.add(new Field("price", "3500", Field.Store.YES,
					Field.Index.TOKENIZED));


its done properly. 

when i go for search am using 

                IndexSearcher searcher = new IndexSearcher(indexDir);

		Analyzer analyzer = new StandardAnalyzer();

		QueryParser parser = new QueryParser("contents", analyzer);
		Query query = parser.parse(qryStr);

		Hits hits = searcher.search(query);

and my query is to search is price:[1000 TO 4000]. when i search this, it
returns nothing or when i change the query to price:[2000 TO 4000] it return
all hits. where am wrong.. am not getting any correct output. could any1
help me out of this. please....
-- 
View this message in context: http://www.nabble.com/Number-range-search-tp18960121p18960121.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Number range search

Posted by Doron Cohen <cd...@gmail.com>.
The code seems correct (although it doesn't show
which analyzer was used at indexing).

Note that when adding numbers like this there's no real point in analyzing
them,
so I would add that field as UN_TOKENIZED. This would be more efficient,
and would also comply with the query parser who does not apply
the analyzer on range query terms. Anyhow this does not explain the problem
you see, because standard analyzer would not modify the numbers anyhow.

Which Lucene version version you are using?

Can you provide a small self-containing program demonstrating the unexpected
behavior?

(often just writing this small program shows leads to solve a problem like
this).

Doron

On Wed, Aug 13, 2008 at 12:55 PM, m.harig <m....@gmail.com> wrote:

>
> hi all.
>
>  am indexing a price field by
>
> doc.add(new Field("price", "1450", Field.Store.YES,
>                                        Field.Index.TOKENIZED));
> doc.add(new Field("price", "3800", Field.Store.YES,
>                                        Field.Index.TOKENIZED));
> doc.add(new Field("price", "2500", Field.Store.YES,
>                                        Field.Index.TOKENIZED));
> doc.add(new Field("price", "7020", Field.Store.YES,
>                                        Field.Index.TOKENIZED));
> doc.add(new Field("price", "3500", Field.Store.YES,
>                                        Field.Index.TOKENIZED));
>
>
> its done properly.
>
> when i go for search am using
>
>                IndexSearcher searcher = new IndexSearcher(indexDir);
>
>                Analyzer analyzer = new StandardAnalyzer();
>
>                QueryParser parser = new QueryParser("contents", analyzer);
>                Query query = parser.parse(qryStr);
>
>                Hits hits = searcher.search(query);
>
> and my query is to search is price:[1000 TO 4000]. when i search this, it
> returns nothing or when i change the query to price:[2000 TO 4000] it
> return
> all hits. where am wrong.. am not getting any correct output. could any1
> help me out of this. please....
>