Initial commit
This commit is contained in:
27
app/models/concerns/searchable.rb
Normal file
27
app/models/concerns/searchable.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
module Searchable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
include PgSearch
|
||||
end
|
||||
|
||||
class_methods do
|
||||
def searchable_on(fields)
|
||||
search_opts = {
|
||||
against: fields,
|
||||
associated_against: {
|
||||
notes: [:content],
|
||||
tags: [:name],
|
||||
internal_tags: [:name]
|
||||
},
|
||||
using: {
|
||||
tsearch: { any_word: true, prefix: true },
|
||||
trigram: {},
|
||||
dmetaphone: { any_word: true },
|
||||
}
|
||||
}
|
||||
|
||||
send(:pg_search_scope, :search, search_opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user