searchstringparser.parser
¶
-
class
searchstringparser.parser.postgresql.
PostgreSQLTextSearchParser
(lexer=None, **kw_args)[source]¶ Bases:
object
This parser implements the following rules using the tokens generated by an appropriate lexer. The goal is to generate a string for PostgreSQL full text search that conforms with the syntax understood by the function tsquery or to_tsquery.
The following rules are implemented which generate the correct query string.
expression : expression expression | expression AND expression | expression OR expression | NOT expression | LPAREN expression RPAREN | QUOTE term QUOTE | WORD WILDCARD | WORD term : term SPACE term | term term | LITERAL_QUOTE | SYMBOL
-
__init__
(lexer=None, **kw_args)[source]¶ Parser instantiation.
Parameters: - lexer (ply.lex (optional)) – Any ply.lex lexer instance and generates the tokens listed in the rules. The default uses a GeneralSearchStringLexer instance.
- kw_args – Keyword arguments are passed to the ply.yacc.yacc call.
-
get_illegal
()[source]¶ Inspect encountered illegal characters.
Returns: - None – If no illegal characters occurred.
- Tuple – A pair of lists that contain the illegal characters and the positions where they occurred.
-
parse
(query, **kw_args)[source]¶ Parse any string input according to the rules.
Parameters: - query (str) – A string expected to conform with the search query syntax.
- kw_args – Keyword arguments are passed on to the ply.yacc.yacc.parse call.
Returns: A string that can directly be passed to the PostgreSQL functions tsquery or to_tsquery.
Return type: str
-