Commit 2e3a1b13 authored by Bas de Nooijer's avatar Bas de Nooijer

Added matchoffset setting to MLT querytype (closes #233)

parent 5341fdb6
......@@ -70,6 +70,7 @@ class Query extends SelectQuery
'fields' => '*,score',
'interestingTerms' => 'none',
'matchinclude' => false,
'matchoffset' => 0,
'stream' => false,
'omitheader' => true,
);
......@@ -174,6 +175,30 @@ class Query extends SelectQuery
return $this->getOption('matchinclude');
}
/**
* Set the mlt.match.offset parameter, which determines the which result from the query should be used for MLT
* For paging of MLT use setStart / setRows
*
* @see http://wiki.apache.org/solr/MoreLikeThisHandler#Params
*
* @param int $offset
* @return self Provides fluent interface
*/
public function setMatchOffset($offset)
{
return $this->setOption('matchoffset', $offset);
}
/**
* Get the mlt.match.offset parameter.
*
* @return int
*/
public function getMatchOffset()
{
return $this->getOption('matchoffset');
}
/**
* Set MLT fields option
*
......
......@@ -63,7 +63,7 @@ class RequestBuilder extends SelectRequestBuilder
// add mlt params to request
$request->addParam('mlt.interestingTerms', $query->getInterestingTerms());
$request->addParam('mlt.match.include', $query->getMatchInclude());
$request->addParam('mlt.match.offset', $query->getStart());
$request->addParam('mlt.match.offset', $query->getMatchOffset());
$request->addParam('mlt.fl', implode(',', $query->getMltFields()));
$request->addParam('mlt.mintf', $query->getMinimumTermFrequency());
$request->addParam('mlt.mindf', $query->getMinimumDocumentFrequency());
......
......@@ -439,6 +439,7 @@ class QueryTest extends \PHPUnit_Framework_TestCase
)
),
),
'matchoffset' => 15,
'resultclass' => 'MyResultClass',
'documentclass' => 'MyDocumentClass',
);
......@@ -451,6 +452,7 @@ class QueryTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($config['start'], $query->getStart());
$this->assertEquals($config['documentclass'], $query->getDocumentClass());
$this->assertEquals($config['resultclass'], $query->getResultClass());
$this->assertEquals($config['matchoffset'], $query->getMatchOffset());
$this->assertEquals('published:true', $query->getFilterQuery('pub')->getQuery());
$this->assertEquals('online:true', $query->getFilterQuery('online')->getQuery());
......@@ -664,6 +666,17 @@ class QueryTest extends \PHPUnit_Framework_TestCase
);
}
public function testSetAndGetMatchOffset()
{
$value = 20;
$this->query->setMatchOffset($value);
$this->assertEquals(
$value,
$this->query->getMatchOffset()
);
}
public function testSetAndGetMltFields()
{
$value = 'name,description';
......
......@@ -58,6 +58,7 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase
$this->query->setInterestingTerms('test');
$this->query->setMatchInclude(true);
$this->query->setStart(12);
$this->query->setMatchOffset(15);
$this->query->setMltFields('description,name');
$this->query->setMinimumTermFrequency(1);
$this->query->setMinimumDocumentFrequency(3);
......@@ -74,7 +75,7 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase
array(
'mlt.interestingTerms' => 'test',
'mlt.match.include' => 'true',
'mlt.match.offset' => 12,
'mlt.match.offset' => 15,
'mlt.fl' => 'description,name',
'mlt.mintf' => 1,
'mlt.mindf' => 3,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment