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

Add setPostFilter method to Elastica\Query #645

Merged
merged 2 commits into from
Jul 3, 2014

Conversation

krzaczek
Copy link
Contributor

@krzaczek krzaczek commented Jul 2, 2014

Hi,

Just added a missing method setPostFilter() that allows to set "post_filter" param to Elastica\Query object.
@see http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_filtering_queries_and_aggregations.html#_post_filter

Pawel

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) when pulling 9e6d598 on krzaczek:fix-query-post-filter into 8024d1f on ruflin:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) when pulling 572e44b on krzaczek:fix-query-post-filter into 8024d1f on ruflin:master.

@ruflin
Copy link
Owner

ruflin commented Jul 2, 2014

@krzaczek Can you add a second "integration" test to make sure it also works directly with ES?

@krzaczek
Copy link
Contributor Author

krzaczek commented Jul 2, 2014

Can I add it to testSetPostQuery() test ... or do You prefer to put it in a seperate test ?

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) when pulling 27667c5 on krzaczek:fix-query-post-filter into 8024d1f on ruflin:master.

@krzaczek
Copy link
Contributor Author

krzaczek commented Jul 3, 2014

@ruflin Added new test file Query/PostFilterTest.php and placed both tests there. Hope it's ok now.

Pawel

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) when pulling bfc8ace on krzaczek:fix-query-post-filter into 8024d1f on ruflin:master.

@@ -1,5 +1,8 @@
CHANGES

2014-07-02
- Add setPostFilter method to Elastica\Query (http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_filtering_queries_and_aggregations.html#_post_filter)
Copy link
Owner

Choose a reason for hiding this comment

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

One detail I forgot: Can you add the pull request Id at the end of the line. I just realized the one before is also missing. If you can add also this one, I don't mind ;-)

@krzaczek
Copy link
Contributor Author

krzaczek commented Jul 3, 2014

Done

ruflin added a commit that referenced this pull request Jul 3, 2014
Add setPostFilter method to Elastica\Query
@ruflin ruflin merged commit 9fc23a8 into ruflin:master Jul 3, 2014
@ruflin
Copy link
Owner

ruflin commented Jul 3, 2014

Merged. Thx.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) when pulling d9ca120 on krzaczek:fix-query-post-filter into 8024d1f on ruflin:master.

@MrHash
Copy link
Contributor

MrHash commented Aug 23, 2014

Don't you think this should support the setting of a post filter that extends AbstractFilter as opposed to requiring an array?

@MrHash
Copy link
Contributor

MrHash commented Aug 24, 2014

Please see #669

@krzaczek
Copy link
Contributor Author

According to doc:

Also, the top-level filter parameter in search has been renamed to post_filter, to indicate that it should not be used as the primary way to filter search results (use a filtered query instead), but only to filter results AFTER facets/aggregations have been calculated.

We should probably make setFilter deprecated and change it to:

public function setFilter(AbstractFilter $filter)
    {
        return $this->setPostFilter($filer)
    }

and rewrite setPostFilter to

public function setPostFilter(AbstractFilter $filter)
    {
        return $this->setParam('post_filter', $filter->toArray());
    }

or better to make it backwards compatible ..

public function setPostFilter($filter)
    {
        if (is_array($filter)) {
            return $this->setParam("post_filter", $filter);
        } elseif ($filter instarnceof AbstractFilter) {
            return $this->setParam('post_filter', $filter->toArray());
        }
    }

@MrHash
Copy link
Contributor

MrHash commented Aug 24, 2014

Personally i prefer the non-backwards compatible solution you described since the changes are fresh.

@krzaczek
Copy link
Contributor Author

@ruflin What do You think ?

@ruflin
Copy link
Owner

ruflin commented Aug 25, 2014

As the function setFilter is used very often, I prefer the BC compatible option but we should have a way to tell the people that they are using a deprecated version (phpdoc @deprecated). Can you open a pull request with the suggestion? So we also se what kind of changes are needed on the Elastica side.

@krzaczek
Copy link
Contributor Author

Well the BC doesn't affect setFilter method. It always required AbstractFIlter as parameter. Only the setPostFilter required array ... and it's rather new (merged 1 month ago) so the question is shoud we change the param to AbstractFIlter for setPostFilter .. or keep it BC and allow array and AbstractFilter

@krzaczek krzaczek deleted the fix-query-post-filter branch August 25, 2014 08:27
@ruflin
Copy link
Owner

ruflin commented Aug 25, 2014

Unfortunately there was already a release in between so I would suggest to make it BC compatible for the moment but make it clear that this will not be the case in the long run and should be cleaned up later.

@krzaczek
Copy link
Contributor Author

OK ... i've just sent a pull request ... check it out.

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.

4 participants