mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-05-01 08:25:18 -04: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 = "&")
|
def self.ts_query(term, locale = nil, joiner = "&")
|
||||||
|
|
||||||
|
|
||||||
data = Post.exec_sql("SELECT to_tsvector(:locale, :term)",
|
data = Post.exec_sql("SELECT to_tsvector(:locale, :term)",
|
||||||
locale: locale || long_locale,
|
locale: locale || long_locale,
|
||||||
term: term
|
term: term
|
||||||
|
@ -470,6 +469,10 @@ class Search
|
||||||
|
|
||||||
locale = Post.sanitize(locale) if locale
|
locale = Post.sanitize(locale) if locale
|
||||||
all_terms = data.scan(/'([^']+)'\:\d+/).flatten
|
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} "))
|
query = Post.sanitize(all_terms.map {|t| "#{PG::Connection.escape_string(t)}:*"}.join(" #{joiner} "))
|
||||||
"TO_TSQUERY(#{locale || query_locale}, #{query})"
|
"TO_TSQUERY(#{locale || query_locale}, #{query})"
|
||||||
end
|
end
|
||||||
|
|
|
@ -443,5 +443,13 @@ describe Search do
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue