Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Lucene +PhraseQuery

 
Vallaru smitha
Ranch Hand
Posts: 87
Firefox Browser Hibernate Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


could any let me know what is wrong with my code as its returning 0 hits if the phrase exits.

thanks in advance
Smitha.>
 
Karthik Shiraly
Bartender
Posts: 1208
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Try this (notice that the search terms are in *lowercase*):


Try this too (notice that search terms are as they are):


The Analyzer you choose is critical - read the javadoc of StandardAnalyzer and you'll find it involves a LowerCaseFilter.
You have to decide for your application whether Managing = managing = MaNaGing.

Approaches:
- Choose an analyzer that doesn't make any modifications you're not expecting, OR
- Based on analyzer javadocs, enforce modifications on your search term (i.e, since you've read StandardAnalyzer javadocs and you know in your mind that it applies a lowercase filter, you do a toLower() on your search terms). This is bad approach because the rules of analyzer are being duplicated in your code.
- Best approach: Apply the same Analyzer that you use to index, on your query too, using the QueryParser class. In future, if you change your indexing Analyzer, the queries will auto conform to its rules.

Use Luke tool to analyze your indices. It tells you the terms stored and a lot more. For debugging ease, it's better to work on a file based index during development till your basic indexing and querying are verified ok.
 
Vallaru smitha
Ranch Hand
Posts: 87
Firefox Browser Hibernate Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Karthik for the reply.

but i got woking it after changing
StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT);

into

StandardAnalyzer analyzer = new StandardAnalyzer();

and that was trial and error as I ran out logic.

Thanks
Smitha
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic