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

Allow the Terms query to accept arrays of strings, ints and floats #1872

Merged
merged 3 commits into from
Nov 20, 2020

Conversation

mfn
Copy link
Contributor

@mfn mfn commented Nov 18, 2020

As shown in #1765 (comment) , ElasticSearch accepts all of them

Note: the change of public function addTerm was not previously discussed, but is made for consistency, however poses a breaking change if someone extended this class previously => https://3v4l.org/Ws5bM

TODO

  • Add changelog
  • Discuss breaking change outcome
  • Provide a functional test

@ruflin
Copy link
Owner

ruflin commented Nov 18, 2020

Did not realise this could be a breaking change but I would argue this one is acceptable as it is actually a bug fix. @thePanz @deguif WDYT?

@mfn Can you add a changelog entry?

@mfn
Copy link
Contributor Author

mfn commented Nov 18, 2020

Can you add a changelog entry?

On it, actually i also would like to provide a test, but need a bit time => moving into draft state!

@mfn mfn marked this pull request as draft November 18, 2020 13:12
@ruflin
Copy link
Owner

ruflin commented Nov 18, 2020

Awesome, thanks!

@mfn
Copy link
Contributor Author

mfn commented Nov 18, 2020

Hmm, a force-push doesn't seem to retrigger the build?

@mfn mfn closed this Nov 18, 2020
@mfn mfn reopened this Nov 18, 2020
@mfn
Copy link
Contributor Author

mfn commented Nov 18, 2020

Re-opening the PR does 😄

@mfn mfn mentioned this pull request Nov 18, 2020
@mfn mfn marked this pull request as ready for review November 18, 2020 14:37
@mfn
Copy link
Contributor Author

mfn commented Nov 18, 2020

@ruflin technically all done / green, only BC break needs be discussed

@mfn
Copy link
Contributor Author

mfn commented Nov 18, 2020

PS: great contributing guide, although I don't have much docker experience, was able to get this easily running and also execute the phpunit tests before pushing, thank you! 👍

@deguif
Copy link
Collaborator

deguif commented Nov 19, 2020

@mfn @ruflin yes this is a BC break, but impact should be very limited.

I'm also wondering if several types can be combined in the same array like mixing string, int and/or float at the same time.

Maybe this can be something like that if types can be mixed:

array<string|int|float>

@mfn
Copy link
Contributor Author

mfn commented Nov 19, 2020

array<string|int|float>

Should be fine; I didn't see any existing array<> syntax in the project so it didn't occur to me. Also wish that would be rather something a code style fix change just do themselves 😅 At least I saw that php-cs did re-order the types I provided 🤷‍♀️

Would probably be judicious to throw an error when type is not accepted?

🤷‍♀️

The existing code base doesn't seem much to use such a pattern, couldn't find any. So I made the change as un-intrusive as possible


I'm not sure if you want me to go ahead and change things, the feedback doesn't seem to much match the existing code base.

I'm happy to change it, just wanted to make sure I don't to unnecessary work, let me know.

Thank you.

@ruflin
Copy link
Owner

ruflin commented Nov 19, 2020

I'm personally comfortable with getting this breaking change in. I'm pretty sure we will have 1-2 users hit by it but I personally would even consider it a bug fix. The 1-2 users that will hit by will hopefully have an IDE in place that tells them there is a problem? In the changelog, lets put it under breaking change to make it more obvious. Or do I miss something here?

No strong preference on my end on the way we put it in. I'm following the guidance of @deguif as he put a lot of effort into unifying the code base recently and probably knows best.

I'm also ok with merging the PR as is and then follow up. @deguif WDYT?

@thePanz
Copy link
Collaborator

thePanz commented Nov 19, 2020

@ruflin I do not see this as a breaking change, as the method, is now accepting a wider range of types.

@mfn
Copy link
Contributor Author

mfn commented Nov 19, 2020

I'm following the guidance of @deguif as he put a lot of effort into unifying the code base recently and probably knows best.

Roger that! Suggestion applied 😄

In the changelog, lets put it under breaking change to make it more obvious.

Also done!

@mfn
Copy link
Contributor Author

mfn commented Nov 19, 2020

@thePanz it's a technical one, see https://3v4l.org/Ws5bM => if someone extended addTerm previously => 💥

{
if (!\is_string($term) && !\is_int($term) && !\is_float($term)) {
throw new TypeError(\sprintf('Argument 1 passed to "%s()" must be of type float|int|string, %s given.', __METHOD__, \is_object($term) ? \get_class($term) : \gettype($term)));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we have a throw new \TypeError to avoid the use of it at the beginning of the class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So what's the rule when to import and when not?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure, IMHO I would try to not import something from the root namespace, but just use \TypeError. WDYT?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes I'm 👍 with @thePanz comment ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@thePanz
Copy link
Collaborator

thePanz commented Nov 19, 2020

@thePanz it's a technical one, see https://3v4l.org/Ws5bM => if someone extended addTerm previously => boom

@mfn you're right! This would open the discussion on making the query classes final, but let's not open the Pandora's vase now :)

/**
* @group functional
*/
public function testVariousDataTypesViaConstructor(): void
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add a mixed test too? Terms('some_numeric_field', ['9876', 1234])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! => testVariousMixedDataTypesViaConstructor

@mfn
Copy link
Contributor Author

mfn commented Nov 19, 2020

All done!

@ruflin ruflin merged commit a323450 into ruflin:master Nov 20, 2020
@ruflin
Copy link
Owner

ruflin commented Nov 20, 2020

Thanks everyone for getting this in with reviews and @mfn for the quick turn arounds on all the changes!

@mfn
Copy link
Contributor Author

mfn commented Nov 20, 2020

\o/

Thank you @ruflin , @deguif and @thePanz !

@mfn mfn deleted the mfn-terms-types branch November 20, 2020 08:21
@romainneutron
Copy link
Contributor

I think it should also accept booleans since elasticsearch accepts those

romainneutron added a commit to romainneutron/Elastica that referenced this pull request Nov 23, 2020
romainneutron added a commit to romainneutron/Elastica that referenced this pull request Nov 23, 2020
@deguif
Copy link
Collaborator

deguif commented Nov 23, 2020

@romainneutron I think you're right.
@mfn would you be able to provide another PR to support boolean?

PS: Sorry. I just see it was already propsed as a bug fix by @romainneutron

romainneutron added a commit to romainneutron/Elastica that referenced this pull request Nov 23, 2020
romainneutron added a commit to romainneutron/Elastica that referenced this pull request Nov 23, 2020
deguif pushed a commit that referenced this pull request Nov 23, 2020
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

Successfully merging this pull request may close these issues.

5 participants