Simple Ferret Questions

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

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

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