query

package
v0.0.0-...-7ffb936 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2025 License: Apache-2.0 Imports: 19 Imported by: 10

Documentation

Overview

Package query contains the API for creating Zoekt queries. Queries can be constructed directly through query.Q objects, or by parsing a string using query.Parse

Index

Constants

View Source
const (
	TypeFileMatch uint8 = iota
	TypeFileName
	TypeRepo
)

Variables

This section is empty.

Functions

func LowerRegexp

func LowerRegexp(r *syntax.Regexp) *syntax.Regexp

func OptimizeRegexp

func OptimizeRegexp(re *syntax.Regexp, flags syntax.Flags) *syntax.Regexp

OptimizeRegexp converts capturing groups to non-capturing groups. Returns original input if an error is encountered

func QToProto

func QToProto(q Q) *webserverv1.Q

func VisitAtoms

func VisitAtoms(q Q, v func(q Q))

VisitAtoms runs `v` on all atom queries within `q`.

Types

type And

type And struct {
	Children []Q
}

And is matched when all its children are.

func AndFromProto

func AndFromProto(p *webserverv1.And) (*And, error)

func (*And) String

func (q *And) String() string

func (*And) ToProto

func (q *And) ToProto() *webserverv1.And

type Boost

type Boost struct {
	Child Q
	// Boost will multiply the score of its descendents. Values less than 1 will
	// give less importance while values greater than 1 will give more
	// importance.
	Boost float64
}

Boost scales the contribution to score of descendents.

func BoostFromProto

func BoostFromProto(p *webserverv1.Boost) (*Boost, error)

func (*Boost) String

func (q *Boost) String() string

func (*Boost) ToProto

func (q *Boost) ToProto() *webserverv1.Boost

type Branch

type Branch struct {
	Pattern string

	// exact is true if we want to Pattern to equal branch.
	Exact bool
}

Branch limits search to a specific branch.

func BranchFromProto

func BranchFromProto(p *webserverv1.Branch) *Branch

func (*Branch) String

func (q *Branch) String() string

func (*Branch) ToProto

func (q *Branch) ToProto() *webserverv1.Branch

type BranchRepos

type BranchRepos struct {
	Branch string
	Repos  *roaring.Bitmap
}

BranchRepos is a (branch, sourcegraph repo ids bitmap) tuple. It is a Sourcegraph addition.

func BranchReposFromProto

func BranchReposFromProto(p *webserverv1.BranchRepos) (BranchRepos, error)

func (*BranchRepos) ToProto

func (br *BranchRepos) ToProto() *webserverv1.BranchRepos

type BranchesRepos

type BranchesRepos struct {
	List []BranchRepos
}

BranchesRepos is a slice of BranchRepos to match. It is a Sourcegraph addition and only used in the RPC interface for efficient checking of large repo lists.

func BranchesReposFromProto

func BranchesReposFromProto(p *webserverv1.BranchesRepos) (*BranchesRepos, error)

func NewSingleBranchesRepos

func NewSingleBranchesRepos(branch string, ids ...uint32) *BranchesRepos

NewSingleBranchesRepos is a helper for creating a BranchesRepos which searches a single branch.

func (BranchesRepos) MarshalBinary

func (q BranchesRepos) MarshalBinary() ([]byte, error)

MarshalBinary implements a specialized encoder for BranchesRepos.

func (*BranchesRepos) String

func (q *BranchesRepos) String() string

func (*BranchesRepos) ToProto

func (br *BranchesRepos) ToProto() *webserverv1.BranchesRepos

func (*BranchesRepos) UnmarshalBinary

func (q *BranchesRepos) UnmarshalBinary(b []byte) (err error)

UnmarshalBinary implements a specialized decoder for BranchesRepos.

type Const

type Const struct {
	Value bool
}

func (*Const) String

func (q *Const) String() string

type FileNameSet

type FileNameSet struct {
	Set map[string]struct{}
}

FileNameSet is a list of file names to match. It is a Sourcegraph addition and only used in the RPC interface for efficient checking of large file lists.

