-
Notifications
You must be signed in to change notification settings - Fork 732
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
1963 - support multiple direct_generators #1964
1963 - support multiple direct_generators #1964
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution. Could you also add a test and a changelog entry?
Also see comment from @deguif
…astica\Suggest\Phrase::addDirectGenerator; Update \Elastica\Suggest\CandidateGenerator\DirectGenerator::toArray so the generator can be included in a direct_generator list; Update CHANGELOG.md
@deguif I added the new method and deprecated the old one since it was a bit confusing to use. The toArray trick was required by @ruflin I updated the changelog. When do you think you could include this in a patch version? Thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @sergiuionescu for your work.
Some new comments related to how we handle deprecations.
Another one related to toArray
change that can probably be done another way more standard.
public function toArray() | ||
{ | ||
$data = $this->getParams(); | ||
|
||
if (!empty($this->_rawParams)) { | ||
$data = \array_merge($data, $this->_rawParams); | ||
} | ||
|
||
return $this->_convertArrayable($data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementing NameableInterface here should do the trick and avoid customizing the toArray()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@deguif Thanks for suggesting the changes and align this with the future changes for the lib.
I do not see how implementing NameableInterface will do the trick here. The handling for that interface is:
$arr[$value instanceof NameableInterface ? $value->getName() : $key] = $value->toArray();
So we will still get a map with the "direct_generator" name and params, instead of a list of direct_generator's params.
We are looking to get
{
"suggest": {
"text": "obel prize",
"simple_phrase": {
"phrase": {
"field": "title.trigram",
"size": 1,
"direct_generator": [
{
"field": "title.trigram",
"suggest_mode": "always"
},
{
"field": "title.reverse",
"suggest_mode": "always",
"pre_filter": "reverse",
"post_filter": "reverse"
}
]
}
}
}
}
I think the override is the more transparent approach. Am i missing something with the NameableInterface, do you have an example where that is used to build a list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're absolutely right here.
NameableInterface is not handled correctly for list.
In this case I must admit, the first trick, overriding the toArray
method of Phrase is probably the most adapted choice (and certainly kind of why it was done this way).
Overriding the toArray
method of DirectGenerator to only return its parameters without its name would be a BC break.
I'm sorry for the noise my previous comment introduced regarding NameableInterface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@deguif Please run the tests whenever possible, i reverted to the \Elastica\Suggest\Phrase::toArray
override.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes done again, I did it this morning but Github was encountering issues.
Co-authored-by: François-Xavier de Guillebon <[email protected]>
Co-authored-by: François-Xavier de Guillebon <[email protected]>
Co-authored-by: François-Xavier de Guillebon <[email protected]>
…nescu/Elastica into 1963-multiple-direct-generators
Thanks @sergiuionescu |
Thank you @deguif , @ruflin for the quick action and support! |
See #1963