On Sep 16, 2:32 pm, Joe Van Dyk <[email protected]> wrote:
> I often need to do something like:
>
> def search *keywords
>   select * from something where column ilike '%first-keyword%' OR
> column ilike '%second-keyword%' ......;
> end

I'd recommend Dataset#grep:

  DB[:something].grep(:column, %w'%first% %second% %third
%', :case_insensitive=>true)

> So, the query would contain an arbitrary amount of OR'd conditions,
> depending on how many keywords were passed in to the search function.

grep works for this case, but in general you would be looking at
something with .inject(:|).

> I'm having trouble getting sequel to do the right syntax.  If I wanted
> AND instead of ORs, I could do something like:
>
> query = DB[:table]....
> keywords.each { |k| query = query.filter("column ilike ?, "%#{k}%" }

You might be able to get Dataset#or to work similarly, but it is not
an exact replacement for what you want.

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to