Examine
Examine copied to clipboard
Nested query doesn't return results
We have a query builder constructing a nested query, so value of registration deadline or end date need to be between DateTime.Now and DateTime.MaxValue.
if (_hasEnded.HasValue && _hasEnded.Value == false)
{
query.And().Group(x =>
{
return x.RangeQuery<DateTime>(new[]
{
Constants.Examine.CourseInstance.FieldNames.RegistrationDeadline
}, DateTime.Now, DateTime.MaxValue)
.Or()
.RangeQuery<DateTime>(new[]
{
Constants.Examine.CourseInstance.FieldNames.EndDate
}, DateTime.Now, DateTime.MaxValue);
});
}
this has been simplified a bit.
which generates a Lucene query like:
+__IndexType:courseinstance +hideFromSearch:0 +(categoryID:42291) +isCancelled:0 +((registrationDeadline:[638128410874010000 TO 3155378975999990000]) (endDate:[638128410874010000 TO 3155378975999990000])) +(categoryID:42291) +isCancelled:0 +((registrationDeadline:[638128411018970000 TO 3155378975999990000]) (endDate:[638128411018970000 TO 3155378975999990000]))
The raw query executed in Examine dashboard shows results:

but not mapped to ISearchResults:

when I comment this part I get results:

Umbraco v10.4.0 Examine v3.0.1
I had another scenario in same project, where I did this:
query.And().Group(x =>
{
// Start with a range query for first duration range.
var inner = x.RangeQuery<double>(durationFields, first.Min ?? 0, first.Max ?? double.MaxValue);
// Create a range query and OR operation for each duration.
foreach (var duration in _durations.Skip(1))
{
inner.Or().RangeQuery<double>(durationFields,
duration.Min ?? 0,
duration.Max ?? double.MaxValue);
}
return inner;
});
where durations variable is List<NumberRange and NumberRange defined as:
public class NumberRange
{
public NumberRange() { }
public NumberRange(int? min, int? max)
{
Min = min;
Max = max;
}
public int? Min { get; set; }
public int? Max { get; set; }
}
I think it would be great it the docs showed a few example of nested queries using .Group() where input is INestedQuery and output is INestedBooleanOperation.
Any chance you can create a test in the FluentApiTests to replicate?
@Shazwazza I have made an attempt to add test case in https://github.com/Shazwazza/Examine/pull/334
In the specific project I used the NumberRange class as mentioned, but not sure we want to include that, so I just used a dictionary for now.
The test case is the one which should work, but originally something like this didn't seem to work:
query.And().Group(x =>
{
return x.RangeQuery<DateTime>(new[]
{
Constants.Examine.CourseInstance.FieldNames.RegistrationDeadline
}, DateTime.Now, DateTime.MaxValue)
.Or()
.RangeQuery<DateTime>(new[]
{
Constants.Examine.CourseInstance.FieldNames.EndDate
}, DateTime.Now, DateTime.MaxValue);
});