search

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrOrganizationNotFound = errors.New("search organization not found")
	ErrIndexNotFound        = errors.New("search index not found")
	ErrNotFound             = ErrOrganizationNotFound
	ErrUnavailable          = errors.New("search backend unavailable")
	ErrInvalidConfiguration = errors.New("search backend invalid configuration")
	// ErrInvalidQuery marks Chef search query syntax that OpenCook can parse as invalid.
	ErrInvalidQuery = errors.New("search query invalid")
	ErrRejected     = errors.New("search backend rejected request")
)

Functions

func NewIndexingBootstrapCoreStore

func NewIndexingBootstrapCoreStore(delegate bootstrap.BootstrapCoreStore, indexer DocumentIndexer) bootstrap.BootstrapCoreStore

func NewIndexingCoreObjectStore

func NewIndexingCoreObjectStore(delegate bootstrap.CoreObjectStore, indexer DocumentIndexer) bootstrap.CoreObjectStore

func OpenSearchDocumentID

func OpenSearchDocumentID(doc Document) string

func OpenSearchDocumentIDForRef

func OpenSearchDocumentIDForRef(ref DocumentRef) string

func RebuildOpenSearchIndex

func RebuildOpenSearchIndex(ctx context.Context, client *OpenSearchClient, state *bootstrap.Service) error

func ValidateOpenSearchEndpoint

func ValidateOpenSearchEndpoint(raw string) error

Types

type ConsistencyCounts

type ConsistencyCounts struct {
	Expected    int `json:"expected"`
	Observed    int `json:"observed"`
	Missing     int `json:"missing"`
	Stale       int `json:"stale"`
	Unsupported int `json:"unsupported"`
	Upserted    int `json:"upserted"`
	Deleted     int `json:"deleted"`
	Skipped     int `json:"skipped"`
	Failed      int `json:"failed"`
	Clean       int `json:"clean"`
}

type ConsistencyObjectCount

type ConsistencyObjectCount struct {
	Organization string `json:"organization"`
	Index        string `json:"index"`
	Expected     int    `json:"expected"`
	Observed     int    `json:"observed"`
	Missing      int    `json:"missing"`
	Stale        int    `json:"stale"`
}

type ConsistencyPlan

type ConsistencyPlan struct {
	AllOrganizations bool
	Organization     string
	Index            string
	Repair           bool
	DryRun           bool
}

type ConsistencyResult

type ConsistencyResult struct {
	AllOrganizations  bool                     `json:"all_organizations"`
	Organization      string                   `json:"organization,omitempty"`
	Index             string                   `json:"index,omitempty"`
	Repair            bool                     `json:"repair,omitempty"`
	DryRun            bool                     `json:"dry_run,omitempty"`
	Counts            ConsistencyCounts        `json:"counts"`
	ObjectCounts      []ConsistencyObjectCount `json:"object_counts,omitempty"`
	MissingDocuments  []string                 `json:"missing_documents,omitempty"`
	StaleDocuments    []string                 `json:"stale_documents,omitempty"`
	UnsupportedScopes []string                 `json:"unsupported_scopes,omitempty"`
	Failures          []string                 `json:"failures,omitempty"`
	Duration          time.Duration            `json:"duration"`
}

type ConsistencyService

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

func NewConsistencyService

func NewConsistencyService(state *bootstrap.Service, target ConsistencyTarget) *ConsistencyService

func (*ConsistencyService) Run

func (s *ConsistencyService) Run(ctx context.Context, plan ConsistencyPlan) (result ConsistencyResult, err error)

func (*ConsistencyService) WithNow

func (s *ConsistencyService) WithNow(now func() time.Time) *ConsistencyService

type ConsistencyTarget

type ConsistencyTarget interface {
	Ping(context.Context) error
	EnsureChefIndex(context.Context) error
	SearchIDs(context.Context, Query) ([]string, error)
	BulkUpsert(context.Context, []Document) error
	DeleteDocument(context.Context, string) error
	Refresh(context.Context) error
}

type Document

type Document struct {
	Index    string
	Name     string
	Object   map[string]any
	Partial  map[string]any
	Fields   map[string][]string
	Resource authz.Resource
}

func DocumentsFromBootstrapState

func DocumentsFromBootstrapState(state *bootstrap.Service) ([]Document, error)

func DocumentsFromBootstrapStateForPlan

func DocumentsFromBootstrapStateForPlan(state *bootstrap.Service, plan ReindexPlan) ([]Document, error)

type DocumentBuilder

type DocumentBuilder struct{}

DocumentBuilder centralizes Chef-style search document expansion so the memory and OpenSearch-backed indexes cannot drift in field semantics.

func NewDocumentBuilder

func NewDocumentBuilder() DocumentBuilder

func (DocumentBuilder) Client

func (b DocumentBuilder) Client(org string, client bootstrap.Client) Document

func (DocumentBuilder) DataBagItem

func (b DocumentBuilder) DataBagItem(org, bagName string, item bootstrap.DataBagItem) Document

