Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
webservices
cern-search
cern-search-rest-api
Commits
28e87a43
Commit
28e87a43
authored
Feb 22, 2019
by
Pablo Panero
Browse files
search: add custom query parser to specify search field
parent
263b135f
Changes
2
Hide whitespace changes
Inline
Side-by-side
cern_search_rest_api/config.py
View file @
28e87a43
...
...
@@ -103,6 +103,7 @@ RECORDS_REST_ENDPOINTS = dict(
'application/json'
:
(
'invenio_records_rest.serializers'
':json_v1_search'
),
},
search_factory_imp
=
'cern_search_rest_api.modules.cernsearch.search.csas_search_factory'
,
max_result_window
=
10000
,
read_permission_factory_imp
=
record_read_permission_factory
,
list_permission_factory_imp
=
record_list_permission_factory
,
...
...
cern_search_rest_api/modules/cernsearch/search.py
View file @
28e87a43
...
...
@@ -8,6 +8,7 @@
# or submit itself to any jurisdiction.
from
elasticsearch_dsl
import
Q
from
invenio_records_rest.query
import
default_search_factory
from
invenio_search
import
RecordsSearch
from
invenio_search.api
import
DefaultFilter
from
flask
import
request
,
current_app
...
...
@@ -75,6 +76,20 @@ def get_egroups():
return
get_user_provides
()
def
search_factory
(
self
,
search
,
query_parser
=
None
):
def
_csas_query_parser
(
qstr
=
None
):
"""Default parser that uses the Q() from elasticsearch_dsl."""
if
qstr
:
return
Q
(
'query_string'
,
query
=
qstr
,
default_field
=
'_search_all'
)
return
Q
()
return
default_search_factory
(
self
,
search
,
_csas_query_parser
)
csas_search_factory
=
search_factory
class
RecordCERNSearch
(
RecordsSearch
):
"""CERN search class."""
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment