Skip to content

Commit

Permalink
search: possibility to specify a different query_parser
Browse files Browse the repository at this point in the history
  • Loading branch information
psaiz committed Dec 1, 2023
1 parent 945a870 commit afc3b52
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion invenio_records_rest/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ def create_url_rules(
links_factory_imp=None,
suggesters=None,
default_endpoint_prefix=None,
search_query_parser=None,
):
"""Create Werkzeug URL rules.
Expand Down Expand Up @@ -254,6 +255,7 @@ def create_url_rules(
:param search_factory_imp: Factory to parse queries.
:param links_factory_imp: Factory for record links generation.
:param suggesters: Suggester fields configuration.
:param search_query_parser: Function that implements the query parser
:returns: a list of dictionaries with can each be passed as keywords
arguments to ``Blueprint.add_url_rule``.
Expand Down Expand Up @@ -325,6 +327,7 @@ def links_factory(pid, record=None, **kwargs):
),
item_links_factory=links_factory,
record_class=record_class,
search_query_parser=search_query_parser,
)
item_view = RecordResource.as_view(
RecordResource.view_name.format(endpoint),
Expand Down Expand Up @@ -591,6 +594,7 @@ def __init__(
item_links_factory=None,
record_class=None,
indexer_class=None,
search_query_parser=None,
**kwargs
):
"""Constructor."""
Expand Down Expand Up @@ -623,6 +627,7 @@ def __init__(
self.loaders = record_loaders or current_records_rest.loaders
self.record_class = record_class or Record
self.indexer_class = indexer_class
self.query_parser = search_query_parser

@need_record_permission("list_permission_factory")
@use_paginate_args(
Expand All @@ -647,7 +652,7 @@ def get(self, pagination=None, **kwargs):
search = search[pagination["from_idx"] : pagination["to_idx"]]
search = search.extra(track_total_hits=True)

search, qs_kwargs = self.search_factory(search)
search, qs_kwargs = self.search_factory(search, self.search_query_parser)
urlkwargs.update(qs_kwargs)

# Execute search
Expand Down

0 comments on commit afc3b52

Please sign in to comment.