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

1963 - support multiple direct_generators #1964

Merged
merged 12 commits into from
Jun 2, 2021
Merged

1963 - support multiple direct_generators #1964

merged 12 commits into from
Jun 2, 2021

Conversation

sergiuionescu
Copy link
Contributor

@sergiuionescu sergiuionescu commented May 31, 2021

See #1963

Copy link
Owner

@ruflin ruflin left a 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
@sergiuionescu
Copy link
Contributor Author

Thanks for the contribution. Could you also add a test and a changelog entry?

Also see comment from @deguif

@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 \Elastica\Suggest\CandidateGenerator\DirectGenerator::toArray which is also updated.

@ruflin I updated the changelog. When do you think you could include this in a patch version?

Thanks.

Copy link
Collaborator

@deguif deguif left a 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.

src/Suggest/Phrase.php Outdated Show resolved Hide resolved
src/Suggest/Phrase.php Show resolved Hide resolved
src/Suggest/Phrase.php Outdated Show resolved Hide resolved
Comment on lines 141 to 149
public function toArray()
{
$data = $this->getParams();

if (!empty($this->_rawParams)) {
$data = \array_merge($data, $this->_rawParams);
}

return $this->_convertArrayable($data);
Copy link
Collaborator

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()

Copy link
Contributor Author

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?

Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@deguif deguif merged commit f63d179 into ruflin:master Jun 2, 2021
@deguif
Copy link
Collaborator

deguif commented Jun 2, 2021

Thanks @sergiuionescu

@deguif deguif added this to the 7.2.0 milestone Jun 2, 2021
@sergiuionescu
Copy link
Contributor Author

Thanks @sergiuionescu

Thank you @deguif , @ruflin for the quick action and support!

@sergiuionescu sergiuionescu deleted the 1963-multiple-direct-generators branch June 2, 2021 17:57
@deguif deguif modified the milestones: 7.2.0, 7.1.2 Oct 21, 2021
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.

3 participants