Forum: Ferret Newbie having full text search problem with acts_as_ferret

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.
Harman S. (Guest)
on 2007-04-06 06:27
Hi guys,

I am using acts_as_ferret to do full text search on my models and I am
having problem on three-letter word searches.

I am going to use an example to explain my problem. Here it is:

There is a table called users and it has login, first_name, last_name
columns. There are three rows inside it.

login        first_name     last_name
bob          bob            henry
longbob      nil            nil
existingbob  nil            nil

Now I am expecting to get all three rows as the search result and my
search query is: "bob OR *bob* OR bob* OR *bob"
However, I am only getting longbob and existingbob rows, not the user
bob.

I have tried many other queries and still no luck. At first I thought
that some columns might not be indexed properly but doing login:bob
returns me with the user bob, so I don't think that it's indexing
problem anymore.

Any idea?

Thank you in advance for the help.

Regards,
Harman
David B. (Guest)
on 2007-04-06 06:58
(Received via mailing list)
On 4/6/07, Harman S. <removed_email_address@domain.invalid> wrote:
> login        first_name     last_name
> that some columns might not be indexed properly but doing login:bob
> returns me with the user bob, so I don't think that it's indexing
> problem anymore.
>
> Any idea?

Sorry, I can't seem to replicate this problem;

  require 'ferret'
  i = Ferret::Index::Index.new()
  i << {:login => "bob",         :first_name => "bob", :last_name =>
"henry"}
  i << {:login => "longbob",     :first_name => nil, :last_name => nil}
  i << {:login => "existingbob", :first_name => nil, :last_name => nil}
  puts i.search("bob OR *bob* OR bob* OR *bob").to_s(:login)

Gives me the correct output;

  TopDocs: total_hits = 3, max_score = 2.091924 [
          0 "bob": 2.091924
          1 "longbob": 0.045950
          2 "existingbob": 0.045950
  ]

Perhaps you are using an earlier version of Ferret. Otherwise I'm not
sure what the problem might me.
Harman S. (Guest)
on 2007-04-06 07:59
> Perhaps you are using an earlier version of Ferret. Otherwise I'm not
> sure what the problem might me.

Thanks a lot for the reply David! I believe I'm using the latest Ferret
though.

At least now I know that the query I'm using is correct so nothing wrong
with that.

Also I am not too sure about it but this can be changed:
"bob OR *bob* OR bob* OR *bob" to "bob OR *bob*"
Am I right?

As I mentioned before I'm using acts_as_ferret to implement my full text
search. Here is a piece of the code:
  def self.quick_search(search_text)
    return [] if search_text.blank?
    q = "#{search_text} OR *#{search_text}*"
    multi_search_result = []
    for m in AVAILABLE_MODELS_FOR_SEARCH
      size, result = m.constantize.find_id_by_contents(q)
      multi_search_result += result
    end
  ...
  end

Any other insight, guys?

I must did something wrong but still no luck in finding it until now.
David B. (Guest)
on 2007-04-06 08:59
(Received via mailing list)
On 4/6/07, Harman S. <removed_email_address@domain.invalid> wrote:
> Also I am not too sure about it but this can be changed:
> "bob OR *bob* OR bob* OR *bob" to "bob OR *bob*"
> Am I right?

Actually "*bob*" will probably do what you want, but "bob OR *bob*"
will make sure that "bob" scores much higher than "longbob".

> Any other insight, guys?

Sorry, no other idea what the problem might be.
Harman S. (Guest)
on 2007-04-06 09:19
Hi David!

David B. wrote:
> On 4/6/07, Harman S. <removed_email_address@domain.invalid> wrote:
>> Also I am not too sure about it but this can be changed:
>> "bob OR *bob* OR bob* OR *bob" to "bob OR *bob*"
>> Am I right?
>
> Actually "*bob*" will probably do what you want, but "bob OR *bob*"
> will make sure that "bob" scores much higher than "longbob".
>

Ahhhh I see....

>> Any other insight, guys?
>
> Sorry, no other idea what the problem might be.

Not a problem, thank you for your help again.

I finally found out what the problem is. It turns out to be completely
unrelated to Ferret and my implementation of the search. The problem is
that the search result I'm expecting is located on the second page of my
paginator object and I did not pass the correct page =.=" It's hard to
see because it's part of my integration test.

My stupid brain is playing trick on me!!! >.<
I can't believe I spent about 6+ hours on this error...

Thanks again!
Harman
This topic is locked and can not be replied to.