Skip to content

Instantly share code, notes, and snippets.

@felipefunes
Last active October 2, 2019 17:37
Show Gist options
  • Save felipefunes/d1295e1cd6a02b002f5375bede0a87fb to your computer and use it in GitHub Desktop.
Save felipefunes/d1295e1cd6a02b002f5375bede0a87fb to your computer and use it in GitHub Desktop.
# ===== MULTISEARCH ===== #
include PgSearch::Model
multisearchable against: [:attributes, :you, :want, :to, :index]
def search(query)
found_ids = PgSearch.multisearch(query).pluck(:searchable_id)
YourModel.where(id: found_ids)
end
# configure type search options
PgSearch.multisearch_options = {
using: :tsearch
}
YourModel.search('What ever you want to search')
# ===== SCOPES ===== #
include PgSearch::Model
pg_search_scope :search_scope_name, against: [:attributes, :you, :want, :to, :index]
YourModel.search_scope_name('What ever you want to search')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment