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

Nested query doesn't return results #330

Open
bjarnef opened this issue Feb 24, 2023 · 3 comments
Open

Nested query doesn't return results #330

bjarnef opened this issue Feb 24, 2023 · 3 comments

Comments

@bjarnef
Copy link
Contributor

bjarnef commented Feb 24, 2023

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:

image

but not mapped to ISearchResults:

image

when I comment this part I get results:

image

Umbraco v10.4.0
Examine v3.0.1

@bjarnef
Copy link
Contributor Author

bjarnef commented Mar 1, 2023

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.

@Shazwazza
Copy link
Owner

Any chance you can create a test in the FluentApiTests to replicate?

@bjarnef
Copy link
Contributor Author

bjarnef commented May 4, 2023

@Shazwazza I have made an attempt to add test case in #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);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants