mongodb-labs / mongo-csharp-search

C# driver extension providing support for Atlas Search
Apache License 2.0
17 stars 1 forks source link

search question #15

Open ghendo opened 2 years ago

ghendo commented 2 years ago

I am trying to implement the following query but having trouble This is the query

{ "$search" : { "compound":{ "filter" : { "compound":{ "should" : [ { "autocomplete" : { "query" : ["john"], "path" : "site.name"} }, { "autocomplete" : { "query" : ["john"], "path" : "site.client.onsiteClientName" } }, { "autocomplete" : { "query" : ["john"], "path" : "subContractor.companyName" } }, { "autocomplete" : { "query" : ["john"], "path" : "supervisor.givenName"} } ], "minimumShouldMatch" : 1 }}, "must" : [ { "near" : { "path" : "startTime", "origin" : ISODate("1000-12-31T23:59:59.999Z"), "pivot" : 1 } }], }} }

This is what I tried

var pipelineData = pipeline .Search(SearchBuilders<T>.Search.Compound() .Filter(SearchBuilders<T>.Search.Compound() .Should(searches).MinimumShouldMatch(minShouldMatch) .Must(nearFilter)), null, "JobAutoV2")

where searches is array of autocompletes

and nearfilter is var nearFilter = new SearchDefinitionBuilder().Near(sortField, new DateTime(1100,12,31), 60000);

but I feel this is wrong

dgolub commented 2 years ago

That looks like it should be right. Is it not returning the correct results for you?

ghendo commented 2 years ago

I wanted the results sorted highest date first to lowest date

dgolub commented 2 years ago

You should be able to get that by adding a $sort stage after the $search stage.