func FileNameSetFromProto

func FileNameSetFromProto(p *webserverv1.FileNameSet) *FileNameSet

func NewFileNameSet

func NewFileNameSet(fileNames ...string) *FileNameSet

func (*FileNameSet) MarshalBinary

func (q *FileNameSet) MarshalBinary() ([]byte, error)

MarshalBinary implements a specialized encoder for FileNameSet.

func (*FileNameSet) String

func (q *FileNameSet) String() string

func (*FileNameSet) ToProto

func (q *FileNameSet) ToProto() *webserverv1.FileNameSet

func (*FileNameSet) UnmarshalBinary

func (q *FileNameSet) UnmarshalBinary(b []byte) error

UnmarshalBinary implements a specialized decoder for FileNameSet.

type Language

type Language struct {
	Language string
}

func LanguageFromProto

func LanguageFromProto(p *webserverv1.Language) *Language

func (*Language) String

func (l *Language) String() string

func (*Language) ToProto

func (l *Language) ToProto() *webserverv1.Language

type Meta

type Meta struct {
	Field string         // The metadata field name
	Value *regexp.Regexp // The value to match
}

Meta represents a query for metadata fields.

func MetaFromProto

func MetaFromProto(p *webserverv1.Meta) (*Meta, error)

func (*Meta) String

func (m *Meta) String() string

String returns a string representation of the Meta query.

type Not

type Not struct {
	Child Q
}

Not inverts the meaning of its child.

func NotFromProto

func NotFromProto(p *webserverv1.Not) (*Not, error)

func (*Not) String

func (q *Not) String() string

func (*Not) ToProto

func (q *Not) ToProto() *webserverv1.Not

type Or

type Or struct {
	Children []Q
}

Or is matched when any of its children is matched.

func OrFromProto

func OrFromProto(p *webserverv1.Or) (*Or, error)

func (*Or) String

func (q *Or) String() string

func (*Or) ToProto

func (q *Or) ToProto() *webserverv1.Or

type Q

type Q interface {
	String() string
}

Q is a representation for a possibly hierarchical search query.

func ExpandFileContent

func ExpandFileContent(q Q) Q

Expand expands Substr queries into (OR file_substr content_substr) queries, and the same for Regexp queries..

func Map

func Map(q Q, f func(q Q) Q) Q

Map runs f over the q.

func NewAnd

func NewAnd(qs ...Q) Q

NewAnd is syntactic sugar for constructing And queries.

func NewOr

func NewOr(qs ...Q) Q

NewOr is syntactic sugar for constructing Or queries.

func Parse

func Parse(qStr string) (Q, error)

Parse parses a string into a query.

func QFromProto

func QFromProto(p *webserverv1.Q) (Q, error)

func RegexpQuery

func RegexpQuery(text string, content, file bool) (Q, error)

RegexpQuery parses an atom into either a regular expression, or a simple substring atom.

func Simplify

func Simplify(q Q) Q

type RawConfig

type RawConfig uint64

RawConfig filters repositories based on their encoded RawConfig map.

const (
	RcOnlyPublic   RawConfig = 1
	RcOnlyPrivate  RawConfig = 2
	RcOnlyForks    RawConfig = 1 << 2
	RcNoForks      RawConfig = 2 << 2
	RcOnlyArchived RawConfig = 1 << 4
	RcNoArchived   RawConfig = 2 << 4
)

func RawConfigFromProto

func RawConfigFromProto(p *webserverv1.RawConfig) (res RawConfig)

func (RawConfig) String

func (r RawConfig) String() string

func (RawConfig) ToProto

func (r RawConfig) ToProto() *webserverv1.RawConfig

type Regexp

type Regexp struct {
	Regexp        *syntax.Regexp
	FileName      bool
	Content       bool
	CaseSensitive bool
}

RegexpQuery is a query looking for regular expressions matches.

func RegexpFromProto

func RegexpFromProto(p *webserverv1.Regexp) (*Regexp, error)

func (*Regexp) GobDecode

func (q *Regexp) GobDecode(data []byte) error

