query

package
v0.0.39 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 27, 2026 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AggregateByDepth

func AggregateByDepth(media []models.MediaWithDB, flags models.GlobalFlags, fastMode ...bool) []models.FolderStats

func AggregateExtensions

func AggregateExtensions(media []models.MediaWithDB, fastMode ...bool) []models.FolderStats

func AggregateMedia

func AggregateMedia(media []models.MediaWithDB, flags models.GlobalFlags) []models.FolderStats

AggregateMedia media using the specified aggregation mode

func AggregateMediaWithMode added in v0.0.32

func AggregateMediaWithMode(media []models.MediaWithDB, flags models.GlobalFlags, fastMode bool) []models.FolderStats

AggregateMediaWithMode aggregates media with optional fast mode fastMode: skip expensive calculations (median, file storage) for faster navigation

func AggregateSizeBuckets

func AggregateSizeBuckets(media []models.MediaWithDB, fastMode ...bool) []models.FolderStats

func ApplyNaturalSort added in v0.0.38

func ApplyNaturalSort(media []models.MediaWithDB, fields []SortField)

ApplyNaturalSort applies natural sorting to media using the specified fields as tiebreakers

func ApplyWeightedRerank added in v0.0.38

func ApplyWeightedRerank(media []models.MediaWithDB, fields []SortField)

ApplyWeightedRerank applies MCDA-style weighted re-ranking based on field positions Fields earlier in the list have higher weights (position-based weighting)

func CompareSortFields added in v0.0.38

func CompareSortFields(media []models.MediaWithDB, i, j int, sortFields []SortField, alg string) int

CompareSortFields compares two media items using multiple sort fields

func ExpandRelatedMedia added in v0.0.30

func ExpandRelatedMedia(
	ctx context.Context,
	sqlDB *sql.DB,
	media *[]models.MediaWithDB,
	flags models.GlobalFlags,
) error

ExpandRelatedMedia expands the result set with media related to the first item based on shared search terms (title, path words) using FTS rank

func FetchDUDirectFiles added in v0.0.32

func FetchDUDirectFiles(
	ctx context.Context,
	dbPaths []string,
	pathPrefix string,
	targetDepth int,
) ([]models.MediaWithDB, error)

FetchDUDirectFiles fetches files at the target depth for DU mode

func FetchDUDirectFilesWithFilters added in v0.0.32

func FetchDUDirectFilesWithFilters(
	ctx context.Context,
	dbPaths []string,
	pathPrefix string,
	targetDepth int,
	flags models.GlobalFlags,
) ([]models.MediaWithDB, error)

FetchDUDirectFilesWithFilters fetches files at the target depth with filter support Uses two-path approach: - Fast path: no filters - direct SQL query - Filter path: applies SQL-level filters

func FetchSiblings

func FetchSiblings(
	ctx context.Context,
	media []models.MediaWithDB,
	flags models.GlobalFlags,
) ([]models.MediaWithDB, error)

FetchSiblings fetches sibling files for the given media (Re-exported for tests)

func FilterMedia

func FilterMedia(media []models.MediaWithDB, flags models.GlobalFlags) []models.MediaWithDB

FilterMedia applies all filters to media list in memory

func GetSortValueFloat64 added in v0.0.38

func GetSortValueFloat64(m models.MediaWithDB, field string) float64

GetSortValueFloat64 returns a numeric sort value for a field

func GetSortValueString added in v0.0.38

func GetSortValueString(m models.MediaWithDB, field string) string

GetSortValueString returns a string sort value for a field

func IsNumericField added in v0.0.38

func IsNumericField(field string) bool

IsNumericField checks if a field is numeric (float64) or string

func IsSearchAvailable added in v0.0.9

func IsSearchAvailable(ctx context.Context, mode SearchMode, db *sql.DB) bool

IsSearchAvailable checks if a specific search mode is available

func MediaQuery

func MediaQuery(ctx context.Context, dbs []string, flags models.GlobalFlags) ([]models.MediaWithDB, error)

MediaQuery executes a query against multiple databases concurrently

func MediaQueryCount

func MediaQueryCount(ctx context.Context, dbs []string, flags models.GlobalFlags) (int64, error)

MediaQueryCount executes a count query against multiple databases concurrently

func QueryDatabase

func QueryDatabase(ctx context.Context, dbPath, query string, args []any) ([]models.MediaWithDB, error)

QueryDatabase executes a query against a single database

func ReRankMedia

func ReRankMedia(media []models.MediaWithDB, flags models.GlobalFlags) []models.MediaWithDB

ReRankMedia implements MCDA-like re-ranking

func RegexSortMedia

func RegexSortMedia(media []models.MediaWithDB, flags models.GlobalFlags) []models.MediaWithDB

RegexSortMedia sorts media using the text processor

func ResetSearchModeDetection added in v0.0.9

func ResetSearchModeDetection()

ResetSearchModeDetection resets the detection cache (useful for testing)

func ResolvePercentileFlags

func ResolvePercentileFlags(ctx context.Context, dbs []string, flags models.GlobalFlags) (models.GlobalFlags, error)

