query

package
v0.0.34 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: BSD-3-Clause Imports: 19 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 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 IsSearchAvailable added in v0.0.9

func IsSearchAvailable(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 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 string, pathPrefix string, targetDepth int, currentDepth 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, currentDepth 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, currentDepth 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 string, pathPrefix string, targetDepth int, currentDepth 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 {
	// contains filtered or unexported fields
}

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() (string, []any)

BuildCount builds a count query

func (*FilterBuilder) BuildQuery

func (fb *FilterBuilder) BuildQuery(columns string) (string, []any)

BuildQuery constructs a complete SQL query with the given columns

func (*FilterBuilder) BuildSelect

func (fb *FilterBuilder) BuildSelect(columns string) (string, []any)

BuildSelect is an alias for BuildQuery for backward compatibility

func (*FilterBuilder) BuildWhereClauses

func (fb *FilterBuilder) BuildWhereClauses() ([]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 string, freq string, 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 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(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 {
	// contains filtered or unexported fields
}

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

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

Jump to

Keyboard shortcuts

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