Save 36% for Black Friday! Learn more

makeapp

Joined

10 Experience
0 Lessons Completed
0 Questions Solved

Activity

Posted in Searchick filter with scope

Hi, I still have this problem. When I create a user whose role is not "a" and search, I can get that user. Should I specify where in the search function? But when I explicitly call People.reindex, I can not get that user any more.

This is what I write

People.rb
scope :search_import, ->{where(role:"a")}
def should_index?
  self.search_import
end
def search_data
  {
    username: username,
    description:description,
    role:role,
  }
end

When I search, i use

result=People.search(params[:search], {fields: [role], autocomplete: true, load: false, misspellings: {below: 4}}) 
logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2020 GoRails, LLC. All rights reserved.