Hello all
I finally caved in and decided I should build my own query instead of
relying on QueryParser to do the job for me, but I've hit a strange
problem..
Here's how I build my query:
#Main query
query = Ferret::Search::BooleanQuery.new
#Build query to match types
typesquery = Ferret::Search::BooleanQuery.new
@selected_types.each{|type|
typesquery.add_query(
Ferret::Search::TermQuery.new(Ferret::Index::Term.new('type',
type)),
Ferret::Search::BooleanClause::Occur::SHOULD
)
}
#Add types query to main query
query.add_query(typesquery, Ferret::Search::BooleanClause::Occur::MUST)
#Build query to match content and title
contenttitlequery = Ferret::Search::BooleanQuery.new
contenttitlequery.add_query(
Ferret::Search::TermQuery.new(Ferret::Index::Term.new('content',
params[:query])),
Ferret::Search::BooleanClause::Occur::SHOULD
)
contenttitlequery.add_query(
Ferret::Search::TermQuery.new(Ferret::Index::Term.new('title',
params[:query])),
Ferret::Search::BooleanClause::Occur::SHOULD
)
#Add content+title query to main query
query.add_query(contenttitlequery,
Ferret::Search::BooleanClause::Occur::MUST)
The problem is that index.search(query) always gives me 0 results.
However, if I do index.search(query.to_s) it returns the results I
expect..
Here's an example output of query.to_s:
+(type:Foo type:Bar) +(content:baz title:baz)
What I'm trying to do is search for items that is of type Foo or Bar and
has "baz" in either the content or the title.
Does anyone have an idea of what's going on here?
Thanks,
Tore
Using QueryParser vs building my own query
on 27.06.2006 11:51
Re: Using QueryParser vs building my own query
on 28.06.2006 16:53
On 6/27/06, Tore Darell <toredarell@gmail.com> wrote: > > #Add types query to main query > Ferret::Search::TermQuery.new(Ferret::Index::Term.new('title', > The problem is that index.search(query) always gives me 0 results. > Does anyone have an idea of what's going on here? You must have used a lowercasing analyzer. You'll need to lowercase the "Foo" and "Bar". QueryParser will do that for you. An easy fix. Cheers, Dave
Re: Using QueryParser vs building my own query
on 29.06.2006 15:23
David Balmain wrote: > On 6/27/06, Tore Darell <toredarell@gmail.com> wrote: >> >> #Add types query to main query >> Ferret::Search::TermQuery.new(Ferret::Index::Term.new('title', >> The problem is that index.search(query) always gives me 0 results. >> Does anyone have an idea of what's going on here? > You must have used a lowercasing analyzer. You'll need to lowercase > the "Foo" and "Bar". QueryParser will do that for you. An easy fix. > > Cheers, > Dave You're right, thanks. For some reason I had set the type field to be tokenised.. Tore
