Index description too
This commit is contained in:
@@ -4,7 +4,7 @@ module Card::Searchable
|
||||
included do
|
||||
include ::Searchable
|
||||
|
||||
searchable_by :title, using: :cards_search_index
|
||||
searchable_by :title_and_description, using: :cards_search_index, as: :title
|
||||
|
||||
scope :mentioning, ->(query) do
|
||||
if query = sanitize_query_syntax(query)
|
||||
@@ -18,25 +18,31 @@ module Card::Searchable
|
||||
end
|
||||
end
|
||||
|
||||
class_methods do
|
||||
def sanitize_query_syntax(terms)
|
||||
terms = terms.to_s
|
||||
terms = remove_invalid_search_characters(terms)
|
||||
terms = remove_unbalanced_quotes(terms)
|
||||
terms.presence
|
||||
class_methods do
|
||||
def sanitize_query_syntax(terms)
|
||||
terms = terms.to_s
|
||||
terms = remove_invalid_search_characters(terms)
|
||||
terms = remove_unbalanced_quotes(terms)
|
||||
terms.presence
|
||||
end
|
||||
|
||||
private
|
||||
def remove_invalid_search_characters(terms)
|
||||
terms.gsub(/[^\w"]/, " ")
|
||||
end
|
||||
|
||||
private
|
||||
def remove_invalid_search_characters(terms)
|
||||
terms.gsub(/[^\w"]/, " ")
|
||||
def remove_unbalanced_quotes(terms)
|
||||
if terms.count("\"").even?
|
||||
terms
|
||||
else
|
||||
terms.gsub("\"", " ")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def remove_unbalanced_quotes(terms)
|
||||
if terms.count("\"").even?
|
||||
terms
|
||||
else
|
||||
terms.gsub("\"", " ")
|
||||
end
|
||||
end
|
||||
private
|
||||
# TODO: Temporary until we stabilize the search API
|
||||
def title_and_description
|
||||
[title, description.to_plain_text].join(" ")
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user