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 John john <ze...@yahoo.fr> on 2006/07/28 15:36:19 UTC

Search Numerical Field

Hello, 
 
 I tried to add a field like that
  field = new Field("number", "1", Field.Store.YES,Field.Index.UN_TOKENIZED);
 
 so i should be indexed and to analyzed? my writer is 
 writer = new IndexWriter(INDEX_DIR, new StandardAnalyzer(), true);
 
 but according to the javadoc it should be alright and searching with "number:1" should return resultats? Where i'm wrong?
 
 Thanks
 
 		
---------------------------------
 Découvrez un nouveau moyen de poser toutes vos questions quelque soit le sujet ! Yahoo! Questions/Réponses pour partager vos connaissances, vos opinions et vos expériences. Cliquez ici. 

Re: Search Numerical Field

Posted by Erick Erickson <er...@gmail.com>.
I'd really advise getting a copy of Luke to inspect your index as a first
step. I've been surprised a number of times by what really got in my index.

You might also try using a WhitespaceAnalyzer instead of StandardAnalyzer,
that's the most basic analyzer available. I'm not sure whether individual
numbers are considered stop words by the standard analyzer, yet another
reason to look at your index with Luke.

Hope this helps
Erick

Re: Search Numerical Field

Posted by Doron Cohen <DO...@il.ibm.com>.
John john <ze...@yahoo.fr> wrote on 28/07/2006 06:36:19:

> Hello,
>
>  I tried to add a field like that
>   field = new Field("number", "1",
Field.Store.YES,Field.Index.UN_TOKENIZED);
>
>  so i should be indexed and to analyzed? my writer is
>  writer = new IndexWriter(INDEX_DIR, new StandardAnalyzer(), true);
>
>  but according to the javadoc it should be alright and searching
> with "number:1" should return resultats? Where i'm wrong?

Seems that should be working.

Having "number:1" as query text suggests that QueryParser.parse() was used
to get a query object, i.e. the query text is analyzed - which is
inconsistent with an UN_TOKENIZED field. Consider using TermQuery to avoid
tokenizing the query text:
    Query q = new TermQuery(new Term("number","1"));
However this cannot explain why no results are returned, since the string
"1" would generate the token "1" (well, "number:1") also with analysis.

Perhaps its the common problem of not closing indexWriter after adding the
doc or not re-opening searcher after closing the writer...

- Doron


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