Benjamin Arai
2008-Jan-16 21:03 UTC
[Ferret-talk] Escaping special characters :, (, ), [, ], {, }, !, +, ", ~, ^, -, |, <, >, =, *, ?, \
Hello, I am trying to escape words for searching i.e., "hello". The key here is that the two L''s on "hello" are actually vertical bars. Is there a special function in Ferret or anywhere for that matter that will do the escaping of the Ferret special characters? Thanks in advance, Benjamin
Benjamin Arai
2008-Jan-16 23:51 UTC
[Ferret-talk] Escaping special characters :, (, ), [, ], {, }, !, +, ", ~, ^, -, |, <, >, =, *, ?, \
Hello, I am going to answer my own questions... You can do something like: def escape_string(str) str = Regexp.escape(item[:word]).gsub(/([:~!<>="])/,''\\\\\1'') end At one time there was a function called clean_string in QueryParser but it appears to be gone. Benjamin On Jan 16, 2008, at 1:03 PM, Benjamin Arai wrote:> Hello, > > I am trying to escape words for searching i.e., "hello". The key here > is that the two L''s on "hello" are actually vertical bars. Is there > a special function in Ferret or anywhere for that matter that will do > the escaping of the Ferret special characters? > > Thanks in advance, > > Benjamin > _______________________________________________ > Ferret-talk mailing list > Ferret-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/ferret-talk >
Benjamin Arai
2008-Jan-17 01:19 UTC
[Ferret-talk] Escaping special characters :, (, ), [, ], {, }, !, +, ", ~, ^, -, |, <, >, =, *, ?, \
Woops... corrected code below:> def escape_string(str) > return Regexp.escape(str).gsub(/([:~!<>="])/,''\\\\\1'') > endOn Jan 16, 2008, at 3:51 PM, Benjamin Arai wrote:> Hello, > > I am going to answer my own questions... > > You can do something like: > > def escape_string(str) > str = Regexp.escape(item[:word]).gsub(/([:~!<>="])/,''\\\\\1'') > end > > At one time there was a function called clean_string in QueryParser > but it appears to be gone. > > Benjamin > > On Jan 16, 2008, at 1:03 PM, Benjamin Arai wrote: > >> Hello, >> >> I am trying to escape words for searching i.e., "hello". The key here >> is that the two L''s on "hello" are actually vertical bars. Is there >> a special function in Ferret or anywhere for that matter that will do >> the escaping of the Ferret special characters? >> >> Thanks in advance, >> >> Benjamin >> _______________________________________________ >> Ferret-talk mailing list >> Ferret-talk at rubyforge.org >> http://rubyforge.org/mailman/listinfo/ferret-talk >> > > _______________________________________________ > Ferret-talk mailing list > Ferret-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/ferret-talk >