Filter tag by hierarchy (#1746)

* Add API support for filtering tags by parent / children
* Add parent & child tags filters for tags to UI
* Add API support for filtering tags by parent / child count
* Add parent & child count filters for tags to UI
* Update db generator
* Add missing build tag
* Add unit tests

Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
gitgiggety
2021-10-01 03:50:06 +02:00
committed by GitHub
parent df2c9e9754
commit dabf5acefe
15 changed files with 515 additions and 24 deletions

View File

@@ -151,6 +151,11 @@ const (
tagIdxWithGallery
tagIdx1WithGallery
tagIdx2WithGallery
tagIdxWithChildTag
tagIdxWithParentTag
tagIdxWithGrandChild
tagIdxWithParentAndChild
tagIdxWithGrandParent
// new indexes above
// tags with dup names start from the end
tagIdx1WithDupName
@@ -345,6 +350,14 @@ var (
}
)
var (
tagParentLinks = [][2]int{
{tagIdxWithChildTag, tagIdxWithParentTag},
{tagIdxWithGrandChild, tagIdxWithParentAndChild},
{tagIdxWithParentAndChild, tagIdxWithGrandParent},
}
)
func TestMain(m *testing.M) {
ret := runTests(m)
os.Exit(ret)
@@ -499,6 +512,10 @@ func populateDB() error {
return fmt.Errorf("error linking gallery studios: %s", err.Error())
}
if err := linkTagsParent(r.Tag()); err != nil {
return fmt.Errorf("error linking tags parent: %s", err.Error())
}
if err := createMarker(r.SceneMarker(), sceneIdxWithMarker, tagIdxWithPrimaryMarker, []int{tagIdxWithMarker}); err != nil {
return fmt.Errorf("error creating scene marker: %s", err.Error())
}
@@ -865,6 +882,22 @@ func getTagPerformerCount(id int) int {
return 0
}
func getTagParentCount(id int) int {
if id == tagIDs[tagIdxWithParentTag] || id == tagIDs[tagIdxWithGrandParent] || id == tagIDs[tagIdxWithParentAndChild] {
return 1
}
return 0
}
func getTagChildCount(id int) int {
if id == tagIDs[tagIdxWithChildTag] || id == tagIDs[tagIdxWithGrandChild] || id == tagIDs[tagIdxWithParentAndChild] {
return 1
}
return 0
}
//createTags creates n tags with plain Name and o tags with camel cased NaMe included
func createTags(tqb models.TagReaderWriter, n int, o int) error {
const namePlain = "Name"
@@ -1231,6 +1264,25 @@ func linkStudiosParent(qb models.StudioWriter) error {
})
}
func linkTagsParent(qb models.TagReaderWriter) error {
return doLinks(tagParentLinks, func(parentIndex, childIndex int) error {
tagID := tagIDs[childIndex]
parentTags, err := qb.FindByChildTagID(tagID)
if err != nil {
return err
}
var parentIDs []int
for _, parentTag := range parentTags {
parentIDs = append(parentIDs, parentTag.ID)
}
parentIDs = append(parentIDs, tagIDs[parentIndex])
return qb.UpdateParentTags(tagID, parentIDs)
})
}
func addTagImage(qb models.TagWriter, tagIndex int) error {
return qb.UpdateImage(tagIDs[tagIndex], models.DefaultTagImage)
}