Forum: Ruby on Rails Simple Ferret Questions

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Tom D. (Guest)
on 2006-01-19 19:15
(Received via mailing list)
I am trying to use Ferret for searching for users based on first and
last name.

In my index, I am adding the first_name, last_name, and a full_name
which is basically "#{first_name} #{last_name}".

I am searching the index using something like the following query:

INDEX.search_each(%Q/first_name:#{query}* OR last_name:#{query}* OR
full_name:#{query}*/) do |doc, score|

The problem I am having is when I search the index it is tokenizing my
query so that each word is being evaluated independantly.  For
example, if I search for 'John D.', both 'John' and 'Doe' will match,
so if someone is named 'Jane Doe' it will match and if someone is
named 'John S.' it will match.

Is there a way to not tokenize the query that is passed into the
search_each method?

Also, is there a better way to search for the full name by just using
the first_name and last_name keys rather than creating a separate key
for the full name?

Thanks,
Tom
matthew clark (Guest)
on 2006-01-19 23:05
(Received via mailing list)
I know Lucene better than Ferrett, but I think this should apply.  Two
ways
you can try.

"John D."

or

+John +Doe

I'm not sure the first one will work, but if it does, its the way to go.
The second one will work but it would also match someone named "Doe
John".

matt
David B. (Guest)
on 2006-01-20 02:06
(Received via mailing list)
Hi Tom,

I'm not sure I fully understand your question. PhraseQuery may be what
you want as Matthew has already mentioned. You can also use it to
match first name or last name by using <>. For example;

   ' "#{first_name} <>" '
   ' "<> #{last_name}" '

But for some reason you are using wild card queries with the *. Why is
that? And what exactly is "query"? Does it contain full_name or might
it contain only one name?

Anyway, I hope this has already solved your problem but if not, please
send more info.

Cheers,
Dave
This topic is locked and can not be replied to.