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

Added Rescore Query #441

Merged
merged 24 commits into from
Mar 16, 2014
Merged

Added Rescore Query #441

merged 24 commits into from
Mar 16, 2014

Conversation

jsonblob
Copy link
Contributor

I have been using the new rescore feature of elasticsearch 0.9x and have had to write my own query for them. I thought this would help with others who might use the lastest api. All the parameters are in conjunction with the outline of the usage of rescore on http://www.elasticsearch.org/guide/reference/api/search/rescore/

{
$this->setQuery($query);
$this->setParam('rescore', array());
$this->setRescoreQuery($rescore_query);
Copy link
Owner

Choose a reason for hiding this comment

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

Please name it $rescoreQuery based on the Elastica naming standard

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah will do

@ruflin
Copy link
Owner

ruflin commented Aug 11, 2013

Nice addition. Can you update the changes.txt file with your changes and fix the naming issues?

@jsonblob
Copy link
Contributor Author

Will do

@ruflin
Copy link
Owner

ruflin commented Aug 13, 2013

Looks good. I would like to see one addition. Can you also create a test where Elastica actually runs a query on elasticsearch to confirm, that also the specific elasticsearch version supports it? Like this we always know in case we upgrade to a new elasticsearch version, if the client is still compatible.

Because of an other update to changes.txt (because I was too slow) there is now a conflict in changes.txt. Can you merge master and resolve it?

@ruflin
Copy link
Owner

ruflin commented Aug 13, 2013

BTW: Please add a comment when you updated it, as otherwise I don't get notified.

@jsonblob
Copy link
Contributor Author

I have added the extra test, which was a really good idea because it helped me catch an error in the Query::create method in how it handled rescore since the structure is slightly different than all other queries. I also pulled the upstream updates but they caused my latest commit to contain changes from the person who changed the filters. Is that a problem or will github handle it?

@@ -57,6 +57,11 @@ public static function create($query)
case $query instanceof Query:
return $query;
case $query instanceof AbstractQuery:
$query_array = $query->toArray();
Copy link
Owner

Choose a reason for hiding this comment

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

Please use the camelCase naming: $queryArray

And I assume as this is special to rescore, the "reformatting" should happen in the toArray function of Rescore and not here. Exceptions should be treated locally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've been using underscores a lot recently, sorry about that.

I have already overriden the toArray method but it's only part of the solution. Every time a search happens, ultimately it will come to a Query::create. Since the Rescore extends AbstractQuery, it will currently add an extra top level of query and wrap the rescore parameters in it. So instead of
{'query':{}, 'rescore':{}} CORRECT
it will be
{'query':{'query':{}, 'rescore':{}}} INCORRECT.
The above place was the only way I saw to add support for Rescore without completely changing the way search works.

@ruflin
Copy link
Owner

ruflin commented Aug 14, 2013

Somehow got an e-mail for your comment but couldn't find it anymore. One thing I just realized: Rescore is not a query type. So it should not be inside Elastica\Query*. In a way in Elastica\Search.php and Elastica\Query.php there should be a function setRescore(Elastica\Rescore) ...

@jsonblob
Copy link
Contributor Author

should that method only exist inside Elastica\Query then, since Search will create a new Query anyways and not really use setQuery itself?

@ruflin
Copy link
Owner

ruflin commented Aug 14, 2013

There is a little bit a mix between Search and Query. From my point of view, Query only exists because of legacy. In the beginning there were not facets, filters etc. so query made totally sense. I think in the long term everything should be transferred to Search. So at the moment normally it is implemented in both ...

@jsonblob
Copy link
Contributor Author

Ok, so after reading the elasticsearch api on rescore, it seems that they will probably add more types of rescores. So I have set up a new Rescore directory with an AbstractRescore that can be extended for future work. The only supported rescore currently is Query so it is there as well. I've also added setRescore in both search and query and added tests for them.

public function setRescore(AbstractRescore $rescore)
{
$data = $rescore->toArray();
return $this->setParam('rescore', $data['rescore']);
Copy link
Owner

Choose a reason for hiding this comment

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

Why do we have to use $data['rescore'] and not just $data?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a side-effect of using Param as the base class of AbstractRescore

@ruflin
Copy link
Owner

ruflin commented Aug 16, 2013

Somehow i miss the AbstractRescore.php file? Will there be one rescore per search or multiple?

@ruflin
Copy link
Owner

ruflin commented Oct 26, 2013

@mjhu Any updates here? I think it would be very nice to have this in the code.

@jsonblob
Copy link
Contributor Author

@ruflin Sorry for the lack of updates. After my internship ended, I kinda forgot about this. Do you like the setup of the rescorer?

@ruflin
Copy link
Owner

ruflin commented Oct 28, 2013

Yes, but I miss some files. Check my comment above (2 months ago)

@ruflin
Copy link
Owner

ruflin commented Mar 8, 2014

@mjhu Any updates here. I would really like to have this in Elastica.

@jsonblob
Copy link
Contributor Author

jsonblob commented Mar 8, 2014

Hey sorry for taking so long, but I missed your first email, and it has been slipping my mind. I also ran my tests on 1.0.1 of elasticsearch to make sure the api still works.

@ruflin
Copy link
Owner

ruflin commented Mar 9, 2014

@mjhu Thx for the update. Can you add some tests that test Rescore directly with elasticsearch (integration tests). As far as I can see the current tests all check if the models are correctly built which is good. But to detect changes and implementation issues with elasticsearch itself making calls is very helpful.

@jsonblob
Copy link
Contributor Author

@ruflin Good call on integration tests. Also allowed me to restructure the Rescore to follow current schemes Filters, Queries, etc.

@ruflin ruflin merged commit ef9b125 into ruflin:master Mar 16, 2014
@ruflin
Copy link
Owner

ruflin commented Mar 16, 2014

Merged, and all is green. Thx.

@jeffchan
Copy link

👍

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