Nexted search criteria.

0 views
Skip to first unread message

Dan Barber

unread,
Jul 12, 2010, 10:29:50 AM7/12/10
to Searchlogic
Hi,

I've just started using RoR and the app I manage uses SearchLogic for
it's searching capabilities. We need to be able to do something like
the following SQL:

SELECT * FROM table WHERE (title LIKE '%text%' OR description LIKE
'%text%') AND group_id = '%group%';

Is this possible?

- Dan

Dan Barber

unread,
Jul 22, 2010, 4:59:12 AM7/22/10
to Searchlogic
Of course, I meant nested!

ricsrock

unread,
Jul 22, 2010, 8:29:58 AM7/22/10
to searc...@googlegroups.com
Try this:

Thing.group_id_equals(id).title_or_description_like('text')

Lowell

> --
> You received this message because you are subscribed to the Google
> Groups "Searchlogic" group.
> To post to this group, send email to searc...@googlegroups.com.
> To unsubscribe from this group, send email to searchlogic...@googlegroups.com
> .
> For more options, visit this group at http://groups.google.com/group/searchlogic?hl=en
> .
>

Dan Barber

unread,
Jul 22, 2010, 11:48:34 AM7/22/10
to Searchlogic
Thanks for that. Unfortunately it doesn't work because the app I'm
trying to fix uses an old version of SearchLogic (1.6.6). I'm going to
try and update the app to use the latest release.

ricsrock

unread,
Jul 22, 2010, 11:58:15 AM7/22/10
to searc...@googlegroups.com
You could create a named scope for the OR condition:

named_scope :or_for_title_description, lambda {|text| { :conditions =>
['title LIKE ? OR description LIKE ?', text, text]}}

Then do:

Thing.group_id_equals(id).or_for_title_description('text')

untested

Lowell

Dan Barber

unread,
Jul 23, 2010, 10:05:47 AM7/23/10
to Searchlogic
I discovered SearchLogic 1.6.6's grouping functions and this has
enabled me to do what I require:

@search = Thing.new_search()

group_description = @search.conditions.group
group_description.or_title_like = "text"
group_description.or_description_like = "text"

@search.conditions.group_id_equals = 2

This results in SQL like this: SELECT * FROM `things` WHERE
((`things`.`title` LIKE 'text' OR `things`.`description` LIKE 'text')
AND `things`.`group_id` = 2)
Reply all
Reply to author
Forward
0 new messages