Documentation
¶
Overview ¶
Package search provides full-text search using bleve for ranked results.
Index Management ¶
The Index type wraps a bleve index with markdown-post-aware document mapping. Indexes are persisted to disk and rebuilt only when content changes (detected via content hash).
Usage ¶
idx, err := search.Open(dir)
if err != nil {
idx, err = search.Build(dir, posts)
}
results, err := idx.Search("golang", search.QueryOptions{Limit: 10})
Index ¶
- func ContentHash(posts []*models.Post) string
- func DefaultDir(cacheDir string) string
- func NamedDir(cacheDir, name string) string
- func NamedHashFile(cacheDir, name string) string
- func PostsByPath(posts []*models.Post) map[string]*models.Post
- type Document
- type Index
- func Build(dir string, posts []*models.Post) (*Index, error)
- func BuildIfNeeded(cacheDir string, posts []*models.Post) (*Index, error)
- func BuildIfNeededAt(dir, hashPath string, posts []*models.Post) (*Index, error)
- func BuildIfNeededNamed(cacheDir, name string, posts []*models.Post) (*Index, error)
- func Open(dir string) (*Index, error)
- type QueryOptions
- type Result
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContentHash ¶
ContentHash computes a hash of all post paths and content for cache invalidation.
func DefaultDir ¶
DefaultDir returns the default index directory inside the cache dir.
func NamedDir ¶
NamedDir returns an index directory with a process-specific suffix. Use this when multiple processes may share the same cache directory (e.g., serve and search-server running simultaneously).
func NamedHashFile ¶
NamedHashFile returns a hash file path with a process-specific suffix.
Types ¶
type Document ¶
type Document struct {
Title string `json:"title"`
Content string `json:"content,omitempty"`
Description string `json:"description,omitempty"`
Tags []string `json:"tags,omitempty"`
Path string `json:"path"`
Slug string `json:"slug,omitempty"`
Href string `json:"href,omitempty"`
Date time.Time `json:"date,omitempty"`
Published bool `json:"published"`
Private bool `json:"private,omitempty"`
WordCount int `json:"word_count,omitempty"`
MediaURL string `json:"media_url,omitempty"`
MediaType string `json:"media_type,omitempty"`
PosterURL string `json:"poster_url,omitempty"`
VideoMIME string `json:"video_mime,omitempty"`
DocJSON string `json:"doc_json,omitempty"`
}
Document is the stored bleve document used to answer search results safely. It contains only fields that are allowed to be exposed by search.
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index wraps a bleve index with post-aware operations.
func Build ¶
Build creates a new bleve index from posts. If dir already exists, it is removed and rebuilt.
func BuildIfNeeded ¶
BuildIfNeeded creates or opens an index, rebuilding only if the content hash changed.
func BuildIfNeededAt ¶
BuildIfNeededAt creates or opens an index at an explicit path, rebuilding only if the content hash changed.
func BuildIfNeededNamed ¶
BuildIfNeededNamed creates or opens a named index, allowing multiple processes to maintain separate indexes in the same cache directory.