Skip to content

SearchBuilder

Fluent search builder for advanced event queries. Provides case-insensitive text search, metadata search, and more.

// Get events
const events = cal.search()
.text('christmas')
.categories(['holiday'])
.metadata({ season: 'advent' })
.dateFrom('2025-01-01')
.dateTo('2025-12-31')
.sortBy('date', 'asc')
.getEvents();
// Get days containing matching events
const days = cal.search()
.text('easter')
.getDays();

TMetadata extends Record<string, unknown> = Record<string, unknown>

Custom metadata type for events

TCategory extends string = string

Category type for events

new SearchBuilder<TMetadata, TCategory>(executor): SearchBuilder<TMetadata, TCategory>

(options) => CalendarEvent<TMetadata, TCategory>[]

SearchBuilder<TMetadata, TCategory>

categories(categories): this

Filter by categories (match any)

string[]

this


category(category): this

Filter by category (single)

string

this


count(): number

Count matching events

number


date(date): this

Filter by specific date

string

this


dateFrom(date): this

Filter events from this date onwards (inclusive, uses >=)

string

Start date in YYYY-MM-DD format

this


dateTo(date): this

Filter events up to this date (inclusive, uses <=)

string

End date in YYYY-MM-DD format

this


description(search): this

Search text in description only (case-insensitive)

string

this


exists(): boolean

Check if any events match the search criteria

boolean


first(): CalendarEvent<TMetadata, TCategory> | undefined

Get the first matching event or undefined

CalendarEvent<TMetadata, TCategory> | undefined


getDays(): CalendarDay<TMetadata, TCategory>[]

Get calendar days containing matching events. Returns days with their events sorted by keyword match score (highest first), then by priority.

CalendarDay<TMetadata, TCategory>[]

Array of calendar days containing matching events

// Basic usage - get days with matching events
const days = cal.search().text('christmas').getDays();
// With typed calendar (generics flow automatically)
const cal = calendary<LiturgicalMetadata>();
const days = cal.search().category('holiday').getDays();
// days[0].events[0].metadata?.rank is typed!

getEvents(): CalendarEvent<TMetadata, TCategory>[]

Get matching events with typed result. Returns only the events that match the search criteria.

CalendarEvent<TMetadata, TCategory>[]

Array of matching events

// Basic usage
const events = cal.search().text('christmas').getEvents();
// With typed calendar (generics flow automatically)
const cal = calendary<LiturgicalMetadata>();
const events = cal.search().metadata({ rank: 'solemnity' }).getEvents();
// events[0].metadata?.rank is typed!

group(groupId): this

Filter by single group

string

this


groups(groupIds): this

Filter by groups

string[]

this


hasAllCategories(categories): this

Filter by categories (must have all)

string[]

this


id(search): this

Search text in id only (case-insensitive)

string

this


keyword(keyword): this

Search by single keyword

string

this


keywords(keywords): this

Search by keywords (match any)

string[]

this


limit(count): this

Limit number of results

number

this


maxPriority(priority): this

Filter by maximum priority (higher = more important; default 0)

number

this


metadata(query): this

Search by metadata key-value pairs. Supports nested objects and case-insensitive string matching.

MetadataQuery<TMetadata>

this

// Simple key-value
.metadata({ season: 'advent' })
// Nested object
.metadata({ location: { country: 'fr' } })
// Multiple conditions (AND)
.metadata({ rank: 'solemnity', vestmentColor: 'white' })

minPriority(priority): this

Filter by minimum priority (higher = more important; default 0)

number

this


offset(count): this

Offset results (for pagination)

number

this


range(from, to): this

Filter by date range (inclusive on both ends)

string

string

this


sortBy(field, order?): this

Sort results by field and order

SortField

SortOrder = "asc"

this


source(…source): this

Filter by source — match any (the plugin / feed / subscription that produced it).

string[]

this


status(…status): this

Filter by status — match any (e.g. hide cancelled by listing the ones you want).

…("confirmed" | "tentative" | "cancelled")[]

this


text(search): this

Search text in title and description (case-insensitive)

string

this


title(search): this

Search text in title only (case-insensitive)

string

this


type(…types): this

Filter by event type(s) — match any (e.g. "weekly", "daily", a plugin type).

string[]

this