ResolvePercentileFlags resolves percentile-based filters (Re-exported for tests)

func ScanMedia

func ScanMedia(rows *sql.Rows, dbPath string) ([]models.MediaWithDB, error)

ScanMedia maps SQL rows to MediaWithDB structs

func SortFolders

func SortFolders(folders []models.FolderStats, sortBy string, reverse bool)

SortFolders sorts folder stats

func SortHistory

func SortHistory(media []models.MediaWithDB, partial string, reverse bool)

SortHistory applies specialized sorting for playback history

func SortMedia

func SortMedia(media []models.MediaWithDB, flags models.GlobalFlags)

SortMedia sorts media using the unified SortBuilder

func SortMediaWithExpansion added in v0.0.30

func SortMediaWithExpansion(ctx context.Context, sqlDB *sql.DB, media *[]models.MediaWithDB, flags models.GlobalFlags)

SortMediaWithExpansion sorts media with optional result expansion (siblings, related) This should be used when sort config includes expansion markers

Types

type DUAggregationOptions added in v0.0.38

type DUAggregationOptions struct {
	// contains filtered or unexported fields
}

type DUQueryResult added in v0.0.32

type DUQueryResult struct {
	Path          string
	Count         int
	TotalSize     int64
	TotalDuration int64
}

DUQueryResult holds the result of a DU aggregation query

func AggregateDUByPath added in v0.0.32

func AggregateDUByPath(
	ctx context.Context,
	dbPath, pathPrefix string,
	targetDepth int,
) ([]DUQueryResult, error)

AggregateDUByPath performs SQL-level aggregation for DU mode This is much faster than fetching all media and aggregating in Go

func AggregateDUByPathMultiDB added in v0.0.32

func AggregateDUByPathMultiDB(
	ctx context.Context,
	dbPaths []string,
	pathPrefix string,
	targetDepth int,
) ([]DUQueryResult, error)

AggregateDUByPathMultiDB performs SQL-level aggregation across multiple databases

func AggregateDUByPathMultiDBWithFilters added in v0.0.32

func AggregateDUByPathMultiDBWithFilters(
	ctx context.Context,
	dbPaths []string,
	pathPrefix string,
	targetDepth int,
	flags models.GlobalFlags,
) ([]DUQueryResult, error)

AggregateDUByPathMultiDBWithFilters performs SQL-level aggregation with filter support

func AggregateDUByPathWithFilters added in v0.0.32

func AggregateDUByPathWithFilters(
	ctx context.Context,
	dbPath, pathPrefix string,
	targetDepth int,
	flags models.GlobalFlags,
) ([]DUQueryResult, error)

AggregateDUByPathWithFilters performs SQL-level aggregation with filter support Uses two-path approach: - Fast path: no FileCounts/FolderCounts/FolderSizes filters - direct SQL aggregation - Slow path: folder backfiltering for FileCounts/FolderCounts/FolderSizes

type FilterBuilder

type FilterBuilder struct {
	Flags models.GlobalFlags
}

FilterBuilder constructs SQL queries and in-memory filters from flags This is the single source of truth for all filter logic

func NewFilterBuilder

func NewFilterBuilder(flags models.GlobalFlags) *FilterBuilder

NewFilterBuilder creates a new FilterBuilder from global flags

func (*FilterBuilder) BuildCount

func (fb *FilterBuilder) BuildCount(ctx context.Context) (string, []any)

BuildCount builds a count query

func (*FilterBuilder) BuildQuery

func (fb *FilterBuilder) BuildQuery(ctx context.Context, columns string) (string, []any)

BuildQuery constructs a complete SQL query with the given columns

func (*FilterBuilder) BuildSelect

func (fb *FilterBuilder) BuildSelect(ctx context.Context, columns string) (string, []any)

BuildSelect is an alias for BuildQuery for backward compatibility

func (*FilterBuilder) BuildWhereClauses

func (fb *FilterBuilder) BuildWhereClauses(ctx context.Context) ([]string, []any)

BuildWhereClauses builds WHERE clauses and arguments for SQL queries Order matters for performance: selective indexed filters come before expensive substring searches Based on benchmark: indexed equality (~277μs) << LIKE prefix (~500μs) << LIKE substring (~1ms)

func (*FilterBuilder) CreateInMemoryFilter

func (fb *FilterBuilder) CreateInMemoryFilter() func(models.MediaWithDB) bool

CreateInMemoryFilter creates a function that can filter media in memory

func (*FilterBuilder) FilterMedia

func (fb *FilterBuilder) FilterMedia(media []models.MediaWithDB) []models.MediaWithDB

FilterMedia applies in-memory filtering to a slice of media

func (*FilterBuilder) OverrideSort

func (fb *FilterBuilder) OverrideSort(s string) string

OverrideSort translates logical sort fields into SQL expressions

type FrequencyStats

type FrequencyStats struct {
	Label         string `json:"label"`
	Count         int    `json:"count"`
	TotalSize     int64  `json:"total_size"`
	TotalDuration int64  `json:"total_duration"`
}

