Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added changes to fix the client run search #7076

Merged
merged 2 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions components/compliance-service/reporting/relaxting/suggestions.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,24 @@ func (backend ES2Backend) getAggSuggestions(ctx context.Context, client *elastic
lowerText := strings.ToLower(text)

if len(text) >= 2 {
// Any(or) of the text words can match
matchQuery := elastic.NewMatchQuery(fmt.Sprintf("%s.engram", target), text).Operator("or")
boolQuery = boolQuery.Must(matchQuery)
// All(or) of the text words need to match to get a score boost from this condition
matchQuery = elastic.NewMatchQuery(fmt.Sprintf("%s.engram", target), text).Operator("and")
boolQuery = boolQuery.Should(matchQuery)
// Give a score boost to values that equal the suggested text
termQuery := elastic.NewTermQuery(fmt.Sprintf("%s.lower", target), lowerText).Boost(100)
boolQuery = boolQuery.Should(termQuery)
// Give a score boost to values that start with the suggested text
prefixQuery := elastic.NewPrefixQuery(fmt.Sprintf("%s.lower", target), lowerText).Boost(100)
boolQuery = boolQuery.Should(prefixQuery)
if target == "node_name" {
text_string := "*" + lowerText + "*"
matchQuery := elastic.NewQueryStringQuery(text_string).Field(target)
boolQuery = boolQuery.Must(matchQuery)
} else {
// Any(or) of the text words can match
matchQuery := elastic.NewMatchQuery(fmt.Sprintf("%s.engram", target), text).Operator("or")
boolQuery = boolQuery.Must(matchQuery)
// All(or) of the text words need to match to get a score boost from this condition
matchQuery = elastic.NewMatchQuery(fmt.Sprintf("%s.engram", target), text).Operator("and")
boolQuery = boolQuery.Should(matchQuery)
// Give a score boost to values that equal the suggested text
termQuery := elastic.NewTermQuery(fmt.Sprintf("%s.lower", target), lowerText).Boost(100)
boolQuery = boolQuery.Should(termQuery)
// Give a score boost to values that start with the suggested text
prefixQuery := elastic.NewPrefixQuery(fmt.Sprintf("%s.lower", target), lowerText).Boost(100)
boolQuery = boolQuery.Should(prefixQuery)
}
}
// Create a term aggregation in order to group all the documents that have the same
// value and order by score. This is important for suggestions accuracy
Expand Down
30 changes: 18 additions & 12 deletions components/config-mgmt-service/backend/elastic/suggestions.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,24 @@ func (es Backend) getAggSuggestions(term string, text string, filters map[string

// return all unless text has at least 2 chars
if len(text) >= 2 {
// Any(or) of the text words can match
matchQuery := elastic.NewMatchQuery(fmt.Sprintf("%s.engram", term), text).Operator("or")
boolQuery = boolQuery.Must(matchQuery)
// All(or) of the text words need to match to get a score boost from this condition
matchQuery = elastic.NewMatchQuery(fmt.Sprintf("%s.engram", term), text).Operator("and")
boolQuery = boolQuery.Must(matchQuery)
// Give a score boost to values that equal the suggested text
termQuery := elastic.NewTermQuery(fmt.Sprintf("%s.lower", term), lowerText).Boost(200)
boolQuery = boolQuery.Should(termQuery)
// Give a score boost to values that start with the suggested text
prefixQuery := elastic.NewPrefixQuery(fmt.Sprintf("%s.lower", term), lowerText).Boost(100)
boolQuery = boolQuery.Should(prefixQuery)
if term == "node_name" {
text_string := "*" + lowerText + "*"
matchQuery := elastic.NewQueryStringQuery(text_string).Field(term)
boolQuery = boolQuery.Must(matchQuery)
} else {
// Any(or) of the text words can match
matchQuery := elastic.NewMatchQuery(fmt.Sprintf("%s.engram", term), text).Operator("or")
boolQuery = boolQuery.Must(matchQuery)
// All(or) of the text words need to match to get a score boost from this condition
matchQuery = elastic.NewMatchQuery(fmt.Sprintf("%s.engram", term), text).Operator("and")
boolQuery = boolQuery.Must(matchQuery)
// Give a score boost to values that equal the suggested text
termQuery := elastic.NewTermQuery(fmt.Sprintf("%s.lower", term), lowerText).Boost(200)
boolQuery = boolQuery.Should(termQuery)
// Give a score boost to values that start with the suggested text
prefixQuery := elastic.NewPrefixQuery(fmt.Sprintf("%s.lower", term), lowerText).Boost(100)
boolQuery = boolQuery.Should(prefixQuery)
}
}
//aggs
aggs := elastic.NewTermsAggregation().Field(term).Size(SuggestionQuerySize).Order("mymaxscore", false)
Expand Down