Query Objects vs. Query Strings

Hi …

I tried to build some query objects to get some documents from my
index… without success… Is something wrong here?

q = Ferret::Search::BooleanQuery.new
q1 = Ferret::Search::TermQuery.new(:type, “movie”)
q2 = Ferret::Search::TermQuery.new(:name, “Indiana”)
q.add_query(q1, :should)
q.add_query(q2, :should)

Indexer.index.search_each(q) do |doc, score| puts doc end
0
Indexer.index.search_each(q.to_s) do |doc, score| puts doc end
70
65
68
5368
197
=> 5

Ben

You need to downcase Indiana. The QueryParser does it for you but when
you build the Query object yourself you need to make sure the terms
are downcase as if they had already been through the Analyzer.
Similarly, if you use a StopFilter then you shouldn’t add “the” (or
“das” or whatever is a stop-word in the language you are working with)
terms to your queries. That’s why the QueryParser is so useful. It
handles all of this for you. :slight_smile: