Anh Pham
Anh Pham

Reputation: 5481

How to exclude records in searchkick?

I need to exclude records from searchkick when it has less than 3 tags. Right now, my search_data function is as follow:

def search_data
  {
    ...
    tag_ids: tags.map(&:id)
  }
end

Can I do this?

def search_data
  return nil if tags.count < 3
  {
    ...
    tag_ids: tags.map(&:id)
  }
end

Or can I add some condition when I perform lookup(), so it only search records that have tag_ids array with 3 or more id? (Other than add a tag_count field and reindex everything?)

Thanks!

Upvotes: 0

Views: 915

Answers (1)

Linell
Linell

Reputation: 749

Searchkick provides the ability to define a should_index? method that does exactly what you're looking for. Check it out here!

Upvotes: 2

Related Questions