Forum: Ferret Using the wildcard plus partial searched

67b20ecd191f6041e821a6f3c1abf523?d=identicon&s=25 Richard (Guest)
on 2006-09-18 18:06
I've seen no definitive answer to this question.

I've noticed that typing "t" in the search box will return no results
however if I type "t*" it brings up all results beginning with t.

I would like this behaviour on by default without having to type the
wildcard. Is there a way to do this?
C9dd93aa135988cabf9183d3210665ca?d=identicon&s=25 Jens Kraemer (Guest)
on 2006-09-18 19:58
(Received via mailing list)
On Mon, Sep 18, 2006 at 06:06:00PM +0200, Richard wrote:
> I've seen no definitive answer to this question.
>
> I've noticed that typing "t" in the search box will return no results
> however if I type "t*" it brings up all results beginning with t.
>
> I would like this behaviour on by default without having to type the
> wildcard. Is there a way to do this?

Manually append a wild card to the query terms before giving it to the
parser. I once did something like this for a customer. The problem is
that this can get complex with more complex queries, i.e. you won't want
to append a '*' to the word AND, since that's part of the query
language.

Would be better to have a special query parser for this, or even an
option in the stock QueryParser to force it to use wild card queries all
the time.


Jens



--
webit! Gesellschaft für neue Medien mbH          www.webit.de
Dipl.-Wirtschaftsingenieur Jens Krämer       kraemer@webit.de
Schnorrstraße 76                         Tel +49 351 46766  0
D-01069 Dresden                          Fax +49 351 46766 66
D03961539afa06b1f08c70aa6bf7718e?d=identicon&s=25 Brian Keats (bfkeats)
on 2006-10-14 18:49
> I've noticed that typing "t" in the search box will return no results
> however if I type "t*" it brings up all results beginning with t.
>
> I would like this behaviour on by default without having to type the
> wildcard. Is there a way to do this?

Add the following search method to your model

  def self.search(query)
    criteria = query.split
    wild_criteria = []
    criteria.each do |criterion|
      if criterion == "AND" || criterion == "OR"
        wild_criteria.push(criterion)
      else
        wild_criterion = "*"+criterion+"*"
        wild_criteria.push(wild_criterion)
      end
    end
    wild_criteria.pop if wild_criteria.last == "AND" ||
wild_criteria.last == "OR"
    wild_query = wild_criteria.join(" ")
    self.find_by_contents(wild_query)
  end

This also removes trailing logical operators, which will prevent it from
screwing up a live search.
71b46c4f6e9cfec742e18deeec6d2cd9?d=identicon&s=25 Joost Baaij (joost)
on 2008-07-10 11:20
Hi ferret users/devs,

I found this post on ruby-forum which does exactly what I want.

However it feels kinda patchy and since it was posted two years ago, I
am wondering if this behaviour is now built-in?


Brian Keats wrote:
>> I've noticed that typing "t" in the search box will return no results
>> however if I type "t*" it brings up all results beginning with t.
>>
>> I would like this behaviour on by default without having to type the
>> wildcard. Is there a way to do this?
>
> Add the following search method to your model
>
>   def self.search(query)
>     criteria = query.split
>     wild_criteria = []
>     criteria.each do |criterion|
>       if criterion == "AND" || criterion == "OR"
>         wild_criteria.push(criterion)
>       else
>         wild_criterion = "*"+criterion+"*"
>         wild_criteria.push(wild_criterion)
>       end
>     end
>     wild_criteria.pop if wild_criteria.last == "AND" ||
> wild_criteria.last == "OR"
>     wild_query = wild_criteria.join(" ")
>     self.find_by_contents(wild_query)
>   end
>
> This also removes trailing logical operators, which will prevent it from
> screwing up a live search.
This topic is locked and can not be replied to.