-
Notifications
You must be signed in to change notification settings - Fork 3
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
ENH: Augment search methods #79
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4d1a9fa
MNT: refactor FilestoreBackend.search
shilorigins 847e8b8
ENH: implement and integrate SearchTerm
shilorigins a84c010
ENH: add 'like_with_tols' search operator
shilorigins fc07479
TST: add working tag search test
shilorigins bded804
DOC: pre-release notes
shilorigins 4424438
MNT: support calling Client.search with bare tuples
shilorigins c472661
MNT: raise errors if SearchTerm receives unsupported op or arg type
shilorigins 55ee758
MNT: rename 'like_with_tols' to 'isclose'
shilorigins a276aaf
MNT: type hint SearchTerm and search method parameters
shilorigins 4e749df
MNT: support searching UUIDs with 'like' operator
shilorigins f73ef72
BUG: make collection builder page use SearchTerm
shilorigins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
docs/source/upcoming_release_notes/79-augment_search_methods.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
79 augment search methods | ||
################# | ||
|
||
API Breaks | ||
---------- | ||
- Client.search takes SearchTerms as *args rather than key-value pairs as **kwargs | ||
|
||
Features | ||
-------- | ||
- regex search on Entry text fields | ||
- filter Entrys by tag | ||
- filter Entrys by attribute value | ||
|
||
Bugfixes | ||
-------- | ||
- N/A | ||
|
||
Maintenance | ||
----------- | ||
- N/A | ||
|
||
Contributors | ||
------------ | ||
- shilorigins |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
from enum import Flag, auto | ||
from uuid import UUID | ||
|
||
import pytest | ||
|
||
from superscore.backends.core import _Backend | ||
from superscore.backends.core import SearchTerm, _Backend | ||
from superscore.errors import (BackendError, EntryExistsError, | ||
EntryNotFoundError) | ||
from superscore.model import Collection, Parameter, Snapshot | ||
|
@@ -73,42 +74,118 @@ def test_delete_entry(backends: _Backend): | |
def test_search_entry(backends: _Backend): | ||
# Given an entry we know is in the backend | ||
results = backends.search( | ||
description='collection 1 defining some motor fields' | ||
SearchTerm('description', 'eq', 'collection 1 defining some motor fields') | ||
) | ||
assert len(list(results)) == 1 | ||
# Search by field name | ||
results = backends.search( | ||
uuid=UUID('ffd668d3-57d9-404e-8366-0778af7aee61') | ||
SearchTerm('uuid', 'eq', UUID('ffd668d3-57d9-404e-8366-0778af7aee61')) | ||
) | ||
assert len(list(results)) == 1 | ||
# Search by field name | ||
results = backends.search(data=2) | ||
results = backends.search( | ||
SearchTerm('data', 'eq', 2) | ||
) | ||
assert len(list(results)) == 3 | ||
# Search by field name | ||
results = backends.search( | ||
uuid=UUID('ecb42cdb-b703-4562-86e1-45bd67a2ab1a'), data=2 | ||
SearchTerm('uuid', 'eq', UUID('ecb42cdb-b703-4562-86e1-45bd67a2ab1a')), | ||
tangkong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
SearchTerm('data', 'eq', 2) | ||
) | ||
assert len(list(results)) == 1 | ||
|
||
results = backends.search(entry_type=Snapshot,) | ||
results = backends.search( | ||
SearchTerm('entry_type', 'eq', Snapshot) | ||
) | ||
assert len(list(results)) == 1 | ||
|
||
results = backends.search(entry_type=(Snapshot, Collection)) | ||
results = backends.search( | ||
SearchTerm('entry_type', 'in', (Snapshot, Collection)) | ||
) | ||
assert len(list(results)) == 2 | ||
|
||
results = backends.search( | ||
SearchTerm('data', 'lt', 3) | ||
) | ||
assert len(list(results)) == 3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something I hadn't considered in the previous PRs: would it add value to check that the results match the searches in the test suite? Or is this not worth the effort? I'm not sure but I thought I'd mention it.
|
||
|
||
results = backends.search( | ||
SearchTerm('data', 'gt', 3) | ||
) | ||
assert len(list(results)) == 1 | ||
|
||
|
||
@pytest.mark.parametrize('backends', [0], indirect=True) | ||
def test_fuzzy_search(backends: _Backend): | ||
results = list(backends.search( | ||
SearchTerm('description', 'like', 'motor')) | ||
) | ||
assert len(results) == 4 | ||
|
||
results = list(backends.search( | ||
SearchTerm('description', 'like', 'motor field (?!PREC)')) | ||
) | ||
assert len(results) == 2 | ||
|
||
results = list(backends.search( | ||
SearchTerm('uuid', 'like', '17cc6ebf')) | ||
) | ||
assert len(results) == 1 | ||
|
||
|
||
@pytest.mark.parametrize('backends', [0], indirect=True) | ||
def test_tag_search(backends: _Backend): | ||
results = list(backends.search( | ||
SearchTerm('tags', 'gt', set()) | ||
)) | ||
assert len(results) == 2 # only the Collection and Snapshot have .tags | ||
|
||
class Tag(Flag): | ||
T1 = auto() | ||
T2 = auto() | ||
|
||
results[0].tags = {Tag.T1} | ||
results[1].tags = {Tag.T1, Tag.T2} | ||
backends.update_entry(results[0]) | ||
backends.update_entry(results[1]) | ||
|
||
results = list(backends.search( | ||
SearchTerm('tags', 'gt', {Tag.T1}) | ||
)) | ||
assert len(results) == 2 | ||
|
||
results = list(backends.search( | ||
SearchTerm('tags', 'gt', {Tag.T1, Tag.T2}) | ||
)) | ||
assert len(results) == 1 | ||
|
||
|
||
@pytest.mark.parametrize('backends', [0], indirect=True) | ||
def test_search_error(backends: _Backend): | ||
with pytest.raises(TypeError): | ||
results = backends.search( | ||
SearchTerm('data', 'like', 5) | ||
) | ||
list(results) | ||
with pytest.raises(ValueError): | ||
results = backends.search( | ||
SearchTerm('data', 'near', 5) | ||
) | ||
list(results) | ||
|
||
|
||
@pytest.mark.parametrize('backends', [0], indirect=True) | ||
def test_update_entry(backends: _Backend): | ||
# grab an entry from the database and modify it. | ||
entry = list(backends.search( | ||
description='collection 1 defining some motor fields' | ||
SearchTerm('description', 'eq', 'collection 1 defining some motor fields') | ||
))[0] | ||
old_uuid = entry.uuid | ||
|
||
entry.description = 'new_description' | ||
backends.update_entry(entry) | ||
new_entry = list(backends.search( | ||
description='new_description' | ||
SearchTerm('description', 'eq', 'new_description') | ||
))[0] | ||
new_uuid = new_entry.uuid | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The github diff rendered part of this as italics... strange
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It behaves weird with my vim highlighting too. Maybe the double
**
is a parsing edge case?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It renders funny in sphinx too, the
*
ends up being a hyperlink to an id anchor? This is something we can fix up when we actually publish release notes thoughThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Later we can add backticks around these to force them to be literals