conditions any?

13 views
Skip to first unread message

eimantas

unread,
Jun 19, 2009, 5:40:50 AM6/19/09
to Searchlogic
Hi

In verstion 1 there was a method 'any!' to define that search should
be made by union and not intersection. Is there any similar method in
2.0. i can't seem to find it anywhere

Gokul Janga

unread,
Jun 19, 2009, 7:05:37 AM6/19/09
to Searchlogic
The documentation does have an example -

Use any or all

Every condition you’ve seen in this readme also has 2 related
conditions that you can use. Example:

User.username_like_any("bjohnson", "thunt") # will return any
users that have either of the strings in their username
User.username_like_all("bjohnson", "thunt") # will return any
users that have all of the strings in their username
User.username_like_any(["bjohnson", "thunt"]) # also accepts an
array

Christian Mayer

unread,
Jun 19, 2009, 5:23:13 PM6/19/09
to Searchlogic
On Jun 19, 1:05 pm, Gokul Janga <gok...@gmail.com> wrote:
> On Jun 19, 2:40 pm, eimantas <enc.c...@gmail.com> wrote:

> > In verstion 1 there was a method 'any!' to define that search should
> > be made by union and not intersection. Is there any similar method in
> > 2.0. i can't seem to find it anywhere

> The documentation does have an example -
>
> Use any or all
>
> Every condition you’ve seen in this readme also has 2 related
> conditions that you can use. Example:
>
>   User.username_like_any("bjohnson", "thunt")   # will return any
> users that have either of the strings in their username
>   User.username_like_all("bjohnson", "thunt")   # will return any
> users that have all of the strings in their username
>   User.username_like_any(["bjohnson", "thunt"]) # also accepts an
> array

I think eimantas meant Module: Searchlogic::Conditions::AnyOrAll#any!
which made the following possible:
| @search.conditions.any = true # can set this to "true" or "1" or
"yes"
| @search.all # will join all conditions with "or" instead of "and"


For my use case I created a named scope:
| named_scope :name_like, lambda { |n| {:conditions => ["first_name
LIKE ? OR last_name LIKE ?", "%#{n}%", "%#{n}%"] }}

I don't find this particularly elegant, but I don't see how I can
search for first_name OR last_name with searchlogic v2.


regards,
chris

kshet26

unread,
Jul 1, 2009, 2:25:49 PM7/1/09
to Searchlogic
I too am looking for this functionality in V2. This is an important
aspect of search forms.

eimantas

unread,
Jul 7, 2009, 8:25:48 AM7/7/09
to Searchlogic
Chris - thanks! Your solution should work for now (until it's,
hopefully, implemented in SL 2.0)

// E.

johnnyn

unread,
Jul 16, 2009, 11:34:53 AM7/16/09
to Searchlogic
I am also looking for the same functionality. Chris, your solution
works with a complete match, but it'd be nice to have the
functionality of 'any!'.

For instance...
User.username_like_any("bjohnson", "thunt").email_like_any("bjohnson",
"thunt") gets:
SELECT * FROM `users` WHERE ((user.username LIKE '%bjohnson%' OR
user.username LIKE '%thunt%') AND (user.email LIKE '%bjohnson%' OR
user.email LIKE '%thunt%'))

Would like:
SELECT * FROM `users` WHERE ((user.username LIKE '%bjohnson%' OR
user.username LIKE '%thunt%') OR (user.email LIKE '%bjohnson%' OR
user.email LIKE '%thunt%'))

Has anyone found a way to do this?


On Jul 7, 7:25 am, eimantas <enc.c...@gmail.com> wrote:
> Chris - thanks! Your solution should work for now (until it's,
> hopefully, implemented in SL 2.0)
>
> // E.
>
> On Jun 20, 12:23 am, Christian Mayer <ch.ma...@gmail.com> wrote:
>
> > On Jun 19, 1:05 pm, Gokul Janga <gok...@gmail.com> wrote:
>
> > > On Jun 19, 2:40 pm, eimantas <enc.c...@gmail.com> wrote:
> > > > In verstion 1 there was a method 'any!' to define that search should
> > > > be made by union and not intersection. Is thereanysimilar method in
> > > > 2.0. i can't seem to find it anywhere
> > > The documentation does have an example -
>
> > > Useanyor all
>
> > > Every condition you’ve seen in this readme also has 2 related
> > > conditions that you can use. Example:
>
> > >   User.username_like_any("bjohnson", "thunt")   # will returnany
> > > users that have either of the strings in their username
> > >   User.username_like_all("bjohnson", "thunt")   # will returnany
> > > users that have all of the strings in their username
> > >   User.username_like_any(["bjohnson", "thunt"]) # also accepts an
> > > array
>
> > I think eimantas meant Module: Searchlogic::Conditions::AnyOrAll#any!
> > which made the following possible:
> > |  @search.conditions.any= true # can set this to "true" or "1" or

Q

unread,
Aug 1, 2009, 7:31:34 AM8/1/09
to Searchlogic
bump

Ben Johnson

unread,
Aug 1, 2009, 4:34:45 PM8/1/09
to searc...@googlegroups.com
I dont plan on supporting this because the joining of conditions is
not something authlogic handles. Authlogic just leverages named
scopes, which join conditions with AND. In order to provide this
functionality I would have to alter private methods in AR, which is
not something I want to do. If you want fork the repo and give it a
shot I'm all for it, but I don't have any plans to add this in.



Ben Johnson
Binary Logic

W: www.binarylogic.com
E: bjoh...@binarylogic.com

On Aug 1, 2009, at 7:31 AM, Q wrote:

>
> bump
>
> >

Reply all
Reply to author
Forward
0 new messages