include primary tag name in search and sort (#4606)

This commit is contained in:
dogwithakeyboard 2024-02-22 00:18:29 +00:00 committed by GitHub
parent 61bd9233b2
commit c4a91d15a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 10 deletions

View File

@ -299,7 +299,8 @@ func (qb *SceneMarkerStore) makeQuery(ctx context.Context, sceneMarkerFilter *mo
distinctIDs(&query, sceneMarkerTable) distinctIDs(&query, sceneMarkerTable)
if q := findFilter.Q; q != nil && *q != "" { if q := findFilter.Q; q != nil && *q != "" {
searchColumns := []string{"scene_markers.title", "scenes.title"} query.join(tagTable, "", "scene_markers.primary_tag_id = tags.id")
searchColumns := []string{"scene_markers.title", "scenes.title", "tags.name"}
query.parseQueryString(searchColumns, *q) query.parseQueryString(searchColumns, *q)
} }
@ -309,7 +310,8 @@ func (qb *SceneMarkerStore) makeQuery(ctx context.Context, sceneMarkerFilter *mo
return nil, err return nil, err
} }
query.sortAndPagination = qb.getSceneMarkerSort(&query, findFilter) + getPagination(findFilter) qb.setSceneMarkerSort(&query, findFilter)
query.sortAndPagination += getPagination(findFilter)
return &query, nil return &query, nil
} }
@ -471,19 +473,23 @@ func sceneMarkerPerformersCriterionHandler(qb *SceneMarkerStore, performers *mod
} }
} }
func (qb *SceneMarkerStore) getSceneMarkerSort(query *queryBuilder, findFilter *models.FindFilterType) string { func (qb *SceneMarkerStore) setSceneMarkerSort(query *queryBuilder, findFilter *models.FindFilterType) {
sort := findFilter.GetSort("title") sort := findFilter.GetSort("title")
direction := findFilter.GetDirection() direction := findFilter.GetDirection()
tableName := "scene_markers"
if sort == "scenes_updated_at" { switch sort {
// ensure scene table is joined case "scenes_updated_at":
query.join(sceneTable, "", "scenes.id = scene_markers.scene_id")
sort = "updated_at" sort = "updated_at"
tableName = "scenes" query.join(sceneTable, "", "scenes.id = scene_markers.scene_id")
query.sortAndPagination += getSort(sort, direction, sceneTable)
case "title":
query.join(tagTable, "", "scene_markers.primary_tag_id = tags.id")
query.sortAndPagination += " ORDER BY COALESCE(NULLIF(scene_markers.title,''), tags.name) COLLATE NATURAL_CI " + direction
default:
query.sortAndPagination += getSort(sort, direction, sceneMarkerTable)
} }
additional := ", scene_markers.scene_id ASC, scene_markers.seconds ASC" query.sortAndPagination += ", scene_markers.scene_id ASC, scene_markers.seconds ASC"
return getSort(sort, direction, tableName) + additional
} }
func (qb *SceneMarkerStore) querySceneMarkers(ctx context.Context, query string, args []interface{}) ([]*models.SceneMarker, error) { func (qb *SceneMarkerStore) querySceneMarkers(ctx context.Context, query string, args []interface{}) ([]*models.SceneMarker, error) {