Skip to content

Commit

Permalink
feat: enable empty text search
Browse files Browse the repository at this point in the history
  • Loading branch information
anjaliagg9791 committed Oct 4, 2023
1 parent ec9201e commit 26df020
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
3 changes: 0 additions & 3 deletions internal/server/v1beta1/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ func (server *APIServer) SearchAssets(ctx context.Context, req *compassv1beta1.S
}

text := strings.TrimSpace(req.GetText())
if text == "" {
return nil, status.Error(codes.InvalidArgument, "'text' must be specified")
}

cfg := asset.SearchConfig{
Text: text,
Expand Down
7 changes: 4 additions & 3 deletions internal/store/elasticsearch/discovery_search_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ var returnedAssetFieldsResult = []string{"id", "urn", "type", "service", "name",

// Search the asset store
func (repo *DiscoveryRepository) Search(ctx context.Context, cfg asset.SearchConfig) (results []asset.SearchResult, err error) {
if strings.TrimSpace(cfg.Text) == "" {
return nil, asset.DiscoveryError{Op: "Search", Err: errors.New("search text cannot be empty")}
}
maxResults := cfg.MaxResults
if maxResults <= 0 {
maxResults = defaultMaxResults
Expand Down Expand Up @@ -233,6 +230,10 @@ func buildSuggestQuery(cfg asset.SearchConfig) (io.Reader, error) {
}

func buildTextQuery(q *elastic.BoolQuery, cfg asset.SearchConfig) {
if strings.TrimSpace(cfg.Text) == "" {
q.Should(elastic.NewMatchAllQuery())
}

boostedFields := []string{"urn^10", "name^5"}
q.Should(
// Phrase query cannot have `FUZZINESS`
Expand Down

0 comments on commit 26df020

Please sign in to comment.