mirror of
https://github.com/silverstripe/silverstripe-fulltextsearch
synced 2024-10-22 14:05:29 +02:00
ENHANCEMENT Solr->addCopyFields()
This commit is contained in:
parent
0ef78f905c
commit
874bd32300
@ -26,6 +26,8 @@ abstract class SolrIndex extends SearchIndex {
|
||||
|
||||
protected $analyzerFields = array();
|
||||
|
||||
protected $copyFields = array();
|
||||
|
||||
function generateSchema() {
|
||||
return $this->renderWith(Director::baseFolder() . '/fulltextsearch/conf/templates/schema.ss');
|
||||
}
|
||||
@ -148,6 +150,18 @@ abstract class SolrIndex extends SearchIndex {
|
||||
return $xml;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param String $source Composite field name (<class>_<fieldname>)
|
||||
* @param String $dest
|
||||
*/
|
||||
function addCopyField($source, $dest, $extraOptions = array()) {
|
||||
if(!isset($this->copyFields[$source])) $this->copyFields[$source] = array();
|
||||
$this->copyFields[$source][] = array_merge(
|
||||
array('source' => $source, 'dest' => $dest),
|
||||
$extraOptions
|
||||
);
|
||||
}
|
||||
|
||||
function getCopyFieldDefinitions() {
|
||||
$xml = array();
|
||||
|
||||
@ -155,6 +169,12 @@ abstract class SolrIndex extends SearchIndex {
|
||||
$xml[] = "<copyField source='{$name}' dest='_text' />";
|
||||
}
|
||||
|
||||
foreach ($this->copyFields as $source => $fields) {
|
||||
foreach($fields as $fieldAttrs) {
|
||||
$xml[] = $this->toXmlTag('copyField', $fieldAttrs);
|
||||
}
|
||||
}
|
||||
|
||||
return implode("\n\t", $xml);
|
||||
}
|
||||
|
||||
|
@ -82,8 +82,18 @@ class SolrIndexTest extends SapphireTest {
|
||||
$this->assertEquals('solr.HTMLStripCharFilterFactory', $analyzers[0]->charFilter[0]['class']);
|
||||
}
|
||||
|
||||
protected function getServiceMock() {
|
||||
$serviceMock = Phockito::mock('SolrService');
|
||||
function testAddCopyField() {
|
||||
$index = new SolrIndexTest_FakeIndex();
|
||||
$index->addCopyField('sourceField', 'destField');
|
||||
$defs = simplexml_load_string('<fields>' . $index->getCopyFieldDefinitions() . '</fields>');
|
||||
$lastDef = array_pop($defs);
|
||||
|
||||
$this->assertEquals('sourceField', $lastDef['source']);
|
||||
$this->assertEquals('destField', $lastDef['dest']);
|
||||
}
|
||||
|
||||
protected function getServiceSpy() {
|
||||
$serviceSpy = Phockito::spy('SolrService');
|
||||
$fakeResponse = new Apache_Solr_Response(new Apache_Solr_HttpTransport_Response(null, null, null));
|
||||
|
||||
Phockito::when($serviceMock)
|
||||
|
Loading…
Reference in New Issue
Block a user