Field collapsing on one of multiple models

24 views
Skip to first unread message

tom.ai...@gmail.com

unread,
May 21, 2013, 8:31:50 AM5/21/13
to ruby-s...@googlegroups.com
I am searching through three models like this:

  def self.multiquery q
    Sunspot.search Track, Site, Artist do |query_obj|
      query_obj.keywords q
      query_obj.paginate page: 1, per_page: 16
      query_obj.group :unique_track_id do
        limit 1000
      end
    end
  end

Only Track objects have a :unique_track_id and I only want to group those. Tracks get grouped as they should. What happens though is that all results for other models (Site, Artist) get grouped on :unique_track_id=nil. That is, the result looks like below. The first group contains all found Artist and Site, the others Track.

  SOLR Request (10.2ms)  [ path=#<RSolr::Client:0x00000008d83558> parameters={data: fq=type%3A%28Track+OR+Site+OR+Artist%29&q=country&fl=%2A+score&qf=title_text+artist_text+name_text&defType=dismax&start=0&rows=16&group=true&group.ngroups=true&group.field=unique_track_id_s&group.limit=1000, method: post, params: {:wt=>:ruby}, query: wt=ruby, headers: {"Content-Type"=>"application/x-www-form-urlencoded; charset=UTF-8"}, path: select, uri: http://localhost:8080/solr/select?wt=ruby, open_timeout: , read_timeout: , retry_503: , retry_after_limit: } ]
[
    [ 0] #<Sunspot::Search::Hit:Artist 15482>,
    [ 1] #<Sunspot::Search::Hit:Artist 11502>,
    [ 2] #<Sunspot::Search::Hit:Artist 8812>,
    [ 3] #<Sunspot::Search::Hit:Artist 7474>,
    [ 4] #<Sunspot::Search::Hit:Artist 7449>,
    [ 5] #<Sunspot::Search::Hit:Artist 7168>,
    [ 6] #<Sunspot::Search::Hit:Artist 6015>,
    [ 7] #<Sunspot::Search::Hit:Artist 1438>,
    [ 8] #<Sunspot::Search::Hit:Site 1840>,
    [ 9] #<Sunspot::Search::Hit:Site 1283>,
    [10] #<Sunspot::Search::Hit:Site 863>,
    [11] #<Sunspot::Search::Hit:Site 339>,
    [12] #<Sunspot::Search::Hit:Site 266>
]
[
    [0] #<Sunspot::Search::Hit:Track 4357>
]
[
    [0] #<Sunspot::Search::Hit:Track 2580>
]
[
    [0] #<Sunspot::Search::Hit:Track 2549>
]
[
    [0] #<Sunspot::Search::Hit:Track 1553>,
    [1] #<Sunspot::Search::Hit:Track 1524>,
    [2] #<Sunspot::Search::Hit:Track 1516>
]

My question is then, how can I group/collapse on only one model, for example Track? Is that even possible with Sunspot?

Thanks,

Tom

Reply all
Reply to author
Forward
0 new messages