Question

Im trying to exclude current_user.id from my Tire search results but cannot figure how to pass a param to Tire and use that instead of a fixed value for search. How could one pass the current_user.id to the model and exclude it in search results?

Activerecord way:

Profile.where("user_id != ?", current_user.id)

My tire search block:

if params['people']
  tire.search(load: true, page: params[:page], per_page: 20, :default_operator => 'AND') do
    query do
      boolean do
        must_not { string 'user_id: 1' } <== this works hardcoded
        must_not { string 'user_id: < instead of 1 user current_user.id pass in true params?' }          
      end
    end
    to_curl
  end
end
Was it helpful?

Solution

Have you tried to use the "imperative style" the README mentions on https://github.com/karmi/tire ? This is a straight quote from the readme:

search = Tire::Search::Search.new('articles')
search.query  { string('title:T*') }
search.filter :terms, :tags => ['ruby']
search.sort   { by :title, 'desc' }
search.facet('global-tags') { terms :tags, :global => true }
# ...
p search.results

Maybe the "declarative" style folds to much blocks inside each other, and then the context (current_user) is lost. How exactly did you insert the current_user_id in your boolean condition?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top