-
Notifications
You must be signed in to change notification settings - Fork 733
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
Added Rescore Query #441
Changes from 11 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
7fdb558
added rescore query
jsonblob 2711c13
added weight setters
jsonblob 1ba471a
added rescore test stubs
jsonblob 8627544
Finished rescore and tests
jsonblob 574334e
fixed naming and added changes to changes.txt
jsonblob 37f4b71
added elasticsearch test for rescore
jsonblob 5f3d3f1
fixed changes.txt conflict
jsonblob 26c7313
fixed naming convention again
jsonblob 2ba6439
restructured rescore classes and added setRescore to both Query and S…
jsonblob 1f0331a
updated changes.txt
jsonblob 550c52b
removed some outdated changes
jsonblob c09bc15
Merge pull request #566 from jlinn/snapshot
ruflin df2c11a
Enable goecluster-facet again as now compatible
ruflin 368c8e2
Run elasticsearch in the background to not have log output in travis …
ruflin 5bb17ad
Set memache php version as environment variable
ruflin d0d6f11
Update to memcache 3.0.8 for travis
ruflin 6297d82
Release v1.0.1.1
ruflin f32952d
added rescore query
jsonblob 876c538
added weight setters
jsonblob c143f1a
added rescore test stubs
jsonblob b7dadc8
Finished rescore and tests
jsonblob 674d280
Added all Rescore files
jsonblob 42d727d
Merge branch 'master' into rescore
jsonblob ef9b125
Restructured to follow current scheme of Filters, Querys, etc. and ex…
jsonblob File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
namespace Elastica\Rescore; | ||
|
||
use Elastica\Query as BaseQuery; | ||
|
||
/** | ||
* Rescore query | ||
* | ||
* @category Xodoa | ||
* @package Elastica | ||
* @author Jason Hu <mjhu91@gmail.com> | ||
* @link http://www.elasticsearch.org/guide/reference/api/search/rescore/ | ||
*/ | ||
class QueryRescore extends AbstractRescore | ||
{ | ||
|
||
/** | ||
* Gets the query param | ||
* | ||
* @return array | ||
*/ | ||
protected function getQueryParam() | ||
{ | ||
if (!$this->hasParam('query')) | ||
{ | ||
$this->setParam('query', array()); | ||
} | ||
|
||
return $this->getParam('query'); | ||
} | ||
|
||
/** | ||
* Sets query object | ||
* | ||
* @param string|\Elastica\Query|\Elastica\Query\AbstractQuery $query | ||
* @return \Elastica\Rescore | ||
*/ | ||
public function setQuery($rescoreQuery) | ||
{ | ||
$query = BaseQuery::create($rescoreQuery); | ||
$data = $query->toArray(); | ||
$query = $this->getQueryParam(); | ||
|
||
$query['rescore_query'] = $data['query']; | ||
|
||
return $this->setParam('query', $query); | ||
} | ||
|
||
/** | ||
* Sets query_weight | ||
* | ||
* @param float $weight | ||
* @return \Elastica\Rescore | ||
*/ | ||
public function setQueryWeight($weight) | ||
{ | ||
$query = $this->getQueryParam(); | ||
$query['query_weight'] = $weight; | ||
|
||
return $this->setParam('query', $query); | ||
} | ||
|
||
/** | ||
* Sets rescore_query_weight | ||
* | ||
* @param float $size | ||
* @return \Elastica\Rescore | ||
*/ | ||
public function setRescoreQueryWeight($weight) | ||
{ | ||
$query = $this->getQueryParam(); | ||
$query['rescore_query_weight'] = $weight; | ||
|
||
return $this->setParam('query', $query); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
namespace Elastica\Test; | ||
|
||
use Elastica\Rescore\QueryRescore; | ||
use Elastica\Query\Term; | ||
use Elastica\Query\Match; | ||
use Elastica\Client; | ||
use Elastica\Query; | ||
use Elastica\Test\Base as BaseTest; | ||
|
||
class QueryRescoreTest extends BaseTest | ||
{ | ||
public function testToArray() | ||
{ | ||
$query = new QueryRescore(); | ||
$rescoreQuery = new Term(); | ||
$rescoreQuery = $rescoreQuery->setTerm('test2', 'bar', 2); | ||
$query->setQuery($rescoreQuery); | ||
|
||
$data = $query->toArray(); | ||
$expected = array( | ||
'rescore' => array( | ||
'query' => array( | ||
'rescore_query' => array( | ||
'term' => array( | ||
'test2' => array( | ||
'value' => 'bar', | ||
'boost' => 2, | ||
), | ||
), | ||
), | ||
), | ||
), | ||
); | ||
|
||
$this->assertEquals($expected, $data); | ||
} | ||
|
||
public function testSetSize() | ||
{ | ||
$query = new QueryRescore(); | ||
$rescoreQuery = new Term(); | ||
$rescoreQuery = $rescoreQuery->setTerm('test2', 'bar', 2); | ||
$query->setQuery($rescoreQuery); | ||
$query->setWindowSize(50); | ||
|
||
$data = $query->toArray(); | ||
$expected = array( | ||
'rescore' => array( | ||
'window_size' => 50, | ||
'query' => array( | ||
'rescore_query' => array( | ||
'term' => array( | ||
'test2' => array( | ||
'value' => 'bar', | ||
'boost' => 2, | ||
), | ||
), | ||
), | ||
), | ||
), | ||
); | ||
|
||
$this->assertEquals($expected, $data); | ||
} | ||
|
||
public function testSetWeights() | ||
{ | ||
$query = new QueryRescore(); | ||
$rescoreQuery = new Term(); | ||
$rescoreQuery = $rescoreQuery->setTerm('test2', 'bar', 2); | ||
$query->setQuery($rescoreQuery); | ||
$query->setWindowSize(50); | ||
$query->setQueryWeight(.7); | ||
$query->setRescoreQueryWeight(1.2); | ||
|
||
$data = $query->toArray(); | ||
$expected = array( | ||
'rescore' => array( | ||
'window_size' => 50, | ||
'query' => array( | ||
'rescore_query' => array( | ||
'term' => array( | ||
'test2' => array( | ||
'value' => 'bar', | ||
'boost' => 2, | ||
), | ||
), | ||
), | ||
'query_weight' => 0.7, | ||
'rescore_query_weight' => 1.2 | ||
), | ||
), | ||
); | ||
|
||
$this->assertEquals($expected, $data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why do we have to use $data['rescore'] and not just $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.
This is a side-effect of using Param as the base class of AbstractRescore