mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-02-17 04:01:29 -05:00
FIX: remove invalid chars from ts_query helper
This commit is contained in:
parent
eed040767f
commit
ecac786f86
2 changed files with 12 additions and 1 deletions
|
@ -462,7 +462,6 @@ class Search
|
|||
|
||||
def self.ts_query(term, locale = nil, joiner = "&")
|
||||
|
||||
|
||||
data = Post.exec_sql("SELECT to_tsvector(:locale, :term)",
|
||||
locale: locale || long_locale,
|
||||
term: term
|
||||
|
@ -470,6 +469,10 @@ class Search
|
|||
|
||||
locale = Post.sanitize(locale) if locale
|
||||
all_terms = data.scan(/'([^']+)'\:\d+/).flatten
|
||||
all_terms.map! do |t|
|
||||
t.split(/[\)\(&']/)[0]
|
||||
end.compact!
|
||||
|
||||
query = Post.sanitize(all_terms.map {|t| "#{PG::Connection.escape_string(t)}:*"}.join(" #{joiner} "))
|
||||
"TO_TSQUERY(#{locale || query_locale}, #{query})"
|
||||
end
|
||||
|
|
|
@ -443,5 +443,13 @@ describe Search do
|
|||
end
|
||||
end
|
||||
|
||||
it 'can parse complex strings using ts_query helper' do
|
||||
str = " grigio:babel deprecated? "
|
||||
str << "page page on Atmosphere](https://atmospherejs.com/grigio/babel)xxx:"
|
||||
|
||||
ts_query = Search.ts_query(str, "simple")
|
||||
Post.exec_sql("SELECT to_tsvector('bbb') @@ " << ts_query)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue