Skip to content

Commit

Permalink
🎨 Make search consistent with the lamindb implementation (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
Koncopd authored Nov 22, 2024
1 parent fd45401 commit 17c124b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# bionty data
data/
sources/
versions/

# macOS
.DS_Store
.AppleDouble
Expand Down
29 changes: 15 additions & 14 deletions bionty/base/_public_ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,24 +561,18 @@ def search(
self,
string: str,
*,
field: PublicOntologyField | str | None = None,
field: PublicOntologyField | str | list[PublicOntologyField | str] = None,
limit: int | None = None,
case_sensitive: bool = False,
synonyms_field: PublicOntologyField | str | None = "synonyms",
):
"""Search a given string against a PublicOntology field.
"""Search a given string against a PublicOntology field or fields.
Args:
string: The input string to match against the field values.
field: The PublicOntologyField of the ontology the input string is matching against.
top_hit: Return all entries ranked by matching ratios.
If True, only return the top match.
Defaults to False.
limit: Maximum amount of top results to return.
If None, return all results.
Defaults to None.
field: The PublicOntologyField or several fileds of the ontology
the input string is matching against. Search all fields containing strings by default.
limit: Maximum amount of top results to return. If None, return all results.
case_sensitive: Whether the match is case sensitive.
synonyms_field: By default also search against the synonyms (If None, skips search).
Returns:
Ranked search results.
Expand All @@ -590,14 +584,21 @@ def search(
"""
from lamin_utils._search import search

return search(
if isinstance(field, PublicOntologyField):
field = field.name
elif field is not None and not isinstance(field, str):
field = [f.name if isinstance(f, PublicOntologyField) else f for f in field]

result = search(
df=self._df,
string=string,
field=self._get_default_field(field),
field=field,
limit=limit,
case_sensitive=case_sensitive,
synonyms_field=str(synonyms_field),
)
if "ontology_id" in result.columns:
result = result.set_index("ontology_id")
return result

def diff(
self, compare_to: PublicOntology, **kwargs
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ classifiers = [
dependencies = [
"lamindb",
"lamindb_setup>=0.77.6",
"lamin_utils>=0.13.9",
"filelock",
"requests",
"pyyaml",
Expand Down

0 comments on commit 17c124b

Please sign in to comment.