Is it possible to apply MinimumShouldMatch to more than one group of fields in the 3.0 C# driver? When I write something like the following, it actually groups all the fields into one “should” bucket and applies the MinimumShouldMatch(1) to the whole group:
var compoundSearch = Builders.Search.Compound()
// First group of fields
.Should(Builders.Search.Text(d => d.Field1, “true”))
.Should(Builders.Search.Text(d => d.Field2, “true”))
.MinimumShouldMatch(1)
// Second group of fields
.Should(Builders<Deal>.Search.Text(d => d.Field3, "true"))
.Should(Builders<Deal>.Search.Text(d => d.Field4, "true"))
.MinimumShouldMatch(1);
I think I’ve found a solution. I’m not sure how this will affect performance, but so far it doesn’t seem to have slowed the query down. I found out it’s possible to nest compound searches, so I can do something like this:
var compoundSearch = Builders.Search.Compound()
– First group of fields
.Should(Builders.Search.Text(d => d.Field1, “true”))
.Should(Builders.Search.Text(d => d.Field2, “true”))
.MinimumShouldMatch(1)
– Second compound search as a filter
.Filter(
Builders.Search.Compound()
– Second group of fields
.Should(Builders.Search.Text(d => d.Field3, “true”))
.Should(Builders.Search.Text(d => d.Field4, “true”))
.MinimumShouldMatch(1)
)