Skip to content

Commit

Permalink
MLT query against documents
Browse files Browse the repository at this point in the history
  • Loading branch information
nurikabe committed Apr 10, 2015
1 parent f2f75d4 commit 45ca4da
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lib/Elastica/Query/MoreLikeThis.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
10 changes: 10 additions & 0 deletions test/lib/Elastica/Test/Query/MoreLikeThisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 45ca4da

Please sign in to comment.