Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎨 Make search consistent with the lamindb implementation #170

Merged
merged 5 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading