Skip to content

Commit

Permalink
added changes to fix the client run search (#7076)
Browse files Browse the repository at this point in the history
* added changes to fix the client run search

Signed-off-by: Vinay Sharma <vsharma@chef.io>

* added changes to fix the node name search for compliance

Signed-off-by: Vinay Sharma <vsharma@chef.io>
  • Loading branch information
vinay033 committed May 27, 2022
1 parent 4c81571 commit b6c72c8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 24 deletions.
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

0 comments on commit b6c72c8

Please sign in to comment.