Closed PSvishnu93 closed 5 years ago
That's best done by customizing the search factory which you configure here
# my-site/config.py
from invenio_records_rest.query import default_search_factory
from elasticsearch_dsl.query import Q
def my_query_parser(qstr=None):
if qstr:
return Q('query_string', query=qstr)
return Q()
def my_search_factory(*args, **kwargs):
return default_search_factory(*args, **kwargs, query_parser=my_query_parser)
RECORDS_REST_ENDPOINTS = {
'recid': {
# ...
'search_factory_imp': my_search_factory,
}
}
my_query_parser
is the function you want to modify in order to implement the parsing. Right now what it does, is to simply parse the query to Elasticsearch and let Elasticsearch do the parsing of the query string.
In your case, probably the best is to use something like luqum to parse the query, modify the abstract query and then send it to elasticsearch.
Last, can I ask you to send your questions to https://github.com/inveniosoftware/troubleshooting/issues instead? We prefer keeping issues on each repository to only bugs etc. Questions we prefer having a central place. See also https://invenio.readthedocs.io/en/latest/community/getting-help.html
The solution you provided by overriding the search_factory_imp
works for me. Thank you for the solution. I will post my queries in the places you mentioned above. Again thanks a lot.
Is it possible to modify the
querystring
from the flask api? For example if the incoming request ishttp://localhost:5001/records/?q=abc%20cde
I want to update thequerystring
value from "abc cde" to "*abc* *cde*"