GobDecode implements gob.Decoder.

func (Regexp) GobEncode

func (q Regexp) GobEncode() ([]byte, error)

GobEncode implements gob.Encoder.

func (*Regexp) String

func (q *Regexp) String() string

func (*Regexp) ToProto

func (r *Regexp) ToProto() *webserverv1.Regexp

type Repo

type Repo struct {
	Regexp *regexp.Regexp
}

func RepoFromProto

func RepoFromProto(p *webserverv1.Repo) (*Repo, error)

func (*Repo) GobDecode

func (q *Repo) GobDecode(data []byte) error

func (Repo) GobEncode

func (q Repo) GobEncode() ([]byte, error)

func (*Repo) String

func (q *Repo) String() string

func (*Repo) ToProto

func (q *Repo) ToProto() *webserverv1.Repo

type RepoIDs

type RepoIDs struct {
	Repos *roaring.Bitmap
}

Similar to BranchRepos but will be used to match only by repoid and therefore matches all branches

func NewRepoIDs

func NewRepoIDs(ids ...uint32) *RepoIDs

NewRepoIDs is a helper for creating a RepoIDs which searches only the matched repos.

func RepoIDsFromProto

func RepoIDsFromProto(p *webserverv1.RepoIds) (*RepoIDs, error)

func (*RepoIDs) String

func (q *RepoIDs) String() string

func (*RepoIDs) ToProto

func (q *RepoIDs) ToProto() *webserverv1.RepoIds

type RepoRegexp

type RepoRegexp struct {
	Regexp *regexp.Regexp
}

RepoRegexp is a Sourcegraph addition which searches documents where the repository name matches Regexp.

func RepoRegexpFromProto

func RepoRegexpFromProto(p *webserverv1.RepoRegexp) (*RepoRegexp, error)

func (*RepoRegexp) GobDecode

func (q *RepoRegexp) GobDecode(data []byte) error

GobDecode implements gob.Decoder.

func (*RepoRegexp) GobEncode

func (q *RepoRegexp) GobEncode() ([]byte, error)

GobEncode implements gob.Encoder.

func (*RepoRegexp) String

func (q *RepoRegexp) String() string

func (*RepoRegexp) ToProto

func (q *RepoRegexp) ToProto() *webserverv1.RepoRegexp

type RepoSet

type RepoSet struct {
	Set map[string]bool
}

RepoSet is a list of repos to match. It is a Sourcegraph addition and only used in the RPC interface for efficient checking of large repo lists.

func NewRepoSet

func NewRepoSet(repo ...string) *RepoSet

func RepoSetFromProto

func RepoSetFromProto(p *webserverv1.RepoSet) *RepoSet

func (*RepoSet) String

func (q *RepoSet) String() string

func (*RepoSet) ToProto

func (q *RepoSet) ToProto() *webserverv1.RepoSet

type Substring

type Substring struct {
	Pattern       string
	CaseSensitive bool

	// Match only filename
	FileName bool

	// Match only content
	Content bool
}

Substring is the most basic query: a query for a substring.

func SubstringFromProto

func SubstringFromProto(p *webserverv1.Substring) *Substring

func (*Substring) String

func (q *Substring) String() string

func (*Substring) ToProto

func (q *Substring) ToProto() *webserverv1.Substring

type Symbol

type Symbol struct {
	Expr Q
}

Symbol finds a string that is a symbol.

func SymbolFromProto

func SymbolFromProto(p *webserverv1.Symbol) (*Symbol, error)

func (*Symbol) String

func (s *Symbol) String() string

func (*Symbol) ToProto

func (s *Symbol) ToProto() *webserverv1.Symbol

type Type

type Type struct {
	Child Q
	Type  uint8
}

Type changes the result type returned.

func TypeFromProto

func TypeFromProto(p *webserverv1.Type) (*Type, error)

func (*Type) String

func (q *Type) String() string

func (*Type) ToProto

func (q *Type) ToProto() *webserverv1.Type

Jump to

Keyboard shortcuts

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