func (DocumentBuilder) Environment

func (b DocumentBuilder) Environment(org string, env bootstrap.Environment) Document

func (DocumentBuilder) Node

func (b DocumentBuilder) Node(org string, node bootstrap.Node) Document

func (DocumentBuilder) Role

func (b DocumentBuilder) Role(org string, role bootstrap.Role) Document

type DocumentIndexer

type DocumentIndexer interface {
	UpsertDocuments(context.Context, []Document) error
	DeleteDocuments(context.Context, []DocumentRef) error
}

type DocumentRef

type DocumentRef struct {
	Organization string
	Index        string
	Name         string
}

type Index

type Index interface {
	Name() string
	Status() Status
	Indexes(context.Context, string) ([]string, error)
	Search(context.Context, Query) (Result, error)
}

type MemoryIndex

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

func NewMemoryIndex

func NewMemoryIndex(state *bootstrap.Service, target string) MemoryIndex

func (MemoryIndex) Indexes

func (i MemoryIndex) Indexes(_ context.Context, org string) ([]string, error)

func (MemoryIndex) Name

func (i MemoryIndex) Name() string

func (MemoryIndex) Search

func (i MemoryIndex) Search(_ context.Context, query Query) (Result, error)

Search evaluates the shared compiled query plan against documents derived from the in-memory bootstrap state.

func (MemoryIndex) Status

func (i MemoryIndex) Status() Status

type NoopIndex

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

func NewNoopIndex

func NewNoopIndex(target string) NoopIndex

func (NoopIndex) Indexes

func (i NoopIndex) Indexes(_ context.Context, _ string) ([]string, error)

func (NoopIndex) Name

func (i NoopIndex) Name() string

func (NoopIndex) Search

func (i NoopIndex) Search(_ context.Context, _ Query) (Result, error)

func (NoopIndex) Status

func (i NoopIndex) Status() Status

type OpenSearchCapabilities

type OpenSearchCapabilities struct {
	IndexExistsChecks             bool
	CreateIndex                   bool
	PutMapping                    bool
	BulkIndexing                  bool
	SearchIDs                     bool
	SearchAfterPagination         bool
	Refresh                       bool
	DeleteDocument                bool
	DeleteByQuery                 bool
	DeleteByQueryFallbackRequired bool
	TotalHitsObjectResponses      bool
}

OpenSearchCapabilities describes provider operations OpenCook relies on. Later hardening tasks can replace inferred flags with more exact probes.

type OpenSearchClient

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

func NewOpenSearchClient

func NewOpenSearchClient(raw string, opts ...OpenSearchOption) (*OpenSearchClient, error)

func (*OpenSearchClient) BulkUpsert

func (c *OpenSearchClient) BulkUpsert(ctx context.Context, docs []Document) error

func (*OpenSearchClient) DeleteByQuery

func (c *OpenSearchClient) DeleteByQuery(ctx context.Context, org, index string) error

func (*OpenSearchClient) DeleteDocument

func (c *OpenSearchClient) DeleteDocument(ctx context.Context, id string) error

func (*OpenSearchClient) DeleteDocuments

func (c *OpenSearchClient) DeleteDocuments(ctx context.Context, refs []DocumentRef) error

func (*OpenSearchClient) DiscoverProvider

func (c *OpenSearchClient) DiscoverProvider(ctx context.Context) (OpenSearchProviderInfo, error)

DiscoverProvider performs the non-mutating discovery sequence used to model the configured provider before activation, status, or admin workflows rely on version-specific behavior.

func (*OpenSearchClient) EnsureChefIndex

func (c *OpenSearchClient) EnsureChefIndex(ctx context.Context) error

func (*OpenSearchClient) Ping

func (c *OpenSearchClient) Ping(ctx context.Context) error

func (*OpenSearchClient) ProviderInfo

func (c *OpenSearchClient) ProviderInfo() (OpenSearchProviderInfo, bool)

ProviderInfo returns the last successful provider discovery snapshot. Callers get a copy so later discovery refreshes cannot mutate their view.

func (*OpenSearchClient) Refresh

func (c *OpenSearchClient) Refresh(ctx context.Context) error

func (*OpenSearchClient) SearchIDs

func (c *OpenSearchClient) SearchIDs(ctx context.Context, query Query) ([]string, error)

func (*OpenSearchClient) Status

func (c *OpenSearchClient) Status() Status

func (*OpenSearchClient) UpsertDocuments

func (c *OpenSearchClient) UpsertDocuments(ctx context.Context, docs []Document) error

type OpenSearchIndex

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

func NewOpenSearchIndex

func NewOpenSearchIndex(state *bootstrap.Service, client *OpenSearchClient, target string) *OpenSearchIndex

func (*OpenSearchIndex) Indexes

func (i *OpenSearchIndex) Indexes(_ context.Context, org string) ([]string, error)

func (*OpenSearchIndex) Name

func (i *OpenSearchIndex) Name() string

