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

Filter scenes & images by filename/basename #5526

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions graphql/schema/types/filters.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ input SceneFilterType {
phash_distance: PhashDistanceCriterionInput
"Filter by path"
path: StringCriterionInput
"Filter by filename/basename"
filename: StringCriterionInput
"Filter by file count"
file_count: IntCriterionInput
# rating expressed as 1-100
Expand Down Expand Up @@ -613,6 +615,8 @@ input ImageFilterType {
checksum: StringCriterionInput
"Filter by path"
path: StringCriterionInput
"Filter by filename/basename"
filename: StringCriterionInput
"Filter by file count"
file_count: IntCriterionInput
# rating expressed as 1-100
Expand Down
2 changes: 2 additions & 0 deletions pkg/models/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ type ImageFilterType struct {
Checksum *StringCriterionInput `json:"checksum"`
// Filter by path
Path *StringCriterionInput `json:"path"`
// Filter by filename/basename
Filename *StringCriterionInput `json:"filename"`
// Filter by file count
FileCount *IntCriterionInput `json:"file_count"`
// Filter by rating expressed as 1-100
Expand Down
2 changes: 2 additions & 0 deletions pkg/models/scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type SceneFilterType struct {
PhashDistance *PhashDistanceCriterionInput `json:"phash_distance"`
// Filter by path
Path *StringCriterionInput `json:"path"`
// Filter by filename/basename
Filename *StringCriterionInput `json:"filename"`
// Filter by file count
FileCount *IntCriterionInput `json:"file_count"`
// Filter by rating expressed as 1-100
Expand Down
11 changes: 11 additions & 0 deletions pkg/sqlite/criterion_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ func enumCriterionHandler(modifier models.CriterionModifier, values []string, co
}
}

func filenameCriterionHandler(c *models.StringCriterionInput, basenameColumn string, addJoinFn func(f *filterBuilder)) criterionHandlerFunc {
return func(ctx context.Context, f *filterBuilder) {
if c != nil {
if addJoinFn != nil {
addJoinFn(f)
}
stringCriterionHandler(c, basenameColumn)(ctx, f)
}
}
}

func pathCriterionHandler(c *models.StringCriterionInput, pathColumn string, basenameColumn string, addJoinFn func(f *filterBuilder)) criterionHandlerFunc {
return func(ctx context.Context, f *filterBuilder) {
if c != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/sqlite/image_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func (qb *imageFilterHandler) criterionHandler() criterionHandler {
stringCriterionHandler(imageFilter.Photographer, "images.photographer"),

pathCriterionHandler(imageFilter.Path, "folders.path", "files.basename", imageRepository.addFoldersTable),
filenameCriterionHandler(imageFilter.Filename, "files.basename", imageRepository.addImagesFilesTable),
qb.fileCountCriterionHandler(imageFilter.FileCount),
intCriterionHandler(imageFilter.Rating100, "images.rating", nil),
intCriterionHandler(imageFilter.OCounter, "images.o_counter", nil),
Expand Down
5 changes: 3 additions & 2 deletions pkg/sqlite/scene_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func (qb *sceneFilterHandler) criterionHandler() criterionHandler {
return compoundHandler{
intCriterionHandler(sceneFilter.ID, "scenes.id", nil),
pathCriterionHandler(sceneFilter.Path, "folders.path", "files.basename", qb.addFoldersTable),
filenameCriterionHandler(sceneFilter.Filename, "files.basename", qb.addFilesTable),
qb.fileCountCriterionHandler(sceneFilter.FileCount),
stringCriterionHandler(sceneFilter.Title, "scenes.title"),
stringCriterionHandler(sceneFilter.Code, "scenes.code"),
Expand Down Expand Up @@ -383,8 +384,8 @@ func (qb *sceneFilterHandler) captionCriterionHandler(captions *models.StringCri
},
excludeHandler: func(f *filterBuilder, criterion *models.StringCriterionInput) {
excludeClause := `scenes.id NOT IN (
SELECT scenes_files.scene_id from scenes_files
INNER JOIN video_captions on video_captions.file_id = scenes_files.file_id
SELECT scenes_files.scene_id from scenes_files
INNER JOIN video_captions on video_captions.file_id = scenes_files.file_id
WHERE video_captions.language_code LIKE ?
)`
f.addWhere(excludeClause, criterion.Value)
Expand Down
4 changes: 4 additions & 0 deletions ui/v2.5/src/models/list-filter/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ const criterionOptions = [
createStringCriterionOption("photographer"),
createMandatoryStringCriterionOption("checksum", "media_info.checksum"),
PathCriterionOption,
createStringCriterionOption(
"filename",
"component_tagger.config.query_mode_filename"
),
GalleriesCriterionOption,
OrganizedCriterionOption,
createMandatoryNumberCriterionOption("o_counter", "o_count"),
Expand Down
4 changes: 4 additions & 0 deletions ui/v2.5/src/models/list-filter/scenes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ const criterionOptions = [
createStringCriterionOption("title"),
createStringCriterionOption("code", "scene_code"),
PathCriterionOption,
createStringCriterionOption(
"filename",
"component_tagger.config.query_mode_filename"
),
createStringCriterionOption("details"),
createStringCriterionOption("director"),
createMandatoryStringCriterionOption("oshash", "media_info.hash"),
Expand Down
1 change: 1 addition & 0 deletions ui/v2.5/src/models/list-filter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export interface IOptionType {

export type CriterionType =
| "path"
| "filename"
| "rating100"
| "organized"
| "o_counter"
Expand Down
Loading