Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions module/VuFindSearch/src/VuFindSearch/Backend/Solr/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ public function similar($id, ?ParamBag $params = null)
$params = $params ?: new ParamBag();
$this->injectResponseWriter($params);

$params->mergeWith($this->getSimilarBuilder()->build($id));
$response = $this->connector->similar($id, $params);
$params = $this->getSimilarBuilder()->build($id, $params);
$response = $this->connector->similar($id, $params);
$collection = $this->createRecordCollection($response);
$this->injectSourceIdentifier($collection);
return $collection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,14 @@ public function __construct(
/**
* Return SOLR search parameters based on a record Id and params.
*
* @param string $id Record Id
* @param string $id Record Id
* @param ?ParamBag $params Existing params
*
* @return ParamBag
*/
public function build($id)
public function build(string $id, ?ParamBag $params = null): ParamBag
{
$params = new ParamBag();
$params = $params ?: new ParamBag();
if ($this->useHandler) {
$mltParams = $this->handlerParams
? $this->handlerParams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ interface SimilarBuilderInterface
/**
* Build SOLR query based on VuFind query object.
*
* @param string $id Record id
* @param string $id Record id
* @param ?ParamBag $params Existing params
*
* @return ParamBag
*/
public function build($id);
public function build(string $id, ?ParamBag $params = null): ParamBag;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
namespace VuFindTest\Backend\Solr;

use VuFindSearch\Backend\Solr\SimilarBuilder;
use VuFindSearch\ParamBag;

/**
* Unit tests for SOLR similar records query builder
Expand Down Expand Up @@ -62,6 +63,19 @@ public function testDefaultParams()
$this->assertEquals('morelikethis', $qt[0]);
}

/**
* Test builder with an existing limit
*
* @return void
*/
public function testExistingLimit()
{
$sb = new SimilarBuilder();
$response = $sb->build('testrecord', new ParamBag(['rows' => 42]));
$rows = $response->get('rows');
$this->assertEquals(42, $rows[0]);
}

/**
* Test builder with alternative id field.
*
Expand Down
Loading