-
-
Notifications
You must be signed in to change notification settings - Fork 394
Add search by metadata #284
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
Conversation
dc3c668
to
576278f
Compare
cherry-piked commit with tests # at TagStudio/tagstudio
> ruff check --config ../pyproject.toml src/core/library.py
All checks passed!
> ruff check --config ../pyproject.toml tests/core/
All checks passed! PR is ready for review |
@lunaro-4 can you please rebase your branch? There are some changes which are already merged in also fix the formatting in your code, so the |
Add casefolding to Library.parse_metadata output Add handling of entity.fields with empty dicts to Filter.remap_fields
…brary class to Filter
Words with capital letters in text fields cannot be searched. If the description is I assume this bug applies to the Title, Author, Artist, URL, Description, and Notes fields, though I did not check them all. |
A
|
… "empty" to a variable from mentioned class
nitpicks; switch `lower()` to `casefold()` in `filter_results` method; simplify return in `SearchMode.AND` case; DRYed `preprocess_tag_terms` method;
Sorry for not adressing this before. |
Thank you for pointing things out, will fix and add additional tests |
…negative prompt related to comment TagStudioDev#284 (comment)
…negative prompt related to comment TagStudioDev#284 (comment)
Changes overview:
I also had to change search test from Thank you for patience, will be waiting for new review. |
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 is to complex and nested for me to understand what it does. Im happy to approve it once I have had time to understand this PR. @lunaro-4 if you want to explain it to me I can give it another shot later.
# FILENAME_KEYNAME = "filename" | ||
# TAG_ID_KEYNAME = "tag_id" |
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.
Unused attributes can be deleted.
@eivl At first, there was only one Reading the query
Query keys that do not have values added to the 'unbound' dictionary key (name set in
Filtering the entries
It iterates over list elements ( If the entry does not break loop, it is considerate valid for query and is added to list The The
|
I see a merge conflict, and will try to resolve it this weekend I also would like to hear some tips to make code more readable. For me, this level of nesting is more or less comfortable and I do not know what to do with UPDATE: after further inspection, since the project moved to SQL, I will need a significant amount of work to adapt my changes to new structure, so I will not be able to finish the PR this weekend |
Context
Related to issue #272
Features / Changes
Usage example
In a new version, specifying all tags with whitespace as usual will return result
from AND search type, regardless of one selected in UI:
tag1 tag2
- return all entries, tagged with 'tag1' AND 'tag2'If you want to use OR, you need to specify OR search type in UI, and
provide tags, separated by '|' symbol
tag1 | tag2
- (with OR search type) return all entries, tagged with 'tag1' OR 'tag2'tag1 tag2 | tag3
- (with OR search type) return all entries, tagged with 'tag1' and 'tag2' OR with 'tag3'Search by non-tag metadata is also available by 'key: value' syntax:
description: desc
- return all entries, which description contains 'desc'tag1 ; description: desc
- return all entries, tagged with 'tag1' AND which description contains 'desc'description: desc | description: smth
:Negative query can be set by specifying lookup value as 'null':
tag1; description: null
- return all entries, tagged with 'tag1' and not having a description (or having a null description)Original negative query tags like
empty
orno author
also supported:no author tag1; description: desc
- return all entries without author, tagged with 'tag1' and description containing 'desc'Refactoring note
For ease of maintenance, many functions of original code were extracted to new methods in library.Library class.
To avoid clutter, I extracted them even further to a new class 'library.Filter'. This should help maintain the codebase
in future, but due to lack of tests, I decided to extract to 'Filter' only new methods, and import any required variables
and methods, to aviod breaking other functionality of 'library.Library' class:
This class was added in last commit, so this can be reverted with ease.
Other possible side effects
Changed code works fine at a first glance, but it is not clear for me how exactly
original code worked on some edge cases, especially with coalitions.
I can write tests for it, but I would like to have test cases, for deeper understanding on how should it work