#68 ✓resolved
nico

add explicitly :includes in a search request

Reported by nico | March 23rd, 2009 @ 06:38 AM

I would like to explicitly includes 2 tables in a search query to improve the process of the results

I didn't find any documentation to do that.

I tried:
search = Measure.new_search({:includes=>[:measures_tags,:tags]})

search = Measure.new_search() search.options[:includes]=>[:measures_tags,:tags]

search = Measure.new_search() search.includes=[:measures_tags,:tags]

but nothing works..

Is there a way to do that with searchlogic?

Thanks in advance

Comments and changes to this ticket

  • Deepu

    Deepu March 23rd, 2009 @ 07:25 AM

    @Nico - If i am not wrong you want to include some conditions on the associated tables ? If so then this will do:-

    search = Measure.new_search search.conditions.measures_tags.x_gt = params[:x] search.conditions.tags.y_lt = params[:y] @results = search.all

    just make sure you have proper associations in the respective models.

    Am not sure whether i understood your problem correctly though

  • Deepu

    Deepu March 23rd, 2009 @ 07:28 AM

    sorry above comment was formatted all lost. The code is

    @@@

     search = Measure.new_search search.conditions.measures_tags.x_gt = params[:x] search.conditions.tags.y_lt = params[:y] @results = search.all
    
    
    
    
  • Deepu

    Deepu March 23rd, 2009 @ 07:28 AM

    damn this formatting.

    
    search = Measure.new_search; search.conditions.measures_tags.x_gt = params[:x];
    search.conditions.tags.y_lt = params[:y];
     @results = search.all
    
  • Deepu

    Deepu March 23rd, 2009 @ 10:28 AM

    @nico :-

    try search.all(:include => "tags") . it worked for me.

    Cheers, Deepu.

  • Ben Johnson

    Ben Johnson March 23rd, 2009 @ 05:26 PM

    • State changed from “new” to “open”

    I don't think this is searchlogic, I think ActiveRecord splits it up into multiple queries for performance reasons. Im fairly certain they made this change within the last 6 months or so. Try doing the query without searchlogic, i bet you get the same results.

  • Ben Johnson

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

    I am busy and have a job just like you. It would help me out if you could create a failing test, then I could quickly fix the issue and move on, instead of having to read through all of this. Or you could always try and fix it yourself. Thanks.

  • Georg Ledermann

    Georg Ledermann May 22nd, 2009 @ 07:16 AM

    Stumbled upon the same problem. The :include options seems to be ignored. Hoping Ben has time to fix this... Perhaps this bug is another argument for building the version 2.0 of Searchlogic :)

  • Ben Johnson

    Ben Johnson May 22nd, 2009 @ 10:33 AM

    Well it seems to be working for me:

    >> s = Neighborhood.new_search
    => #25}>
    >> s.include = :relationships
    => :relationships
    >> s.sanitize
    => {:limit=>25, :include=>:relationships}
    

    Also, I remember reading somewhere that AR changed how it treats that option. I might be way off here, but I think they lazily load those records because it was faster to perform a bunch of small queries than one big one.

  • Georg Ledermann

    Georg Ledermann May 22nd, 2009 @ 10:52 AM

    Thank you for this hint, Ben!
    It seems there is difference in this two approaches:

    1)

     s = Neighborhood.new_search
     s.include = :relationships
     s.find :all
    

    => Works fine, the include option is given to AR

    2)

     s = Neighborhood.new_search
     s.find :all, :include => :relationships
    

    => Fails because it ignores the include option

  • Ben Johnson

    Ben Johnson June 20th, 2009 @ 05:02 AM

    • State changed from “open” to “resolved”

    v2 should resolve this issue as it falls into the standard practices of using the :include option. Hope this helps. But the first example georg gave is correct.

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

Pages