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? Thanks, Tom
I know Lucene better than Ferrett, but I think this should apply. Two ways you can try. "John Doe" 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 On 1/19/06, Tom Davies <atomgiant@gmail.com> wrote:> > 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? > > Thanks, > Tom > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060119/64ba1657/attachment.html
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 On 1/20/06, Tom Davies <atomgiant@gmail.com> wrote:> 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? > > Thanks, > Tom > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >