Class TokenEscaper

java.lang.Object
com.redis.vl.utils.TokenEscaper

public class TokenEscaper extends Object
Escape punctuation within an input string.

Ported from Python: redisvl/utils/token_escaper.py

Adapted from RedisOM Python.

Characters that RediSearch requires us to escape during queries.

Source: Redis Search Escaping

Since:
0.1.0
  • Constructor Details

    • TokenEscaper

      public TokenEscaper()
      Default constructor using default escaped characters.
    • TokenEscaper

      public TokenEscaper(Pattern escapeCharsPattern)
      Constructor with custom escape pattern.
      Parameters:
      escapeCharsPattern - custom pattern for characters to escape
  • Method Details

    • escape

      public String escape(String value)
      Escape special characters in the input string.

      Python equivalent:

       def escape(self, value: str) -> str:
           def escape_symbol(match):
               value = match.group(0)
               return f"\\{value}"
           return self.escaped_chars_re.sub(escape_symbol, value)
       
      Parameters:
      value - the string to escape
      Returns:
      escaped string
      Throws:
      IllegalArgumentException - if value is not a string