The search API returns a QueryError when the Query contains ',' (Comma) or = or ()

Using the application search API, I tried to search for requests containing,, = , ( etc. It returns the following error:

 Failed to parse query "engines (Modular)" Traceback (most recent call last): File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1505, in __call__ rv = self.router.dispatch(request, response) File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher return route.handler_adapter(request, response) File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1077, in __call__ return handler.dispatch() File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 547, in dispatch return self.handle_exception(e, self.app.debug) File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch return method(*args, **kwargs) File "/base/data/home/apps/s~generatestock/12.362076640167792770/search.py", line 1641, in get result = find_search_document(search_item) File "/base/data/home/apps/s~generatestock/12.362076640167792770/search.py", line 177, in find_search_document return search.Index(name=_INDEX_NAME).search(query) File "/base/python27_runtime/python27_lib/versions/1/google/appengine/api/search/search.py", line 2715, in search query = Query(query_string=query) File "/base/python27_runtime/python27_lib/versions/1/google/appengine/api/search/search.py", line 2286, in __init__ _CheckQuery(self._query_string) File "/base/python27_runtime/python27_lib/versions/1/google/appengine/api/search/search.py", line 1964, in _CheckQuery raise QueryError('Failed to parse query "%s"' % query) QueryError: Failed to parse query "Engines (Modular)" 

Why? Does the search API support these characters?

+4
source share
1 answer

To parse a phrase, use the quotes around the phrase:

 query = '"Engines (Modular)"' search.Index(name=_INDEX_NAME).search(query) 

You can simply put quotes around an existing query:

 query = '"{0}"'.format(query) search.Index(name=_INDEX_NAME).search(query) 

but you may have to remove the existing quotation marks in the query to make this work. The Google documentation does not say how to include quotation marks in search queries. Thus, a complete, fail-safe method:

 query = '"{0}"'.format(query.replace('"', '')) search.Index(name=_INDEX_NAME).search(query) 
+6
source

Source: https://habr.com/ru/post/1436931/


All Articles