Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ChEMBL
C
ChEMBL
Main Web Interface
Elasticsearch Proxy API
Commits
4d59e04c
Commit
4d59e04c
authored
Sep 28, 2021
by
David Mendez
Browse files
EUbOPEN autocomplete: include name onf highlighted field in response.
parent
7207a657
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
6 deletions
+42
-6
app/eubopen/search/suggestions/suggestions.py
app/eubopen/search/suggestions/suggestions.py
+35
-4
app/properties_configuration/config/override.yml
app/properties_configuration/config/override.yml
+4
-0
app/properties_configuration/properties_configuration_manager.py
...perties_configuration/properties_configuration_manager.py
+3
-2
No files found.
app/eubopen/search/suggestions/suggestions.py
View file @
4d59e04c
...
...
@@ -3,6 +3,8 @@ Module with the functions to generate suggestions for eubopen
"""
from
app.es_data
import
es_data
from
app.config
import
RUN_CONFIG
from
utils
import
dict_property_access
from
app.properties_configuration
import
properties_configuration_manager
def
get_suggestions_for_term
(
term
):
...
...
@@ -48,17 +50,46 @@ def get_suggestions(term, entity_config):
raw_text_suggestions
=
es_data
.
get_es_response
(
index_name
,
suggestion_query
)
raw_options
=
raw_text_suggestions
[
"suggest"
][
"autocomplete"
][
0
][
"options"
]
options
=
[
parse_option
(
option
)
for
option
in
raw_options
]
options
=
[
parse_option
(
option
,
entity_config
)
for
option
in
raw_options
]
return
options
def
parse_option
(
raw_option
):
def
parse_option
(
raw_option
,
entity_config
):
"""
:param raw_option: raw option to parse
:param entity_config: configuration of the entity autocomplete
:return: a simplified version of the suggestion.
"""
label_property
=
entity_config
[
'label_property'
]
highlight_properties
=
entity_config
[
'highlight_properties'
]
text
=
raw_option
[
'text'
]
highlighted_property_label
=
None
highlighted_property_path
=
get_highlighted_property
(
raw_option
[
'_source'
],
highlight_properties
,
text
)
if
highlighted_property_path
is
not
None
:
index_name
=
entity_config
[
'index_name'
]
props_config_instance
=
properties_configuration_manager
.
get_property_configuration_instance
()
highlighted_property_config
=
props_config_instance
.
get_config_for_prop
(
index_name
,
highlighted_property_path
)
highlighted_property_label
=
highlighted_property_config
[
'label'
]
return
{
'_id'
:
raw_option
[
'_id'
],
'item_label'
:
raw_option
[
'_source'
].
get
(
'pref_name'
),
'text'
:
raw_option
[
'text'
]
'item_label'
:
dict_property_access
.
get_property_value
(
raw_option
,
f
'_source.
{
label_property
}
'
),
'text'
:
text
,
'highlighted_property'
:
highlighted_property_label
}
def
get_highlighted_property
(
doc_source
,
highlight_properties
,
text
):
"""
:param doc_source: source for the document to check
:param highlight_properties: list of the properties that are candidates for highlighting
:param text: text matched
"""
for
property_path
in
highlight_properties
:
value
=
str
(
dict_property_access
.
get_property_value
(
doc_source
,
property_path
))
if
text
in
value
:
return
property_path
return
None
app/properties_configuration/config/override.yml
View file @
4d59e04c
...
...
@@ -54,6 +54,10 @@ chembl_molecule:
label
:
'
Molecular
Formula'
'
molecule_structures.canonical_smiles'
:
label
:
'
Smiles'
'
molecule_structures.standard_inchi'
:
label
:
'
Inchi'
'
molecule_structures.standard_inchi_key'
:
label
:
'
Inchi
Key'
'
drug_parent_molecule_chembl_id'
:
based_on
:
'
molecule_chembl_id'
label
:
'
Parent
Molecule'
...
...
app/properties_configuration/properties_configuration_manager.py
View file @
4d59e04c
...
...
@@ -166,8 +166,8 @@ class PropertyConfiguration:
"""
if
property_override_description
.
get
(
'aggregatable'
)
is
None
or
\
property_override_description
.
get
(
'type'
)
is
None
or
\
property_override_description
.
get
(
'sortable'
)
is
None
:
property_override_description
.
get
(
'type'
)
is
None
or
\
property_override_description
.
get
(
'sortable'
)
is
None
:
raise
self
.
PropertiesConfigurationManagerError
(
f
'A virtual contextual property must define the type and if it is '
'aggregatable and sortable. index => {index_name} : prop => {prop_id}'
...
...
@@ -179,6 +179,7 @@ class PropertyConfiguration:
'is_contextual'
:
True
,
}
def
get_property_configuration_instance
():
"""
:return: a default instance for the property configuration
...
...
Write
Preview
Markdown
is supported
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