Using the wildcard plus partial searched

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?

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 [email protected]
Schnorrstraße 76 Tel +49 351 46766 0
D-01069 Dresden Fax +49 351 46766 66

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.

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.