Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include primary tag name in search and sort #4606

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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