Skip to content

Commit

Permalink
Normalize text input into search / ingest channels
Browse files Browse the repository at this point in the history
  • Loading branch information
bendangelo committed Nov 26, 2023
1 parent 1a24b2b commit 8661886
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/sonic/channels/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def normalize(value)
end

def sanitize(value)
value.gsub('"', '\\"').gsub(/[\r\n]+/, ' ')
value.gsub('"', '\\"').gsub(/[\r\n]+/, '\\n').gsub(/\\/, '\\\\')
end

def quote(value)
Expand Down
4 changes: 2 additions & 2 deletions lib/sonic/channels/ingest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ module Sonic
module Channels
class Ingest < Base
def push(collection, bucket, object, text, lang = nil)
arr = [collection, bucket, object, quote(text)]
arr = [collection, bucket, object, normalize(text)]
arr << "LANG(#{lang})" if lang

execute('PUSH', *arr)
end

def pop(collection, bucket, object, text)
execute('POP', collection, bucket, object, quote(text))
execute('POP', collection, bucket, object, normalize(text))
end

def count(collection, bucket = nil, object = nil)
Expand Down
4 changes: 2 additions & 2 deletions lib/sonic/channels/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Sonic
module Channels
class Search < Base
def query(collection, bucket, terms, limit = nil, offset = nil, lang = nil) # rubocop:disable Metrics/ParameterLists, Metrics/LineLength
arr = [collection, bucket, quote(terms)]
arr = [collection, bucket, normalize(terms)]
arr << "LIMIT(#{limit})" if limit
arr << "OFFSET(#{offset})" if offset
arr << "LANG(#{lang})" if lang
Expand All @@ -13,7 +13,7 @@ def query(collection, bucket, terms, limit = nil, offset = nil, lang = nil) # ru
end

def suggest(collection, bucket, word, limit = nil)
arr = [collection, bucket, quote(word)]
arr = [collection, bucket, normalize(word)]
arr << "LIMIT(#{limit})" if limit

execute('SUGGEST', *arr) do
Expand Down

0 comments on commit 8661886

Please sign in to comment.