문제

I'm having trouble with faceted search over an integer field, that is a counter cache for associated records of this model. Basically:

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
...

Problem is, I don't know how to filter by this rows, i.e. something like

# 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]

That's just crap code, I'm trying to illustrate what I'm looking for. Btw, the faceted query works, it brings posts with no comments under the label 'No', and the ones with comments under the label 'Yes'. No I want to filter by that criteria.

Neither the "google algorithm" or the docs have helped me.

도움이 되었습니까?

해결책

Couldn't find a proper solution but monkey patched it like this:

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top