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

Fixed | Nested query with bool doesn't work when there is only one MU… #42

Closed
wants to merge 3 commits into from

Conversation

trandangtri
Copy link
Contributor

Related to this bug #32

@saimaz
Copy link
Member

saimaz commented Dec 9, 2015

@trandangtri next time when you do a PR please include a closing comment for a specific issue if there is one. e.g.

Closing #32

@saimaz
Copy link
Member

saimaz commented Dec 9, 2015

@trandangtri please provide a few unit test cases to represent a problem and to make sure our fix works well.

We should test:

  • Case with 1 query in the must condition
  • Case with 1 queries in the should condition
  • Case with 2 queries in the must condition
  • Case with 2 queries in the should condition
  • Case with 1 query in each, must, must_not and should conditions

/**
* Tests toArray method.
*/
public function testToArray()
{
$missingFilterMock = $this->getMockBuilder('ONGR\ElasticsearchDSL\Filter\MissingFilter')
->setConstructorArgs(['test_field'])
->getMock();
->setConstructorArgs(['test_field'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not look like intentional changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automatic reformatting code in my IDE. I turned off.

@trandangtri
Copy link
Contributor Author

Hi guys,

My fix failed in an old test case. But in my opinion, that test case is not good enough. Look at:

https://github.com/ongr-io/ElasticsearchDSL/blob/master/tests/Query/BoolQueryTest.php#L75

The expected result is

$expected = [
    'should'   => [
        [
            'term' => [
                'key1' => 'value1',
            ],
        ],
    ],
    'must'     => [
        [
            'term' => [
                'key2' => 'value2',
            ],
        ],
    ],
    'must_not' => [
        [
            'term' => [
                'key3' => 'value3',
            ],
        ],
    ],
];

But it should be like this

$expected = [
    'should'   => [
        'term' => [
            'key1' => 'value1',
        ],
    ],
    'must'     => [
        'term' => [
            'key2' => 'value2',
        ],
    ],
    'must_not' => [
        'term' => [
            'key3' => 'value3',
        ],
    ],
];

Please take on a look on the official document of ES Bool Query and their example.

So I do suggest that we should update the old test case.

@murnieza
Copy link
Contributor

murnieza commented Dec 9, 2015

Actually both cases are valid, because you can have either array of term queries or single query.

I do not see any problems with changing old tests as building logic is changing.

@trandangtri
Copy link
Contributor Author

@murnieza, yes, both of them will work well with ES, but the output of toArray() method has one result. That's why I want to update the expected result of the old test case, because currently it's not the best.

@trandangtri
Copy link
Contributor Author

I reverted my work. Now we will always keep the array structure of term query in the output of toArray. With that way, we don't need to change the old test case.

@@ -111,7 +111,13 @@ public function toArray()
$mustContainer = $this->container[self::MUST];
$query = array_shift($mustContainer);

return [$query->getType() => $query->toArray()];
if ($query->getType() == 'match') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't fix the bug. The match query is just like an example of any query. This bug occurs on all other queries also.

@saimaz
Copy link
Member

saimaz commented Dec 16, 2015

For the test cases please write a data provider, don't need to duplicate the same check in each test case. btw, when you will use data provider please include in addition also different queries/filters, not only match. Match query was like an example of query, the bug occurs on any query or filter.

@saimaz saimaz added the wontfix label Dec 16, 2015
@saimaz
Copy link
Member

saimaz commented Dec 24, 2015

fixed in #51

@saimaz saimaz closed this Dec 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants