search

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExecutionPlan

type ExecutionPlan struct {
	// Strategy determines how results from Bleve and SQL are combined.
	Strategy JoinStrategy

	// BleveQuery is the full-text search query for Bleve (empty if SQLOnly).
	BleveQuery string

	// BleveIndex specifies which Bleve index to search: "code" or "diff".
	BleveIndex string

	// SQL is the metadata query (may reference Bleve result IDs).
	SQL string

	// SQLParams are the bound parameters for the SQL query.
	SQLParams []string

	// SearchType is the resolved search type.
	SearchType SearchType

	// Limit is the max number of results.
	Limit int

	// IsRegex indicates if BleveQuery should use regex matching.
	IsRegex bool
}

ExecutionPlan describes how a query will be executed.

func Plan

func Plan(query *ParsedQuery) (*ExecutionPlan, error)

Plan converts a ParsedQuery into an ExecutionPlan.

type Filters

type Filters struct {
	Repo        string
	NegRepo     string
	File        string
	NegFile     string
	Lang        string
	NegLang     string
	Rev         string
	Count       int // 0 means default (20)
	Case        bool
	Author      string
	NegAuthor   string
	Before      string
	After       string
	Message     string
	NegMessage  string
	Select      SelectType
	SelectKind  string // for SelectSymbolKind
	Calls       string
	CalledBy    string
	Returns     string
	CommentKind string
	State       string
}

Filters parsed from the query string.

type JoinStrategy

type JoinStrategy int

JoinStrategy determines how Bleve and SQL results are combined.

const (
	// JoinIntersect means both Bleve and SQL queries run, results are intersected.
	JoinIntersect JoinStrategy = iota
	// JoinSQLOnly means only SQL is needed (commits, symbols, calls).
	JoinSQLOnly
	// JoinBleveOnly means only Bleve full-text search is needed (no metadata filters).
	JoinBleveOnly
)

func (JoinStrategy) String

func (js JoinStrategy) String() string

type ParsedQuery

type ParsedQuery struct {
	// SearchTerms grouped by OR. Each group is space-joined AND terms.
	SearchTerms []string
	Type        SearchType
	IsRegex     bool
	Filters     Filters
}

ParsedQuery is the result of parsing a query string.

func ParseQuery

func ParseQuery(input string) (*ParsedQuery, error)

ParseQuery parses a query string.

func (*ParsedQuery) HasEmptyPattern

func (q *ParsedQuery) HasEmptyPattern() bool

HasEmptyPattern returns true if there are no search terms.

func (*ParsedQuery) SearchPattern

func (q *ParsedQuery) SearchPattern() string

SearchPattern returns all OR groups joined with " OR ".

type Result

type Result struct {
	Repo        string  `json:"repo,omitempty"`
	FilePath    string  `json:"file_path,omitempty"`
	Content     string  `json:"content,omitempty"`
	Score       float64 `json:"score,omitempty"`
	Line        int     `json:"line,omitempty"`
	Language    string  `json:"language,omitempty"`
	CommitHash  string  `json:"commit_hash,omitempty"`
	Author      string  `json:"author,omitempty"`
	Message     string  `json:"message,omitempty"`
	SymbolName  string  `json:"symbol_name,omitempty"`
	SymbolKind  string  `json:"symbol_kind,omitempty"`
	CommentKind string  `json:"comment_kind,omitempty"`
	CommentText string  `json:"comment_text,omitempty"`

	// PR/issue-specific fields (populated for type:pr and type:issue results)
	Number int    `json:"number,omitempty"`
	Title  string `json:"title,omitempty"`
	State  string `json:"state,omitempty"`
	URL    string `json:"url,omitempty"`
}

Result represents a single search result.

func Execute

func Execute(ctx context.Context, s *store.Store, query *ParsedQuery) ([]Result, error)

Execute runs a parsed query against the store using the planner to determine the execution strategy (SQL only, Bleve only, or intersect).

type SearchType

type SearchType int

SearchType determined by the type: filter.

const (
	SearchTypeCode SearchType = iota
	SearchTypeDiff
	SearchTypeCommit
	SearchTypeSymbol
	SearchTypeComment
	SearchTypePR
	SearchTypeIssue
)

func (SearchType) String

func (st SearchType) String() string

type SelectType

type SelectType int

SelectType determined by the select: filter.

const (
	SelectNone SelectType = iota
	SelectRepo
	SelectFile
	SelectSymbol
	SelectSymbolKind
)

type TranslatedQuery

type TranslatedQuery struct {
	SQL        string
	Params     []string
	SearchType SearchType
}

TranslatedQuery is SQL ready for execution with bound parameters.

func Translate

func Translate(query *ParsedQuery) (*TranslatedQuery, error)

Translate converts a ParsedQuery into a TranslatedQuery (SQL + params).

Jump to

Keyboard shortcuts

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