|
|
|
@ -142,7 +142,7 @@ func (b *Indexer) addUpdate(ctx context.Context, batchWriter git.WriteCloserErro |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
if size, err = strconv.ParseInt(strings.TrimSpace(stdout), 10, 64); err != nil { |
|
|
|
|
return fmt.Errorf("Misformatted git cat-file output: %w", err) |
|
|
|
|
return fmt.Errorf("misformatted git cat-file output: %w", err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -233,26 +233,26 @@ func (b *Indexer) Delete(_ context.Context, repoID int64) error { |
|
|
|
|
|
|
|
|
|
// Search searches for files in the specified repo.
|
|
|
|
|
// Returns the matching file-paths
|
|
|
|
|
func (b *Indexer) Search(ctx context.Context, repoIDs []int64, language, keyword string, page, pageSize int, isFuzzy bool) (int64, []*internal.SearchResult, []*internal.SearchResultLanguages, error) { |
|
|
|
|
func (b *Indexer) Search(ctx context.Context, opts *internal.SearchOptions) (int64, []*internal.SearchResult, []*internal.SearchResultLanguages, error) { |
|
|
|
|
var ( |
|
|
|
|
indexerQuery query.Query |
|
|
|
|
keywordQuery query.Query |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if isFuzzy { |
|
|
|
|
phraseQuery := bleve.NewMatchPhraseQuery(keyword) |
|
|
|
|
if opts.IsKeywordFuzzy { |
|
|
|
|
phraseQuery := bleve.NewMatchPhraseQuery(opts.Keyword) |
|
|
|
|
phraseQuery.FieldVal = "Content" |
|
|
|
|
phraseQuery.Analyzer = repoIndexerAnalyzer |
|
|
|
|
keywordQuery = phraseQuery |
|
|
|
|
} else { |
|
|
|
|
prefixQuery := bleve.NewPrefixQuery(keyword) |
|
|
|
|
prefixQuery := bleve.NewPrefixQuery(opts.Keyword) |
|
|
|
|
prefixQuery.FieldVal = "Content" |
|
|
|
|
keywordQuery = prefixQuery |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if len(repoIDs) > 0 { |
|
|
|
|
repoQueries := make([]query.Query, 0, len(repoIDs)) |
|
|
|
|
for _, repoID := range repoIDs { |
|
|
|
|
if len(opts.RepoIDs) > 0 { |
|
|
|
|
repoQueries := make([]query.Query, 0, len(opts.RepoIDs)) |
|
|
|
|
for _, repoID := range opts.RepoIDs { |
|
|
|
|
repoQueries = append(repoQueries, inner_bleve.NumericEqualityQuery(repoID, "RepoID")) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -266,8 +266,8 @@ func (b *Indexer) Search(ctx context.Context, repoIDs []int64, language, keyword |
|
|
|
|
|
|
|
|
|
// Save for reuse without language filter
|
|
|
|
|
facetQuery := indexerQuery |
|
|
|
|
if len(language) > 0 { |
|
|
|
|
languageQuery := bleve.NewMatchQuery(language) |
|
|
|
|
if len(opts.Language) > 0 { |
|
|
|
|
languageQuery := bleve.NewMatchQuery(opts.Language) |
|
|
|
|
languageQuery.FieldVal = "Language" |
|
|
|
|
languageQuery.Analyzer = analyzer_keyword.Name |
|
|
|
|
|
|
|
|
@ -277,12 +277,12 @@ func (b *Indexer) Search(ctx context.Context, repoIDs []int64, language, keyword |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
from := (page - 1) * pageSize |
|
|
|
|
from, pageSize := opts.GetSkipTake() |
|
|
|
|
searchRequest := bleve.NewSearchRequestOptions(indexerQuery, pageSize, from, false) |
|
|
|
|
searchRequest.Fields = []string{"Content", "RepoID", "Language", "CommitID", "UpdatedAt"} |
|
|
|
|
searchRequest.IncludeLocations = true |
|
|
|
|
|
|
|
|
|
if len(language) == 0 { |
|
|
|
|
if len(opts.Language) == 0 { |
|
|
|
|
searchRequest.AddFacet("languages", bleve.NewFacetRequest("Language", 10)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -326,7 +326,7 @@ func (b *Indexer) Search(ctx context.Context, repoIDs []int64, language, keyword |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
searchResultLanguages := make([]*internal.SearchResultLanguages, 0, 10) |
|
|
|
|
if len(language) > 0 { |
|
|
|
|
if len(opts.Language) > 0 { |
|
|
|
|
// Use separate query to go get all language counts
|
|
|
|
|
facetRequest := bleve.NewSearchRequestOptions(facetQuery, 1, 0, false) |
|
|
|
|
facetRequest.Fields = []string{"Content", "RepoID", "Language", "CommitID", "UpdatedAt"} |
|
|
|
|