Skip to content

Commit

Permalink
include primary tag name in search and sort (#4606)
Browse files Browse the repository at this point in the history
  • Loading branch information
dogwithakeyboard committed Feb 22, 2024
1 parent 61bd923 commit c4a91d1
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions pkg/sqlite/scene_marker.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ func (qb *SceneMarkerStore) makeQuery(ctx context.Context, sceneMarkerFilter *mo
distinctIDs(&query, sceneMarkerTable)

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)
}

Expand All @@ -309,7 +310,8 @@ func (qb *SceneMarkerStore) makeQuery(ctx context.Context, sceneMarkerFilter *mo
return nil, err
}

query.sortAndPagination = qb.getSceneMarkerSort(&query, findFilter) + getPagination(findFilter)
qb.setSceneMarkerSort(&query, findFilter)
query.sortAndPagination += getPagination(findFilter)

return &query, nil
}
Expand Down Expand Up @@ -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")
direction := findFilter.GetDirection()
tableName := "scene_markers"
if sort == "scenes_updated_at" {
// ensure scene table is joined
query.join(sceneTable, "", "scenes.id = scene_markers.scene_id")

switch sort {
case "scenes_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"
return getSort(sort, direction, tableName) + additional
query.sortAndPagination += ", scene_markers.scene_id ASC, scene_markers.seconds ASC"
}

func (qb *SceneMarkerStore) querySceneMarkers(ctx context.Context, query string, args []interface{}) ([]*models.SceneMarker, error) {
Expand Down

0 comments on commit c4a91d1

Please sign in to comment.