Last active
October 2, 2019 17:37
-
-
Save felipefunes/d1295e1cd6a02b002f5375bede0a87fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ===== 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