samples

package
v1.0.19 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package samples provides search functionality over community-contributed Microsoft Graph API query samples.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildFTSDatabase added in v1.0.14

func BuildFTSDatabase(idx *Index, dbPath string) error

BuildFTSDatabase creates a SQLite FTS5 database from the samples index. The database contains both a content table (for returning results) and an FTS5 virtual table (for full-text search with Porter stemming).

func FormatFTSResults added in v1.0.14

func FormatFTSResults(results []FTSSearchResult) interface{}

FormatFTSResults converts a slice of FTSSearchResult into the standard JSON output format.

func WriteIndex

func WriteIndex(idx *Index, path string) error

WriteIndex serializes an Index to JSON and writes it to the given path.

Types

type FTSIndex added in v1.0.14

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

FTSIndex provides full-text search over a SQLite FTS5 database containing sample data.

func LoadFTSIndex added in v1.0.14

func LoadFTSIndex(path string) (*FTSIndex, error)

LoadFTSIndex opens a SQLite FTS database for searching. Callers must call Close() when done.

func (*FTSIndex) Close added in v1.0.14

func (idx *FTSIndex) Close() error

Close releases the database connection.

func (*FTSIndex) Search added in v1.0.14

func (idx *FTSIndex) Search(query, product string, limit int) []FTSSearchResult

Search finds samples matching the given criteria using FTS5 full-text search with BM25 ranking.

type FTSSearchResult added in v1.0.14

type FTSSearchResult struct {
	Intent      string  `json:"intent"`
	Query       string  `json:"query"`
	Product     string  `json:"product,omitempty"`
	File        string  `json:"file,omitempty"`
	MatchReason string  `json:"matchReason"`
	Score       float64 `json:"score,omitempty"`
}

FTSSearchResult contains a sample search result with all available fields.

type Index

type Index struct {
	Generated string   `json:"generated"`
	Count     int      `json:"count"`
	Samples   []Sample `json:"samples"`
}

Index holds the full searchable samples index.

func BuildIndex

func BuildIndex(samplesDir string) (*Index, error)

BuildIndex walks a samples directory, parses all YAML files, and returns a compiled Index. This is used by CI to produce samples-index.json.

func LoadIndex

func LoadIndex(path string) (*Index, error)

LoadIndex reads and parses the pre-built samples index JSON file.

func (*Index) Search

func (idx *Index) Search(query string, product string, limit int) []SearchResult

Search finds samples whose intent matches the given query string. It performs case-insensitive keyword matching — all query words must appear somewhere in the intent or query fields.

type Sample

type Sample struct {
	Intent  string      `json:"intent"  yaml:"intent"`
	Query   interface{} `json:"query"   yaml:"query"` // string or []string for multi-step
	Product string      `json:"product" yaml:"-"`     // populated from directory name
	File    string      `json:"file"    yaml:"-"`     // relative path within samples/
}

Sample represents a single community-contributed query sample.

func (*Sample) QueryStrings

func (s *Sample) QueryStrings() []string

QueryStrings returns the query as a string slice, normalizing both single-string and multi-step list formats.

type SearchResult

type SearchResult struct {
	Sample
	MatchReason string `json:"matchReason"`
}

SearchResult wraps a sample with a relevance indicator.

Jump to

Keyboard shortcuts

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