Forum: Ruby on Rails Simple Ferret Questions

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
22580f640e491f0920a192610d1df393?d=identicon&s=25 Tom Davies (Guest)
on 2006-01-19 18: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 Doe', both 'John' and 'Doe' will match,
so if someone is named 'Jane Doe' it will match and if someone is
named 'John Smith' 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?

69b2ef4bce76b5b27c94e898976dc6d8?d=identicon&s=25 matthew clark (Guest)
on 2006-01-19 22:05
(Received via mailing list)
I know Lucene better than Ferrett, but I think this should apply.  Two
you can try.

"John Doe"


+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

B5e329ffa0cc78efbfc7ae2d084c149f?d=identicon&s=25 David Balmain (Guest)
on 2006-01-20 01: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.

This topic is locked and can not be replied to.