func (*OpenSearchIndex) Search

func (i *OpenSearchIndex) Search(ctx context.Context, query Query) (Result, error)

func (*OpenSearchIndex) Status

func (i *OpenSearchIndex) Status() Status

type OpenSearchOption

type OpenSearchOption func(*openSearchOptions)

func WithOpenSearchTransport

func WithOpenSearchTransport(transport OpenSearchTransport) OpenSearchOption

type OpenSearchProviderInfo

type OpenSearchProviderInfo struct {
	Distribution  string
	Version       string
	VersionParsed bool
	Major         int
	Minor         int
	Patch         int
	Tagline       string
	NodeName      string
	ClusterName   string
	BuildFlavor   string
	BuildType     string
	BuildHash     string
	Capabilities  OpenSearchCapabilities
}

OpenSearchProviderInfo records the provider identity and inferred feature set discovered from the configured OpenSearch-compatible endpoint.

type OpenSearchTransport

type OpenSearchTransport interface {
	Do(*http.Request) (*http.Response, error)
}

type Query

type Query struct {
	Organization string
	Index        string
	Q            string
}

type QueryPlan

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

func CompileQuery

func CompileQuery(raw string) QueryPlan

CompileQuery parses the Chef search query string into the shared internal AST used by both memory search and OpenSearch request planning.

func (QueryPlan) Err

func (p QueryPlan) Err() error

Err returns a stable parser error that callers can map to Chef-facing search error shapes without exposing parser/provider internals.

func (QueryPlan) Matches

func (p QueryPlan) Matches(doc Document) bool

Matches evaluates the compiled query against an expanded search document.

func (QueryPlan) MatchesFields

func (p QueryPlan) MatchesFields(fields map[string][]string) bool

MatchesFields is a test/helper shortcut for evaluating already-expanded document fields without constructing a complete search document.

func (QueryPlan) OpenSearchQueryBody

func (p QueryPlan) OpenSearchQueryBody() map[string]any

OpenSearchQueryBody returns the query-only request fragment for tests and request builders that need to inspect the generated provider clause.

func (QueryPlan) OpenSearchQueryClause

func (p QueryPlan) OpenSearchQueryClause() map[string]any

OpenSearchQueryClause compiles the AST into the current compat_terms-based OpenSearch clause, keeping provider behavior aligned with memory search.

type ReindexCounts

type ReindexCounts struct {
	Scanned  int `json:"scanned"`
	Upserted int `json:"upserted"`
	Deleted  int `json:"deleted"`
	Skipped  int `json:"skipped"`
	Missing  int `json:"missing"`
	Failed   int `json:"failed"`
}

type ReindexMode

type ReindexMode string
const (
	ReindexModeDrop     ReindexMode = "drop"
	ReindexModeReindex  ReindexMode = "reindex"
	ReindexModeComplete ReindexMode = "complete"
)

type ReindexPlan

type ReindexPlan struct {
	Mode             ReindexMode
	AllOrganizations bool
	Organization     string
	Index            string
	Names            []string
	DryRun           bool
}

type ReindexResult

type ReindexResult struct {
	Mode             ReindexMode   `json:"mode"`
	AllOrganizations bool          `json:"all_organizations"`
	Organization     string        `json:"organization,omitempty"`
	Index            string        `json:"index,omitempty"`
	Names            []string      `json:"names,omitempty"`
	DryRun           bool          `json:"dry_run,omitempty"`
	Counts           ReindexCounts `json:"counts"`
	Failures         []string      `json:"failures,omitempty"`
	Duration         time.Duration `json:"duration"`
}

type ReindexService

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

func NewReindexService

func NewReindexService(state *bootstrap.Service, target ReindexTarget) *ReindexService

func (*ReindexService) Run

func (s *ReindexService) Run(ctx context.Context, plan ReindexPlan) (result ReindexResult, err error)

func (*ReindexService) WithNow

func (s *ReindexService) WithNow(now func() time.Time) *ReindexService

type ReindexTarget

type ReindexTarget interface {
	Ping(context.Context) error
	EnsureChefIndex(context.Context) error
	DeleteByQuery(context.Context, string, string) error
	DeleteDocument(context.Context, string) error
	BulkUpsert(context.Context, []Document) error
	Refresh(context.Context) error
}

type Result

type Result struct {
	Documents []Document `json:"documents"`
}

type Status

type Status struct {
	Backend    string `json:"backend"`
	Configured bool   `json:"configured"`
	Message    string `json:"message"`
}

func OpenSearchActiveStatus

func OpenSearchActiveStatus() Status

func OpenSearchProviderStatus

func OpenSearchProviderStatus(info OpenSearchProviderInfo, known bool) Status

OpenSearchProviderStatus preserves the stable status payload shape while making discovered provider identity and capability mode visible in the existing human-readable message.

func OpenSearchUnavailableStatus

func OpenSearchUnavailableStatus() Status

Jump to

Keyboard shortcuts

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