func HistoricalUsage

func HistoricalUsage(ctx context.Context, dbPath, freq, timeColumn string) ([]FrequencyStats, error)

func SummarizeMedia

func SummarizeMedia(media []models.MediaWithDB) []FrequencyStats

type QueryExecutor

type QueryExecutor struct {
	// contains filtered or unexported fields
}

QueryExecutor executes queries against databases

func NewQueryExecutor

func NewQueryExecutor(flags models.GlobalFlags) *QueryExecutor

NewQueryExecutor creates a new QueryExecutor

func (*QueryExecutor) FetchSiblings

func (qe *QueryExecutor) FetchSiblings(
	ctx context.Context,
	media []models.MediaWithDB,
	flags models.GlobalFlags,
) ([]models.MediaWithDB, error)

func (*QueryExecutor) GroupByParent

func (qe *QueryExecutor) GroupByParent(allMedia []models.MediaWithDB, flags models.GlobalFlags) []models.MediaWithDB

func (*QueryExecutor) MediaQuery

func (qe *QueryExecutor) MediaQuery(ctx context.Context, dbs []string) ([]models.MediaWithDB, error)

MediaQuery executes a query against multiple databases concurrently

func (*QueryExecutor) MediaQueryCount

func (qe *QueryExecutor) MediaQueryCount(ctx context.Context, dbs []string) (int64, error)

MediaQueryCount executes a count query against multiple databases concurrently

func (*QueryExecutor) ResolvePercentileFlags

func (qe *QueryExecutor) ResolvePercentileFlags(
	ctx context.Context,
	dbs []string,
	flags models.GlobalFlags,
) (models.GlobalFlags, error)

type RelatedSearchParams added in v0.0.38

type RelatedSearchParams struct {
	FTSTable    string
	ExcludePath string
	QueryStr    string
	Limit       int64
}

RelatedSearchParams represents parameters for related media search

type SearchMode added in v0.0.9

type SearchMode int

SearchMode represents the search backend being used

const (
	SearchModeUnknown   SearchMode = iota
	SearchModeSubstring            // LIKE-based search
	SearchModeFTS5                 // SQLite FTS5
)

func DetectSearchMode added in v0.0.9

func DetectSearchMode(ctx context.Context, db *sql.DB) SearchMode

DetectSearchMode detects the best available search backend Priority: FTS5 > Substring

func GetSearchMode added in v0.0.9

func GetSearchMode() SearchMode

GetSearchMode returns the currently detected search mode

func (SearchMode) String added in v0.0.9

func (s SearchMode) String() string

type SortBuilder

type SortBuilder struct {
	Flags models.GlobalFlags
}

SortBuilder handles both SQL and in-memory sorting

func NewSortBuilder

func NewSortBuilder(flags models.GlobalFlags) *SortBuilder

func (*SortBuilder) Sort

func (sb *SortBuilder) Sort(media []models.MediaWithDB)

func (*SortBuilder) SortAdvanced

func (sb *SortBuilder) SortAdvanced(media []models.MediaWithDB, config string)

func (*SortBuilder) SortBasic

func (sb *SortBuilder) SortBasic(media []models.MediaWithDB)

type SortField added in v0.0.30

type SortField struct {
	Field   string
	Reverse bool
}

SortField represents a single field in a multi-field sort

func DuDefaultSort added in v0.0.38

func DuDefaultSort() []SortField

DuDefaultSort returns the default sort for DU mode lambda x: ((size/count), size, count, folders, reverse(path))

func ParseSortConfig added in v0.0.38

func ParseSortConfig(config string) ([]SortField, string)

ParseSortConfig parses a sort configuration string into SortField slices Supports:

  • Simple: "path", "title"
  • Prefixed: "natural_path", "python_title"
  • Reversed: "-path", "reverse_path"
  • Multi-field: "video_count desc,audio_count desc,path asc"
  • Complex: "natural_path,title desc"
  • Array notation: "field1,field2,field3" (comma-separated)
  • Meta-field markers: "_weighted_rerank", "_natural_order" (apply to fields below)

func XklbDefaultSort added in v0.0.38

func XklbDefaultSort() []SortField

XklbDefaultSort returns the xklb-style default sort fields This matches the lambda sorting from xklb: - video_count desc (videos before audio-only) - audio_count desc (files with audio before silent ones) - path like "http%" asc (local files before remote URLs) - subtitle_count desc - play_count asc (unplayed/least-played first) - playhead desc (furthest along first) - time_last_played asc (least-recently played first) - title is not null desc (titled entries before untitled) - path asc (alphabetical tiebreak)

type SortGroup added in v0.0.30

type SortGroup struct {
	Fields []SortField
	Alg    string // "weighted", "natural", "related", or empty for standard
}

SortGroup represents a group of fields with a specific sorting algorithm

func ParseSortConfigWithGroups added in v0.0.38

func ParseSortConfigWithGroups(config string) []SortGroup

type TimePercentileOptions added in v0.0.38

type TimePercentileOptions struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL