Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Lucene +PhraseQuery

 
Ranch Hand
Posts: 87
Hibernate Firefox Browser 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.>
 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • 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
Hibernate Firefox Browser 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 would give a normal human mental abilities to rival mine. To think it is just a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!