def _validated_query_string_query(self, query): try: query = prefixfields(EMBEDDED, query, dialects.elasticsearch) except IllegalStateException: msg = "Invalid query: {}".format(query) raise HTTPBadRequest(explanation=msg) return query.getText()
def prepare_search_term(request): search_term = request.params.get('searchTerm', '').strip() or '*' if search_term == '*': return search_term # avoid interpreting slashes as regular expressions search_term = search_term.replace('/', r'\/') # elasticsearch uses : as field delimiter, but we use it as namespace designator # if you need to search fields you have to use @type:field # if you need to search fields where the field contains ":", you will have to escape it # yourself if search_term.find("@type") < 0: search_term = search_term.replace(':', r'\:') try: query = prefixfields('embedded.', search_term, dialects.elasticsearch) except IllegalStateException: msg = "Invalid query: {}".format(search_term) raise HTTPBadRequest(explanation=msg) else: return query.getText()
def prepare_search_term(request): from antlr4 import IllegalStateException from lucenequery.prefixfields import prefixfields from lucenequery import dialects search_term = request.params.get('searchTerm', '').strip() or '*' if search_term == '*': return search_term # elasticsearch uses : as field delimiter, but we use it as namespace designator # if you need to search fields you have to use @type:field # if you need to search fields where the field contains ":", you will have to escape it # yourself if search_term.find("@type") < 0: search_term = search_term.replace(':', '\:') try: query = prefixfields('embedded.', search_term, dialects.elasticsearch) except (IllegalStateException): msg = "Invalid query: {}".format(search_term) raise HTTPBadRequest(explanation=msg) else: return query.getText()
def test_prefixfields(dialect, query, expect): from lucenequery import dialects from lucenequery.prefixfields import prefixfields clause = prefixfields('prefix.', query, dialect=dialects.elasticsearch) assert clause.getText() == expect