local function EscapeFtPunctuation(cRet)
-- Escape RediSearch FT (full text) search punctuation characters, like '-' (becomes '\-')
-- Also escape spaces, see: http://redisearch.io/Tags/
-- For punctuation characters, see: https://github.com/RedisLabsModules/RediSearch/blob/master/src/toksep.h
-- From the C code:
--[[ [' '] = 1, ['\t'] = 1, [','] = 1, ['.'] = 1, ['/'] = 1, ['('] = 1, [')'] = 1,
['{'] = 1, ['}'] = 1, ['['] = 1, [']'] = 1, [':'] = 1, [';'] = 1, ['\\'] = 1,
['~'] = 1, ['!'] = 1, ['@'] = 1, ['#'] = 1, ['$'] = 1, ['%'] = 1, ['^'] = 1,
['&'] = 1, ['*'] = 1, ['-'] = 1, ['='] = 1, ['+'] = 1, ['|'] = 1, ['\''] = 1,
['`'] = 1, ['"'] = 1, ['<'] = 1, ['>'] = 1, ['?'] = 1,
]]
-- Lua gsub: The lua magic characters are ( ) . % + - * ? [ ^ $
-- So: prepend with '%' in the gsub pattern string (first parameter)
return (cRet:gsub('[ \t,%./%(%){}%[%]:;\\~!@#%$%%%^&%*%-=%+|\'`"<>%?_]', {
[' ' ]='\\ ' ,
['\t']='\\\t' ,
[',' ]='\\,' ,
['.' ]='\\.' ,
['/' ]='\\/' ,
['(' ]='\\(' ,
[')' ]='\\)' ,
['{' ]='\\{' ,
['}' ]='\\}' ,
['[' ]='\\[' ,
[']' ]='\\]' ,
[':' ]='\\:' ,
[';' ]='\\;' ,
['\\']='\\\\' ,
['~' ]='\\~' ,
['!' ]='\\!' ,
['@' ]='\\@' ,
['#' ]='\\#' ,
['$' ]='\\$' ,
['%' ]='\\%' ,
['^' ]='\\^' ,
['&' ]='\\&' ,
['*' ]='\\*' ,
['-' ]='\\-' ,
['=' ]='\\=' ,
['+' ]='\\+' ,
['|' ]='\\|' ,
['\'']='\\\'' ,
['`' ]='\\`' ,
['"' ]='\\"' ,
['<' ]='\\<' ,
['>' ]='\\>' ,
['?' ]='\\?' ,
-- Add underscore as well, seems needed
['_' ]='\\_' ,
}))
end
--
You received this message because you are subscribed to the Google Groups "redisearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redisearch+...@googlegroups.com.
To post to this group, send email to redis...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/redisearch/76886cc0-dc8e-4552-8f2d-b1b72fa24387%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/redisearch/ab4cf306-a8aa-4bbb-a5bb-222604fc572f%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/redisearch/25ad0743-7009-4b08-a7f0-f0249cda7214%40googlegroups.com.