#63 ✓resolved
Marcel Ruegenberg

Bug with grouping and like conditions

Reported by Marcel Ruegenberg | March 6th, 2009 @ 07:21 AM

Following up #51, I tried the solution described there and found a small bug in conditions/like.rb.

I think LIKE-Conditions should be grouped with OR, instead of AND.
Usually, LIKE-conditions joined with AND will cancel out each other, producing an empty result. It is of course possible to write LIKE-conditions that, when joined with AND, do not overlap, but this is a rare case at best.

Adding the line

self.join_arrays_with_or = true
to conditions/like.rb fixes this for me.

Comments and changes to this ticket

  • Deepu

    Deepu March 23rd, 2009 @ 02:41 AM

    Even i had the same issue. did what Marcel did and am happy now. i strongly suggest patching Marcel's solution as the default behaviour

  • Ben Johnson

    Ben Johnson March 23rd, 2009 @ 02:45 AM

    • State changed from “new” to “open”

    I went with AND because the goal is to narrow your search, not broaden it. Usually when people type more terms in a search box they expect the results to narrow down to results containing all terms. Am I missing something?

  • Deepu

    Deepu March 23rd, 2009 @ 03:09 AM

    @Ben - what you said is true in case of doing a more general full-text search(As there is too much info and i need to narrow down). But when i am searching a specific string/text column in most of the cases we end up needing OR condition instead of AND.

    ex - searching a specific column for city or state names, searching for all users who has given any of x,y,z exams etc etc.

    Else if you strongly feel default should be AND it is still ok if you provide an elegant way of changing that behavior to OR when required

  • Ben Johnson

    Ben Johnson March 23rd, 2009 @ 03:12 AM

    Hi Deepu, I agree, its really a case by case basis. Changing that value is very easy. Just put a searchlogic.rb file in your initializers dir and have it do the following:

    Searchlogic::Condition::Like.join_arrays_with_or = true
  • Deepu

    Deepu March 23rd, 2009 @ 03:40 AM

    thanks a bunch Ben.

  • Ben Johnson

    Ben Johnson March 30th, 2009 @ 11:56 AM

    • State changed from “open” to “resolved”

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Provides common named scopes and object based searching.

People watching this ticket