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.
D0915fda695c28ef9dac868cd958ad7f?d=identicon&s=25 Harman Sandjaja (hsandjaja)
on 2007-04-06 04: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
B5e329ffa0cc78efbfc7ae2d084c149f?d=identicon&s=25 David Balmain (Guest)
on 2007-04-06 04:58
(Received via mailing list)
On 4/6/07, Harman Sandjaja <hsandjaja@gmail.com> 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.
D0915fda695c28ef9dac868cd958ad7f?d=identicon&s=25 Harman Sandjaja (hsandjaja)
on 2007-04-06 05: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.
B5e329ffa0cc78efbfc7ae2d084c149f?d=identicon&s=25 David Balmain (Guest)
on 2007-04-06 06:59
(Received via mailing list)
On 4/6/07, Harman Sandjaja <hsandjaja@gmail.com> 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.
D0915fda695c28ef9dac868cd958ad7f?d=identicon&s=25 Harman Sandjaja (hsandjaja)
on 2007-04-06 07:19
Hi David!

David Balmain wrote:
> On 4/6/07, Harman Sandjaja <hsandjaja@gmail.com> 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.