-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
Do not add empty query #296
Conversation
LGTM. Could you update the Changelog.md? |
@hulkur @hkulekci This PR changes observable behavior which typically requires a major version bump. However, since I can't identify any realistic scenarios where this would break existing implementations, a PATCH bump should suffice. Do you see any potential breaking changes that would warrant a major version bump? |
@hulkur @matchish To understand the problem lets prepare a sample. Even we can put these samples into test cases. It would be better. This is the current behaviour: public function test_where_clauses_are_added_to_query_2(): void
{
$builder = new Builder(new Product(), '*');
$search = SearchFactory::create($builder);
$this->assertInstanceOf(BoolQuery::class, $search->getQueries());
$this->assertEquals(
[
'query_string' => [
'query' => '*',
],
],
$search->getQueries()->toArray()
);
} Our expectation is to remove the query string from here. I just apply your changes and write this test: public function test_where_clauses_are_added_to_query_3(): void
{
$builder = new Builder(new Product(), '');
$search = SearchFactory::create($builder);
$this->assertNull($search->getQueries());
$this->assertEmpty($search->toArray());
} To achieve this, we need to send an empty string to the builder. However, this behavior hides this feature. Instead of sending an empty string, we need to make it nullable. So, this change could be a BC break or not. It wont break anything but also change the behaviour. Lastly, we can even remove the query string if we have a where query and with empty string. The test will change from public function test_where_clauses_are_added_to_query(): void
{
$builder = new Builder(new Product(), '*');
$builder->where('price', 100);
$search = SearchFactory::create($builder);
$this->assertNotEmpty($search);
$this->assertInstanceOf(BoolQuery::class, $search->getQueries());
$this->assertEquals(
[
'bool' => [
'filter' => [
[
'term' => ['price' => 100]
]
],
'must' => [
[
'query_string' => [
'query' => '*',
],
],
]
],
],
$search->getQueries()->toArray()
);
} to public function test_where_clauses_are_added_to_query_4(): void
{
$builder = new Builder(new Product(), '');
$builder->where('price', 100);
$search = SearchFactory::create($builder);
$this->assertNotEmpty($search);
$this->assertInstanceOf(BoolQuery::class, $search->getQueries());
$this->assertEquals(
[
'bool' => [
'filter' => [
[
'term' => ['price' => 100]
]
]
],
],
$search->getQueries()->toArray()
);
} As a result, it will improve the quality and change behavior. But we also need to inform users about these behavioral changes. I am not sure it requires a major bump. But could you please put these tests on your PR? |
BTW, these are the results for the tests above with @hulkur changes:
|
In your test you create the Builder directly. |
Could you share how do you add callback after search as I remember scout allow to do it only in search(string, callback) but you are right that's what I meant, do we have some case when we miss querystring and it could break some project code in the callback
|
Builder $callback is public variable, just assign a function. |
Since the compatibility impact is still unclear, I've merged the changes to master but kept them unreleased. These updates will be included in the next major version release. In the meantime, you can access these changes directly from the master branch. |
If there are no
where
clauses thenSearchFactory
adds query string filter even if query string is empty