diff --git a/lib/Elastica/Query/MoreLikeThis.php b/lib/Elastica/Query/MoreLikeThis.php index 4232710def..54c8a56b8c 100644 --- a/lib/Elastica/Query/MoreLikeThis.php +++ b/lib/Elastica/Query/MoreLikeThis.php @@ -13,16 +13,28 @@ class MoreLikeThis extends AbstractQuery { /** - * Adds field to mlt query + * Set fields to which to restrict the mlt query * - * @param array $fields Field names - * @return $this + * @param array $fields Field names + * @return \Elastica\Query\MoreLikeThis Current object */ public function setFields(array $fields) { return $this->setParam('fields', $fields); } + /** + * Set document ids for the mlt query + * + * @param array $ids Document ids + * @return \Elastica\Query\MoreLikeThis Current object + */ + public function setIds(array $ids) + { + return $this->setParam('ids', $ids); + } + + /** * Set the "like_text" value * diff --git a/test/lib/Elastica/Test/Query/MoreLikeThisTest.php b/test/lib/Elastica/Test/Query/MoreLikeThisTest.php index 74c70faf9a..dbe2fbbad8 100644 --- a/test/lib/Elastica/Test/Query/MoreLikeThisTest.php +++ b/test/lib/Elastica/Test/Query/MoreLikeThisTest.php @@ -65,6 +65,16 @@ public function testSetFields() $this->assertEquals($fields, $data['more_like_this']['fields']); } + public function testSetIds() + { + $query = new MoreLikeThis(); + $ids = array(1, 2, 3); + $query->setIds($ids); + + $data = $query->toArray(); + $this->assertEquals($ids, $data['more_like_this']['ids']); + } + public function testSetLikeText() { $query = new MoreLikeThis();