samples

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 7 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 WriteIndex

func WriteIndex(idx *Index, path string) error

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

Types

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