fix: Fix searching A AND A
returning no results
#1138
Merged
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.
Fixes searching
<Tag A> AND <Tag A>
returning no results, when it should return the same results as<Tag A>
(#951).I'm not very familiar with the backend and haven't done very in-depth testing, so please point out if this causes any unintended side effects.
Summary
Tweaked the
__separate_tags()
method insrc/tagstudio/core/library/alchemy/visitors.py
to, rather than a list, use a set for collecting the tag IDs of each term of an ASTANDList
andORList
to prevent duplicate tag IDs from being returned.Cause of Bug
The SQL query built from the search
<Tag A> AND <Tag A>
will always fail due to this section:Since it's getting rows where
count(DISTINCT tag_entries.tag_id) = 2
, but it's only searching for rows with a single tag ID,count(DISTINCT tag_entries.tag_id)
will always equal1
.This doesn't apply just to
ANDList
s containing two of the same tag, anyANDList
containing at least two duplicate tags will cause the query to fail. So a search such as<Tag A> AND <Tag B> AND <Tag A> AND <Tag A>
would also fail.However, if the duplicate tag is ambiguous, the SQL query built filters entries in a fundamentally different way that doesn't suffer the same issue, and the search acts as expected.
Tasks Completed