query

package
v0.0.0-...-631dced Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

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 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 (*And) String

func (q *And) String() string

type Boost

type Boost struct {
	Child Q
	// Boost will multiply the score of its descendants. 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 descendants.

func (*Boost) String

func (q *Boost) String() string

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 (*Branch) String

func (q *Branch) String() string

type BranchRepos

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

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

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 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) 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 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) UnmarshalBinary

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

UnmarshalBinary implements a specialized decoder for FileNameSet.

type Language

type Language struct {
	Language string
}

func (*Language) String

func (l *Language) String() string

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 (*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 (*Not) String

func (q *Not) String() string

type Or

type Or struct {
	Children []Q
}

Or is matched when any of its children is matched.

func (*Or) String

func (q *Or) String() string

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 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 (RawConfig) String

func (r RawConfig) String() string

type Regexp

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

RegexpQuery is a query looking for regular expressions matches.

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

type Repo

type Repo struct {
	Regexp *regexp.Regexp
}

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

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 (*RepoIDs) String

func (q *RepoIDs) String() string

type RepoRegexp

type RepoRegexp struct {
	Regexp *regexp.Regexp
}

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

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

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 (*RepoSet) String

func (q *RepoSet) String() string

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 (*Substring) String

func (q *Substring) String() string

type Symbol

type Symbol struct {
	Expr Q
}

Symbol finds a string that is a symbol.

func (*Symbol) String

func (s *Symbol) String() string

type Type

type Type struct {
	Child Q
	Type  uint8
}

Type changes the result type returned.

func (*Type) String

func (q *Type) String() string

Jump to

Keyboard shortcuts

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