Skip to content
Snippets Groups Projects
Commit 93f1a2c0 authored by Demian Katz's avatar Demian Katz
Browse files

Merge pull request #24 from vufind-org/custom-solr-uniquekey

Allow Solr backends to use different uniqueKey values.
parents 67a3660e 650a4cc3
No related merge requests found
...@@ -97,6 +97,13 @@ abstract class AbstractSolrBackendFactory implements FactoryInterface ...@@ -97,6 +97,13 @@ abstract class AbstractSolrBackendFactory implements FactoryInterface
*/ */
protected $solrCore = ''; protected $solrCore = '';
/**
* Solr field used to store unique identifiers
*
* @var string
*/
protected $uniqueKey = 'id';
/** /**
* Constructor * Constructor
*/ */
...@@ -254,7 +261,9 @@ abstract class AbstractSolrBackendFactory implements FactoryInterface ...@@ -254,7 +261,9 @@ abstract class AbstractSolrBackendFactory implements FactoryInterface
} }
} }
$connector = new Connector($this->getSolrUrl(), new HandlerMap($handlers)); $connector = new Connector(
$this->getSolrUrl(), new HandlerMap($handlers), $this->uniqueKey
);
$connector->setTimeout( $connector->setTimeout(
isset($config->Index->timeout) ? $config->Index->timeout : 30 isset($config->Index->timeout) ? $config->Index->timeout : 30
); );
......
...@@ -95,6 +95,13 @@ class Connector ...@@ -95,6 +95,13 @@ class Connector
*/ */
protected $map; protected $map;
/**
* Solr field used to store unique identifier
*
* @var string
*/
protected $uniqueKey;
/** /**
* HTTP read timeout. * HTTP read timeout.
* *
...@@ -121,15 +128,17 @@ class Connector ...@@ -121,15 +128,17 @@ class Connector
/** /**
* Constructor * Constructor
* *
* @param string $url SOLR base URL * @param string $url SOLR base URL
* @param HandlerMap $map Handler map * @param HandlerMap $map Handler map
* @param string $uniqueKey Solr field used to store unique identifier
* *
* @return void * @return void
*/ */
public function __construct($url, HandlerMap $map) public function __construct($url, HandlerMap $map, $uniqueKey = 'id')
{ {
$this->url = $url; $this->url = $url;
$this->map = $map; $this->map = $map;
$this->uniqueKey = $uniqueKey;
} }
/// Public API /// Public API
...@@ -165,7 +174,8 @@ class Connector ...@@ -165,7 +174,8 @@ class Connector
public function retrieve($id, ParamBag $params = null) public function retrieve($id, ParamBag $params = null)
{ {
$params = $params ?: new ParamBag(); $params = $params ?: new ParamBag();
$params->set('q', sprintf('id:"%s"', addcslashes($id, '"'))); $params
->set('q', sprintf('%s:"%s"', $this->uniqueKey, addcslashes($id, '"')));
$handler = $this->map->getHandler(__FUNCTION__); $handler = $this->map->getHandler(__FUNCTION__);
$this->map->prepare(__FUNCTION__, $params); $this->map->prepare(__FUNCTION__, $params);
...@@ -186,7 +196,8 @@ class Connector ...@@ -186,7 +196,8 @@ class Connector
public function similar($id, ParamBag $params = null) public function similar($id, ParamBag $params = null)
{ {
$params = $params ?: new ParamBag(); $params = $params ?: new ParamBag();
$params->set('q', sprintf('id:"%s"', addcslashes($id, '"'))); $params
->set('q', sprintf('%s:"%s"', $this->uniqueKey, addcslashes($id, '"')));
$params->set('qt', 'morelikethis'); $params->set('qt', 'morelikethis');
$handler = $this->map->getHandler(__FUNCTION__); $handler = $this->map->getHandler(__FUNCTION__);
......
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