Commit 4d59e04c authored by David Mendez's avatar David Mendez
Browse files

EUbOPEN autocomplete: include name onf highlighted field in response.

parent 7207a657
......@@ -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
......@@ -54,6 +54,10 @@ chembl_molecule:
label: 'Molecular Formula'
label: 'Smiles'
label: 'Inchi'
label: 'Inchi Key'
based_on: 'molecule_chembl_id'
label: 'Parent Molecule'
......@@ -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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment