Search

Functions

Public API reference for the Search extension

Extension Entry Points

FunctionDescription
NewExtension(opts ...ConfigOption) forge.ExtensionCreate the search extension with functional options
NewExtensionWithConfig(config Config) forge.ExtensionCreate the search extension with a complete config
DefaultConfig() ConfigReturns the default configuration

DI Helpers

FunctionDescription
GetSearch(c forge.Container) (Search, error)Resolve the Search from the DI container
MustGetSearch(c forge.Container) SearchSame as GetSearch but panics on error
GetSearchFromApp(app forge.App) (Search, error)Resolve the Search from an app instance
MustGetSearchFromApp(app forge.App) SearchSame as GetSearchFromApp but panics on error

Search Interface -- Connection

MethodDescription
Connect(ctx) errorOpen connection to the search backend
Disconnect(ctx) errorClose the connection
Ping(ctx) errorVerify the backend is reachable

Search Interface -- Index Management

MethodDescription
CreateIndex(ctx, name, schema) errorCreate a new search index with the given schema
DeleteIndex(ctx, name) errorDelete an index and all its documents
ListIndexes(ctx) ([]string, error)List all index names
GetIndexInfo(ctx, name) (*IndexInfo, error)Get index metadata including document count and size

Search Interface -- Document Operations

MethodDescription
Index(ctx, index, doc) errorIndex a single document
BulkIndex(ctx, index, docs) errorIndex multiple documents in one batch
Get(ctx, index, id) (*Document, error)Retrieve a document by ID
Delete(ctx, index, id) errorDelete a document by ID
Update(ctx, index, id, doc) errorUpdate an existing document

Search Interface -- Query Operations

MethodDescription
Search(ctx, query) (*SearchResults, error)Execute a full-text search with filters, sorting, and facets
Suggest(ctx, query) (*SuggestResults, error)Get search suggestions for a partial query
Autocomplete(ctx, query) (*AutocompleteResults, error)Get ranked completions for search-as-you-type

Search Interface -- Analytics

MethodDescription
Stats(ctx) (*SearchStats, error)Get backend statistics (index count, document count, query stats)

Key Types

SearchQuery

The primary query object passed to Search():

FieldTypePurpose
IndexstringTarget index name
QuerystringSearch text
Filters[]FilterField-level filters
Sort[]SortFieldSort order
Facets[]stringFields to compute facet counts for
OffsetintPagination offset
LimitintMaximum results to return
HighlightboolEnable highlighting
HighlightFields[]stringFields to highlight
Fields[]stringFields to return (empty = all)
MinScorefloat64Minimum relevance score threshold
BoostFieldsmap[string]float64Per-field relevance boosting
FuzzyLevelintFuzzy matching tolerance

SearchResults

FieldTypePurpose
Hits[]HitMatching documents with scores and highlights
Totalint64Total number of matches
ProcessingTimetime.DurationBackend query time
Facetsmap[string][]FacetFacet counts by field
ExhaustiveboolWhether the total count is exact

How is this guide?

On this page