query

package
v0.0.0-...-b199f39 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

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) *proto.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 *proto.And) (*And, error)

func (*And) String

func (q *And) String() string

func (*And) ToProto

func (q *And) ToProto() *proto.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 *proto.Boost) (*Boost, error)

func (*Boost) String

func (q *Boost) String() string

func (*Boost) ToProto

func (q *Boost) ToProto() *proto.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 *proto.Branch) *Branch

func (*Branch) String

func (q *Branch) String() string

func (*Branch) ToProto

func (q *Branch) ToProto() *proto.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 *proto.BranchRepos) (BranchRepos, error)

func (*BranchRepos) ToProto

func (br *BranchRepos) ToProto() *proto.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 *proto.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() *proto.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 ExperimentalPhraseBoostOptions

type ExperimentalPhraseBoostOptions struct {
	// The phrase needs to contain atleast this many terms. This is based on the
	// parsed query.
	//
	// Defaults to 3.
	MinTerms int

	// Boost is how much to multiply the phrase match scores by.
	//
	// Defaults to 20.
	Boost float64
}

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 *proto.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() *proto.FileNameSet

func (*FileNameSet) UnmarshalBinary

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

UnmarshalBinary implements a specialized decoder for FileNameSet.

type GobCache

type GobCache struct {
	Q
	// contains filtered or unexported fields
}

GobCache exists so we only pay the cost of marshalling a query once when we aggregate it out over all the replicas.

Our query and eval layer do not support GobCache. Instead, at the gob boundaries (RPC and Streaming) we check if the Q is a GobCache and unwrap it.

"I wish we could get rid of this code soon enough" - tomas

func (*GobCache) GobDecode

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

GobDecode implements gob.Decoder.

func (*GobCache) GobEncode

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

GobEncode implements gob.Encoder.

func (*GobCache) String

func (q *GobCache) String() string

type Language

type Language struct {
	Language string
}

func LanguageFromProto

func LanguageFromProto(p *proto.Language) *Language

func (*Language) String

func (l *Language) String() string

func (*Language) ToProto

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

type Not

type Not struct {
	Child Q
}

Not inverts the meaning of its child.

func NotFromProto

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

func (*Not) String

func (q *Not) String() string

func (*Not) ToProto

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

type Or

type Or struct {
	Children []Q
}

Or is matched when any of its children is matched.

func OrFromProto

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

func (*Or) String

func (q *Or) String() string

func (*Or) ToProto

func (q *Or) ToProto() *proto.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 ExpirementalPhraseBoost

func ExpirementalPhraseBoost(q Q, phrase string, opts ExperimentalPhraseBoostOptions) Q

ExperimentalPhraseBoost transforms q into a query containing exact matches to phrase boosted. opts control how and when the boosting is done.

Note: This is a temporary API and will be removed in future commits.

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 *proto.Q) (Q, error)

func RPCUnwrap

func RPCUnwrap(q Q) Q

RPCUnwrap processes q to remove RPC specific elements from q. This is needed because gob isn't flexible enough for us. This should be called by RPC servers at the client/server boundary so that q works with the rest of zoekt.

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 *proto.RawConfig) (res RawConfig)

func (RawConfig) String

func (r RawConfig) String() string

func (RawConfig) ToProto

func (r RawConfig) ToProto() *proto.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 *proto.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() *proto.Regexp

type Repo

type Repo struct {
	Regexp *regexp.Regexp
}

func RepoFromProto

func RepoFromProto(p *proto.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() *proto.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 *proto.RepoIds) (*RepoIDs, error)

func (*RepoIDs) String

func (q *RepoIDs) String() string

func (*RepoIDs) ToProto

func (q *RepoIDs) ToProto() *proto.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 *proto.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() *proto.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 *proto.RepoSet) *RepoSet

func (*RepoSet) String

func (q *RepoSet) String() string

func (*RepoSet) ToProto

func (q *RepoSet) ToProto() *proto.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 *proto.Substring) *Substring

func (*Substring) String

func (q *Substring) String() string

func (*Substring) ToProto

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

type Symbol

type Symbol struct {
	Expr Q
}

Symbol finds a string that is a symbol.

func SymbolFromProto

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

func (*Symbol) String

func (s *Symbol) String() string

func (*Symbol) ToProto

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

type Type

type Type struct {
	Child Q
	Type  uint8
}

Type changes the result type returned.

func TypeFromProto

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

func (*Type) String

func (q *Type) String() string

func (*Type) ToProto

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

Jump to

Keyboard shortcuts

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