Skip to content
GitLab
Menu
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
4c996aec
Commit
4c996aec
authored
Mar 26, 2018
by
Pablo Panero
Browse files
Add ES central service index prefix handling
parent
643c3bac
Changes
2
Hide whitespace changes
Inline
Side-by-side
cern_search_rest/config.py
View file @
4c996aec
...
...
@@ -16,6 +16,10 @@ def _(x):
"""Identity function used to trigger string extraction."""
return
x
# CERN Search
# ===========
CERN_SEARCH_DEFAULT_INDEX_PREFIX
=
'cern_search'
CERN_SEARCH_INDEX_PREFIX
=
'cern_search'
# OAuth Client
# ============
...
...
cern_search_rest/modules/records/utils.py
View file @
4c996aec
...
...
@@ -4,8 +4,40 @@
"""Helper methods for CERN Search records."""
from
flask
import
g
from
flask
import
current_app
from
invenio_search
import
current_search
from
invenio_search.utils
import
schema_to_index
INDEX_PREFIX
=
current_app
.
config
[
'CERN_SEARCH_DEFAULT_INDEX_PREFIX'
]
def
get_user_provides
():
"""Extract the user's provides from g."""
return
[
need
.
value
for
need
in
g
.
identity
.
provides
]
\ No newline at end of file
return
[
need
.
value
for
need
in
g
.
identity
.
provides
]
def
default_record_to_index
(
record
):
"""Get index/doc_type given a record.
It tries to extract from `record['$schema']` the index and doc_type,
the index has `CERN_SEARCH_INDEX_PREFIX` as prefix or `CERN_SEARCH_DEFAULT_INDEX_PREFIX`
if it is not set up to be able to use the ES central service.
If it fails, return the default values. In this case the prefix is the default value.
:param record: The record object.
:returns: Tuple (index, doc_type).
"""
index_names
=
current_search
.
mappings
.
keys
()
schema
=
record
.
get
(
'$schema'
,
''
)
if
isinstance
(
schema
,
dict
):
schema
=
schema
.
get
(
'$ref'
,
''
)
aux
=
current_app
.
config
[
'CERN_SEARCH_INDEX_PREFIX'
]
if
aux
:
INDEX_PREFIX
=
aux
index
,
doc_type
=
schema_to_index
(
schema
,
index_names
=
index_names
)
if
index
and
doc_type
:
return
'{0}{1}'
.
format
(
INDEX_PREFIX
,
index
),
doc_type
else
:
return
(
'{0}{1}'
.
format
(
current_app
.
config
[
'CERN_SEARCH_DEFAULT_INDEX_PREFIX'
],
current_app
.
config
[
'INDEXER_DEFAULT_INDEX'
]),
current_app
.
config
[
'INDEXER_DEFAULT_DOC_TYPE'
])
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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