2014-01-07 73 views
0

我在整數字段中進行分面搜索時遇到了問題,這是此模型的關聯記錄的計數器緩存。基本上是:Rails和Solr:按行篩選

Post.solr_search do 
    facet(:comments_count) do 
    row('No') { with(:comments_count).less_than 1 } 
    row('Yes') { with(:comments_count).greater_than 0 } 
    end 
... 

問題是,我不知道怎麼用這個行過濾,即像

# params[:comments_count] being either 'Yes' or 'No' 
with(:comments_count, params[:comments_count]) # It obviously doesn't work like this 
# or 
with_facet(:comments_count).row params[:comments_count] 

這只是垃圾代碼,我想說明我要找對於。順便說一下,分面查詢的工作原理是,在標籤「否」下帶有評論的帖子,以及標籤爲「是」的評論。不,我想按照這個標準過濾。

「google算法」或文檔都沒有幫助我。

回答

0

找不到妥善的解決辦法,但猴子打補丁這樣的:

Post.solr_search do 
    facet(:comments_count) do 
    row('No') { with(:comments_count).less_than 1 } 
    row('Yes') { with(:comments_count).greater_than 0 } 
    end 

    case params[:comments_count] 
    when 'No' 
    with(:comments_count).less_than 1 
    when 'Yes' 
    with(:comments_count).greater_than 0 
    end