index

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package index provides full-text search indexing for project descriptions using Bleve

Index

Constants

View Source
const (
	// IndexVersion is the current version of the index schema
	// Increment this when making breaking changes to the index structure
	IndexVersion = 4 // Version 4: Added Member field

)

Variables

View Source
var ErrIndexVersionMismatch = errors.New("index version mismatch")

ErrIndexVersionMismatch indicates the index schema version is incompatible

Functions

func CleanMarkdown

func CleanMarkdown(md string) string

CleanMarkdown removes Markdown formatting and extracts plain text Preserves headings, paragraphs, and lists but removes code blocks, links syntax, etc.

func Exists

func Exists(indexPath string) bool

Exists checks if the index exists at the given path

Types

type CombinedMatch

type CombinedMatch struct {
	Project      model.Project
	Snippet      string      // Description snippet if found there
	SearchScore  float64     // Bleve relevance score
	TotalScore   float64     // Combined score (SearchScore + HistoryScore + StarredBonus)
	HistoryScore int         // History boost (with exponential decay)
	StarredBonus int         // Bonus for starred projects (+50 for starred)
	Source       MatchSource // Bitflags: can be MatchSourceName | MatchSourceDescription
}

CombinedMatch represents a unified search result with score breakdown

type DescriptionDocument

type DescriptionDocument struct {
	ProjectPath string // e.g., "backend/api/auth"
	ProjectName string // e.g., "login-service"
	Description string // Project description
	Starred     bool   // Whether the project is starred by the user
	Archived    bool   // Whether the project is archived
	Member      bool   // Whether the user is a member of this project
}

DescriptionDocument represents an indexed project description

type DescriptionIndex

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

DescriptionIndex manages the bleve index for project descriptions

func NewDescriptionIndex

func NewDescriptionIndex(indexPath string) (*DescriptionIndex, error)

NewDescriptionIndex creates or opens a description index Returns ErrIndexVersionMismatch if existing index has incompatible version

func NewDescriptionIndexWithAutoRecreate added in v0.2.9

func NewDescriptionIndexWithAutoRecreate(indexPath string) (*DescriptionIndex, bool, error)

NewDescriptionIndexWithAutoRecreate creates or opens a description index Automatically recreates the index if version mismatch is detected

func (*DescriptionIndex) Add

func (di *DescriptionIndex) Add(projectPath, projectName, description string, starred, archived bool) error

Add indexes a description document

func (*DescriptionIndex) AddBatch

func (di *DescriptionIndex) AddBatch(docs []DescriptionDocument) error

AddBatch indexes multiple description documents in a batch

func (*DescriptionIndex) Close

func (di *DescriptionIndex) Close() error

Close closes the index

func (*DescriptionIndex) Count

func (di *DescriptionIndex) Count() (uint64, error)

Count returns the number of indexed documents

func (*DescriptionIndex) Delete

func (di *DescriptionIndex) Delete(projectPath string) error

Delete removes a document from the index

func (*DescriptionIndex) GetAllProjects

func (di *DescriptionIndex) GetAllProjects() ([]model.Project, error)

GetAllProjects retrieves all projects from the index Returns all indexed projects (no pagination)

func (*DescriptionIndex) Search

func (di *DescriptionIndex) Search(query string, maxResults int) ([]DescriptionMatch, error)

Search performs a full-text search across ProjectName, ProjectPath, and Description Uses field boosting: ProjectName (5x), ProjectPath (2x), Description (1x) Supports multi-word queries with AND logic (all words must be present)

type DescriptionMatch

type DescriptionMatch struct {
	Project model.Project // The matched project
	Snippet string        // Context snippet with highlighted match
	Score   float64       // Relevance score from bleve
}

DescriptionMatch represents a search result from description index

type MatchSource

type MatchSource int

MatchSource indicates where the match was found

const (
	// MatchSourceName indicates match found in project name (fuzzy)
	MatchSourceName MatchSource = 1 << iota
	// MatchSourceDescription indicates match found in description (bleve)
	MatchSourceDescription
)

Jump to

Keyboard shortcuts

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