Skip to main content
Glama
query-builder.ts2.04 kB
/** * Fluent query builder for search options */ import type { SearchOptions } from './search-engine.js'; /** * Fluent builder for constructing search queries */ export class QueryBuilder { private options: SearchOptions = { query: '', limit: 10, offset: 0, }; /** * Set the search query term */ query(term: string): this { this.options.query = term; return this; } /** * Filter by document type */ documentType(type: 'type' | 'method' | 'function' | 'script' | 'all'): this { this.options.documentType = type; return this; } /** * Filter by category */ category(cat: string): this { this.options.category = cat; return this; } /** * Filter by library */ library(lib: string): this { this.options.library = lib; return this; } /** * Exclude categories */ excludeCategories(categories: string[]): this { this.options.exclude = { ...this.options.exclude, categories, }; return this; } /** * Exclude libraries */ excludeLibraries(libraries: string[]): this { this.options.exclude = { ...this.options.exclude, libraries, }; return this; } /** * Set maximum results */ limit(n: number): this { this.options.limit = n; return this; } /** * Set pagination offset */ offset(n: number): this { this.options.offset = n; return this; } /** * Set pagination by page number (1-indexed) */ page(pageNum: number, pageSize: number = 10): this { this.options.limit = pageSize; this.options.offset = (pageNum - 1) * pageSize; return this; } /** * Set field boost weights */ boost(weights: Record<string, number>): this { this.options.boost = weights; return this; } /** * Build the final search options */ build(): SearchOptions { return { ...this.options }; } /** * Create a new QueryBuilder */ static create(): QueryBuilder { return new QueryBuilder(); } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/harche/ProDisco'

If you have feedback or need assistance with the MCP directory API, please join our Discord server