Skip to content

Commit

Permalink
fixed naked nsarg species bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wshayes committed Nov 13, 2020
1 parent cb74880 commit 783b04b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
16 changes: 11 additions & 5 deletions bel/resources/namespace.py
Expand Up @@ -218,9 +218,9 @@ def terms_iterator_for_arangodb(f: IO, version: str):
term_key = term["key"]
namespace = term["namespace"]

species_id = term.get("species_id", None)
# Skip if species not listed in species_list
if species_list and species_id and species_id not in species_list:
# Skip if species not listed in config species_list
species_key = term.get("species_key", None)
if species_list and species_key and species_key not in species_list:
continue

# Can't use original key formatted for Arangodb as some keys are longer than allowed (_key < 255 chars)
Expand Down Expand Up @@ -346,8 +346,8 @@ def terms_iterator_for_elasticsearch(f: IO, index_name: str, statistics: dict):
ns, id_ = equivalence.split(":", 1)
statistics["equivalenced_namespaces"][ns] += 1

# Filter species if enabled in config
species_key = term.get("species_key", "")
# Skip if species not listed in config species_list
species_key = term.get("species_key", None)
if species_list and species_key and species_key not in species_list:
continue

Expand All @@ -362,6 +362,12 @@ def terms_iterator_for_elasticsearch(f: IO, index_name: str, statistics: dict):
term.pop("parent_keys", "")
term.pop("equivalence_keys", "")

# Must not have species_key attribute to allow naked NSArg queries with filtered species
# but allow non-species terms to be matched as well
if term.get("species_key", "") == "":
term.pop("species_key")
term.pop("species_label")

record = {
"_op_type": "index",
"_index": index_name,
Expand Down
9 changes: 5 additions & 4 deletions bel/terms/terms.py
Expand Up @@ -338,11 +338,12 @@ def get_term_completions(
if entity_types:
grp = [et for et in entity_types if et in settings.species_entity_types]

if grp and species_keys:
if isinstance(species_keys, str):
species_keys = [species_keys]
if isinstance(species_keys, str):
species_keys = [species_keys]

# Allow non-species specific terms to be found
# Allow non-species specific terms to be found along with species=[species_keys]
# grp is set if inside a function and if not entity_types and annotation_types are None
if species_keys and (grp or (not entity_types and not annotation_types)):
filters.append(
{
"bool": {
Expand Down

0 comments on commit 783b04b

Please sign in to comment.