fix: Fix searching A AND A returning no results#1138
Merged
CyanVoxel merged 1 commit intoTagStudioDev:mainfrom Oct 8, 2025
Merged
fix: Fix searching A AND A returning no results#1138CyanVoxel merged 1 commit intoTagStudioDev:mainfrom
A AND A returning no results#1138CyanVoxel merged 1 commit intoTagStudioDev:mainfrom
Conversation
…f a list to prevent duplicate tag IDs
Computerdores
approved these changes
Sep 24, 2025
Member
|
Thank you for your work on this! |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.pyto, rather than a list, use a set for collecting the tag IDs of each term of an ASTANDListandORListto 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
ANDLists containing two of the same tag, anyANDListcontaining 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