Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
Rename 'keyword' patterntype to 'codyContext' (#59529)
Browse files Browse the repository at this point in the history
This renames the experimental `keyword` pattern type to `codyContext` to
clarify its use case, and to distinguish it from the  "keyword search" project.
It also updates some internal naming (packages, methods, etc.)
  • Loading branch information
jtibshirani authored Jan 12, 2024
1 parent 0fb3fc2 commit 6dd737f
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 46 deletions.
4 changes: 2 additions & 2 deletions internal/codycontext/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,11 @@ func (c *CodyContextClient) getKeywordContext(ctx context.Context, args GetConte
ctx, cancel := context.WithCancel(ctx)
defer cancel()

patternTypeKeyword := "keyword"
patternType := "codyContext"
plan, err := c.searchClient.Plan(
ctx,
"V3",
&patternTypeKeyword,
&patternType,
query,
search.Precise,
search.Streaming,
Expand Down
8 changes: 4 additions & 4 deletions internal/search/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ func SearchTypeFromString(patternType string) (query.SearchType, error) {
return query.SearchTypeStructural, nil
case "lucky":
return query.SearchTypeLucky, nil
case "keyword":
return query.SearchTypeKeyword, nil
case "codyContext":
return query.SearchTypeCodyContext, nil
case "newStandardRC1":
return query.SearchTypeNewStandardRC1, nil
default:
Expand Down Expand Up @@ -295,8 +295,8 @@ func overrideSearchType(input string, searchType query.SearchType) query.SearchT
searchType = query.SearchTypeStructural
case "lucky":
searchType = query.SearchTypeLucky
case "keyword":
searchType = query.SearchTypeKeyword
case "codyContext":
searchType = query.SearchTypeCodyContext
case "newStandardRC1":
searchType = query.SearchTypeNewStandardRC1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ load("//dev:go_defs.bzl", "go_test")
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "keyword",
name = "codycontext",
srcs = [
"keyword_search_job.go",
"job.go",
"query_transformer.go",
"stop_words.go",
"string_set.go",
"term_utils.go",
],
importpath = "github.com/sourcegraph/sourcegraph/internal/search/keyword",
importpath = "github.com/sourcegraph/sourcegraph/internal/search/codycontext",
visibility = ["//:__subpackages__"],
deps = [
"//internal/search",
Expand All @@ -24,10 +24,9 @@ go_library(
)

go_test(
name = "keyword_test",
timeout = "short",
name = "codycontext_test",
srcs = ["query_transformer_test.go"],
embed = [":keyword"],
embed = [":codycontext"],
deps = [
"//internal/search/query",
"@com_github_hexops_autogold_v2//:autogold",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package keyword
package codycontext

import (
"context"
Expand All @@ -12,40 +12,40 @@ import (
"github.com/sourcegraph/sourcegraph/lib/errors"
)

func NewKeywordSearchJob(plan query.Plan, newJob func(query.Basic) (job.Job, error)) (job.Job, error) {
func NewSearchJob(plan query.Plan, newJob func(query.Basic) (job.Job, error)) (job.Job, error) {
if len(plan) > 1 {
return nil, errors.New("The 'keyword' patterntype does not support multiple clauses")
return nil, errors.New("The 'codyContext' patterntype does not support multiple clauses")
}

keywordQuery, err := basicQueryToKeywordQuery(plan[0])
if err != nil || keywordQuery == nil {
q, err := transformBasicQuery(plan[0])
if err != nil || q == nil {
return nil, err
}

child, err := newJob(keywordQuery.query)
child, err := newJob(q.query)
if err != nil {
return nil, err
}
return &keywordSearchJob{child: child, patterns: keywordQuery.patterns}, nil
return &searchJob{child: child, patterns: q.patterns}, nil
}

type keywordSearchJob struct {
type searchJob struct {
child job.Job
patterns []string
}

func (j *keywordSearchJob) Run(ctx context.Context, clients job.RuntimeClients, stream streaming.Sender) (alert *search.Alert, err error) {
func (j *searchJob) Run(ctx context.Context, clients job.RuntimeClients, stream streaming.Sender) (alert *search.Alert, err error) {
_, ctx, stream, finish := job.StartSpan(ctx, stream, j)
defer func() { finish(alert, err) }()

return j.child.Run(ctx, clients, stream)
}

func (j *keywordSearchJob) Name() string {
func (j *searchJob) Name() string {
return "KeywordSearchJob"
}

func (j *keywordSearchJob) Attributes(v job.Verbosity) (res []attribute.KeyValue) {
func (j *searchJob) Attributes(v job.Verbosity) (res []attribute.KeyValue) {
switch v {
case job.VerbosityMax:
fallthrough
Expand All @@ -57,11 +57,11 @@ func (j *keywordSearchJob) Attributes(v job.Verbosity) (res []attribute.KeyValue
return res
}

func (j *keywordSearchJob) Children() []job.Describer {
func (j *searchJob) Children() []job.Describer {
return []job.Describer{j.child}
}

func (j *keywordSearchJob) MapChildren(fn job.MapFunc) job.Job {
func (j *searchJob) MapChildren(fn job.MapFunc) job.Job {
cp := *j
cp.child = job.Map(j.child, fn)
return &cp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package keyword
package codycontext

import (
"strings"
Expand Down Expand Up @@ -140,6 +140,6 @@ func queryStringToKeywordQuery(queryString string) (*keywordQuery, error) {
return &keywordQuery{newBasic, transformedPatterns}, nil
}

func basicQueryToKeywordQuery(basicQuery query.Basic) (*keywordQuery, error) {
func transformBasicQuery(basicQuery query.Basic) (*keywordQuery, error) {
return queryStringToKeywordQuery(query.StringHuman(basicQuery.ToParseTree()))
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package keyword
package codycontext

import (
"testing"
Expand Down Expand Up @@ -79,16 +79,16 @@ func TestQueryStringToKeywordQuery(t *testing.T) {

for _, tt := range tests {
t.Run(tt.query, func(t *testing.T) {
keywordQuery, err := queryStringToKeywordQuery(tt.query)
q, err := queryStringToKeywordQuery(tt.query)
if err != nil {
t.Fatal(err)
}
if keywordQuery == nil {
t.Fatal("keywordQuery == nil")
if q == nil {
t.Fatal("q == nil")
}

tt.wantPatterns.Equal(t, keywordQuery.patterns)
tt.wantQuery.Equal(t, query.StringHuman(keywordQuery.query.ToParseTree()))
tt.wantPatterns.Equal(t, q.patterns)
tt.wantQuery.Equal(t, query.StringHuman(q.query.ToParseTree()))
})
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package keyword
package codycontext

// A large set of stopwords, taken from the ATIRE list here: https://github.com/igorbrigadir/stopwords/tree/master.
var stopWords = stringSet{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package keyword
package codycontext

type stringSet map[string]struct{}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package keyword
package codycontext

import (
"strings"
Expand Down
2 changes: 1 addition & 1 deletion internal/search/job/jobutil/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ go_library(
"//internal/own/search",
"//internal/search",
"//internal/search/alert",
"//internal/search/codycontext",
"//internal/search/commit",
"//internal/search/filter",
"//internal/search/job",
"//internal/search/keyword",
"//internal/search/limits",
"//internal/search/query",
"//internal/search/repos",
Expand Down
6 changes: 3 additions & 3 deletions internal/search/job/jobutil/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
"github.com/sourcegraph/sourcegraph/internal/conf"
ownsearch "github.com/sourcegraph/sourcegraph/internal/own/search"
"github.com/sourcegraph/sourcegraph/internal/search"
"github.com/sourcegraph/sourcegraph/internal/search/codycontext"
"github.com/sourcegraph/sourcegraph/internal/search/commit"
"github.com/sourcegraph/sourcegraph/internal/search/filter"
"github.com/sourcegraph/sourcegraph/internal/search/job"
"github.com/sourcegraph/sourcegraph/internal/search/keyword"
"github.com/sourcegraph/sourcegraph/internal/search/limits"
"github.com/sourcegraph/sourcegraph/internal/search/query"
searchrepos "github.com/sourcegraph/sourcegraph/internal/search/repos"
Expand Down Expand Up @@ -45,12 +45,12 @@ func NewPlanJob(inputs *search.Inputs, plan query.Plan) (job.Job, error) {
return NewBasicJob(inputs, b)
}

if inputs.PatternType == query.SearchTypeKeyword {
if inputs.PatternType == query.SearchTypeCodyContext {
if inputs.SearchMode == search.SmartSearch {
return nil, errors.New("The 'keyword' patterntype is not compatible with Smart Search")
}

newJobTree, err := keyword.NewKeywordSearchJob(plan, newJob)
newJobTree, err := codycontext.NewSearchJob(plan, newJob)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/search/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func SubstituteSearchContexts(lookupQueryString func(contextValue string) (strin
func For(searchType SearchType) step {
var processType step
switch searchType {
case SearchTypeStandard, SearchTypeLucky, SearchTypeKeyword:
case SearchTypeStandard, SearchTypeLucky, SearchTypeCodyContext:
processType = succeeds(substituteConcat(standard))
case SearchTypeLiteral:
processType = succeeds(substituteConcat(space))
Expand Down
6 changes: 3 additions & 3 deletions internal/search/query/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const (
SearchTypeStructural
SearchTypeLucky
SearchTypeStandard
SearchTypeKeyword
SearchTypeCodyContext
SearchTypeNewStandardRC1
)

Expand All @@ -55,8 +55,8 @@ func (s SearchType) String() string {
return "structural"
case SearchTypeLucky:
return "lucky"
case SearchTypeKeyword:
return "keyword"
case SearchTypeCodyContext:
return "codyContext"
case SearchTypeNewStandardRC1:
return "newStandardRC1"
default:
Expand Down
2 changes: 1 addition & 1 deletion internal/search/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (o *ZoektParameters) ToSearchOptions(ctx context.Context) (searchOpts *zoek
Trace: policy.ShouldTrace(ctx),
MaxWallTime: defaultTimeout,
ChunkMatches: true,
UseKeywordScoring: o.PatternType == query.SearchTypeKeyword,
UseKeywordScoring: o.PatternType == query.SearchTypeCodyContext,
NumContextLines: o.NumContextLines,
}

Expand Down
2 changes: 1 addition & 1 deletion internal/search/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func TestZoektParameters(t *testing.T) {
context: context.Background(),
params: &ZoektParameters{
FileMatchLimit: limits.DefaultMaxSearchResultsStreaming,
PatternType: query.SearchTypeKeyword,
PatternType: query.SearchTypeCodyContext,
},
want: &zoekt.SearchOptions{
ShardMaxMatchCount: 100000,
Expand Down

0 comments on commit 6dd737f

Please sign in to comment.