のえら

技術備忘とかメモとか.間違いはつっこんでいただきたい所存.アフィリエイトはやっていません.

【rails】solrのfacetでカラムごとにまとめたときの件数が100しか取得できない

solrでfacetを使うと、指定したカラムごとにまとめた結果を取得することができる。

results = User.search do
  facet(:hoge_ids, :foo_ids)
end
results.facet(:hoge_ids).rows

これはhoge_idsとfoo_idsでまとめて、facet(:hoge_ids).rowsでhoge_idsの結果を取得している。
このとき、まとめた件数が100件以上あっても上限が100件になってしまう。

# return 100
results.facet(:foo_ids).rows.count

max100件の設定も指定もしてないよなぁ、と思って調べてみると、readmeに書いてあった。。読もうね自分!
GitHub - sunspot/sunspot: Solr-powered search for Ruby objects

By default Sunspot will only return the first 100 facet values. You can increase this limit, or force it to return all facets by setting limit to -1.

 -1を指定しろとのこと。

User.search do
  facet(:hoge_ids)
  # 対象のカラムのみ指定する
  facet(:foo_ids, limit: -1)
  # どちらも全件返したいときは、1行ずつ指定する必要がある(引数まとめて書けない)
end

参考URL:
http://stackoverflow.com/questions/24388263/faceting-with-solr-sunspot-gem-facets-quantity-limit
https://groups.google.com/forum/#!topic/ruby-sunspot/yPXwPtzJSLI