2012-08-23 17:49:32 +02:00
|
|
|
<?php
|
2017-04-21 02:23:27 +02:00
|
|
|
|
2017-11-14 21:48:52 +01:00
|
|
|
namespace SilverStripe\FullTextSearch\Tests;
|
|
|
|
|
|
|
|
use SilverStripe\Core\Config\Config;
|
2017-11-29 22:40:25 +01:00
|
|
|
use SilverStripe\Core\Environment;
|
2017-11-14 05:05:30 +01:00
|
|
|
use SilverStripe\Core\Injector\Injector;
|
|
|
|
use SilverStripe\Core\Kernel;
|
2017-04-21 02:23:27 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
2017-12-04 21:11:51 +01:00
|
|
|
use SilverStripe\FullTextSearch\Search\Queries\SearchQuery;
|
|
|
|
use SilverStripe\FullTextSearch\Search\Variants\SearchVariantSubsites;
|
2017-12-05 22:17:18 +01:00
|
|
|
use SilverStripe\FullTextSearch\Solr\SolrIndex;
|
2017-12-04 21:11:51 +01:00
|
|
|
use SilverStripe\FullTextSearch\Solr\Services\Solr3Service;
|
2017-04-26 12:52:20 +02:00
|
|
|
use SilverStripe\FullTextSearch\Tests\SearchUpdaterTest\SearchUpdaterTest_Container;
|
|
|
|
use SilverStripe\FullTextSearch\Tests\SearchUpdaterTest\SearchUpdaterTest_HasOne;
|
|
|
|
use SilverStripe\FullTextSearch\Tests\SearchUpdaterTest\SearchUpdaterTest_HasMany;
|
|
|
|
use SilverStripe\FullTextSearch\Tests\SearchUpdaterTest\SearchUpdaterTest_ManyMany;
|
2017-11-14 04:31:16 +01:00
|
|
|
use SilverStripe\FullTextSearch\Tests\SearchUpdaterTest\SearchUpdaterTest_OtherContainer;
|
2017-12-04 21:11:51 +01:00
|
|
|
use SilverStripe\FullTextSearch\Tests\SolrIndexTest\SolrIndexTest_AmbiguousRelationIndex;
|
|
|
|
use SilverStripe\FullTextSearch\Tests\SolrIndexTest\SolrIndexTest_AmbiguousRelationInheritedIndex;
|
|
|
|
use SilverStripe\FullTextSearch\Tests\SolrIndexTest\SolrIndexTest_BoostedIndex;
|
|
|
|
use SilverStripe\FullTextSearch\Tests\SolrIndexTest\SolrIndexTest_FakeIndex;
|
|
|
|
use SilverStripe\FullTextSearch\Tests\SolrIndexTest\SolrIndexTest_FakeIndex2;
|
|
|
|
use SilverStripe\Subsites\Model\Subsite;
|
2017-04-21 03:18:37 +02:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
class SolrIndexTest extends SapphireTest
|
|
|
|
{
|
|
|
|
public function testFieldDataHasOne()
|
|
|
|
{
|
|
|
|
$index = new SolrIndexTest_FakeIndex();
|
|
|
|
$data = $index->fieldData('HasOneObject.Field1');
|
|
|
|
|
2017-04-26 12:52:20 +02:00
|
|
|
$data = $data[SearchUpdaterTest_Container::class . '_HasOneObject_Field1'];
|
|
|
|
|
|
|
|
$this->assertEquals(SearchUpdaterTest_Container::class, $data['origin']);
|
|
|
|
$this->assertEquals(SearchUpdaterTest_Container::class, $data['base']);
|
|
|
|
$this->assertEquals(SearchUpdaterTest_HasOne::class, $data['class']);
|
2015-11-21 07:19:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFieldDataHasMany()
|
|
|
|
{
|
|
|
|
$index = new SolrIndexTest_FakeIndex();
|
|
|
|
$data = $index->fieldData('HasManyObjects.Field1');
|
2017-04-26 12:52:20 +02:00
|
|
|
$data = $data[SearchUpdaterTest_Container::class . '_HasManyObjects_Field1'];
|
2015-11-21 07:19:20 +01:00
|
|
|
|
2017-04-26 12:52:20 +02:00
|
|
|
$this->assertEquals(SearchUpdaterTest_Container::class, $data['origin']);
|
|
|
|
$this->assertEquals(SearchUpdaterTest_Container::class, $data['base']);
|
|
|
|
$this->assertEquals(SearchUpdaterTest_HasMany::class, $data['class']);
|
2015-11-21 07:19:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFieldDataManyMany()
|
|
|
|
{
|
|
|
|
$index = new SolrIndexTest_FakeIndex();
|
|
|
|
$data = $index->fieldData('ManyManyObjects.Field1');
|
2017-04-26 12:52:20 +02:00
|
|
|
$data = $data[SearchUpdaterTest_Container::class . '_ManyManyObjects_Field1'];
|
2015-11-21 07:19:20 +01:00
|
|
|
|
2017-04-26 12:52:20 +02:00
|
|
|
$this->assertEquals(SearchUpdaterTest_Container::class, $data['origin']);
|
|
|
|
$this->assertEquals(SearchUpdaterTest_Container::class, $data['base']);
|
|
|
|
$this->assertEquals(SearchUpdaterTest_ManyMany::class, $data['class']);
|
2015-11-21 07:19:20 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 00:50:11 +02:00
|
|
|
public function testFieldDataAmbiguousHasMany()
|
|
|
|
{
|
|
|
|
$index = new SolrIndexTest_AmbiguousRelationIndex();
|
|
|
|
$data = $index->fieldData('HasManyObjects.Field1');
|
|
|
|
|
2017-11-14 05:05:30 +01:00
|
|
|
$this->assertArrayHasKey(SearchUpdaterTest_Container::class . '_HasManyObjects_Field1', $data);
|
|
|
|
$this->assertArrayHasKey(SearchUpdaterTest_OtherContainer::class . '_HasManyObjects_Field1', $data);
|
2017-06-19 00:50:11 +02:00
|
|
|
|
2017-11-14 05:05:30 +01:00
|
|
|
$dataContainer = $data[SearchUpdaterTest_Container::class . '_HasManyObjects_Field1'];
|
2017-11-14 04:31:16 +01:00
|
|
|
$this->assertEquals(SearchUpdaterTest_Container::class, $dataContainer['origin']);
|
|
|
|
$this->assertEquals(SearchUpdaterTest_Container::class, $dataContainer['base']);
|
|
|
|
$this->assertEquals(SearchUpdaterTest_HasMany::class, $dataContainer['class']);
|
2017-06-19 00:50:11 +02:00
|
|
|
|
2017-11-14 05:05:30 +01:00
|
|
|
$dataOtherContainer = $data[SearchUpdaterTest_OtherContainer::class . '_HasManyObjects_Field1'];
|
2017-11-14 04:31:16 +01:00
|
|
|
$this->assertEquals(SearchUpdaterTest_OtherContainer::class, $dataOtherContainer['origin']);
|
|
|
|
$this->assertEquals(SearchUpdaterTest_OtherContainer::class, $dataOtherContainer['base']);
|
|
|
|
$this->assertEquals(SearchUpdaterTest_HasMany::class, $dataOtherContainer['class']);
|
2017-06-19 00:50:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFieldDataAmbiguousManyMany()
|
|
|
|
{
|
|
|
|
$index = new SolrIndexTest_AmbiguousRelationIndex();
|
|
|
|
$data = $index->fieldData('ManyManyObjects.Field1');
|
|
|
|
|
2017-11-14 05:05:30 +01:00
|
|
|
$this->assertArrayHasKey(SearchUpdaterTest_Container::class . '_ManyManyObjects_Field1', $data);
|
|
|
|
$this->assertArrayHasKey(SearchUpdaterTest_OtherContainer::class . '_ManyManyObjects_Field1', $data);
|
2017-06-19 00:50:11 +02:00
|
|
|
|
2017-11-14 05:05:30 +01:00
|
|
|
$dataContainer = $data[SearchUpdaterTest_Container::class . '_ManyManyObjects_Field1'];
|
2017-11-14 04:31:16 +01:00
|
|
|
$this->assertEquals(SearchUpdaterTest_Container::class, $dataContainer['origin']);
|
|
|
|
$this->assertEquals(SearchUpdaterTest_Container::class, $dataContainer['base']);
|
|
|
|
$this->assertEquals(SearchUpdaterTest_ManyMany::class, $dataContainer['class']);
|
2017-06-19 00:50:11 +02:00
|
|
|
|
2017-11-14 05:05:30 +01:00
|
|
|
$dataOtherContainer = $data[SearchUpdaterTest_OtherContainer::class . '_ManyManyObjects_Field1'];
|
2017-11-14 04:31:16 +01:00
|
|
|
$this->assertEquals(SearchUpdaterTest_OtherContainer::class, $dataOtherContainer['origin']);
|
|
|
|
$this->assertEquals(SearchUpdaterTest_OtherContainer::class, $dataOtherContainer['base']);
|
|
|
|
$this->assertEquals(SearchUpdaterTest_ManyMany::class, $dataOtherContainer['class']);
|
2017-06-19 00:50:11 +02:00
|
|
|
}
|
|
|
|
|
2017-06-15 23:39:37 +02:00
|
|
|
public function testFieldDataAmbiguousManyManyInherited()
|
|
|
|
{
|
|
|
|
$index = new SolrIndexTest_AmbiguousRelationInheritedIndex();
|
|
|
|
$data = $index->fieldData('ManyManyObjects.Field1');
|
|
|
|
|
2017-11-14 05:05:30 +01:00
|
|
|
$this->assertArrayHasKey(SearchUpdaterTest_Container::class . '_ManyManyObjects_Field1', $data);
|
|
|
|
$this->assertArrayHasKey(SearchUpdaterTest_OtherContainer::class . '_ManyManyObjects_Field1', $data);
|
|
|
|
$this->assertArrayNotHasKey(SearchUpdaterTest_ExtendedContainer::class . '_ManyManyObjects_Field1', $data);
|
2017-06-15 23:39:37 +02:00
|
|
|
|
2017-11-14 05:05:30 +01:00
|
|
|
$dataContainer = $data[SearchUpdaterTest_Container::class . '_ManyManyObjects_Field1'];
|
2017-11-14 04:31:16 +01:00
|
|
|
$this->assertEquals(SearchUpdaterTest_Container::class, $dataContainer['origin']);
|
|
|
|
$this->assertEquals(SearchUpdaterTest_Container::class, $dataContainer['base']);
|
|
|
|
$this->assertEquals(SearchUpdaterTest_ManyMany::class, $dataContainer['class']);
|
2017-06-15 23:39:37 +02:00
|
|
|
|
2017-11-14 05:05:30 +01:00
|
|
|
$dataOtherContainer = $data[SearchUpdaterTest_OtherContainer::class . '_ManyManyObjects_Field1'];
|
2017-11-14 04:31:16 +01:00
|
|
|
$this->assertEquals(SearchUpdaterTest_OtherContainer::class, $dataOtherContainer['origin']);
|
|
|
|
$this->assertEquals(SearchUpdaterTest_OtherContainer::class, $dataOtherContainer['base']);
|
|
|
|
$this->assertEquals(SearchUpdaterTest_ManyMany::class, $dataOtherContainer['class']);
|
2017-06-15 23:39:37 +02:00
|
|
|
}
|
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
/**
|
|
|
|
* Test boosting on SearchQuery
|
|
|
|
*/
|
|
|
|
public function testBoostedQuery()
|
|
|
|
{
|
2017-04-26 12:52:20 +02:00
|
|
|
/** @var Solr3Service|PHPUnit_Framework_MockObject_MockObject $serviceMock */
|
|
|
|
$serviceMock = $this->getMockBuilder(Solr3Service::class)
|
|
|
|
->setMethods(['search'])
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$serviceMock->expects($this->once())
|
|
|
|
->method('search')
|
2017-11-14 04:31:16 +01:00
|
|
|
->with(
|
|
|
|
$this->equalTo('+(Field1:term^1.5 OR HasOneObject_Field1:term^3)'),
|
2017-04-26 12:52:20 +02:00
|
|
|
$this->anything(),
|
|
|
|
$this->anything(),
|
|
|
|
$this->anything(),
|
|
|
|
$this->anything()
|
|
|
|
)->willReturn($this->getFakeRawSolrResponse());
|
2015-11-21 07:19:20 +01:00
|
|
|
|
|
|
|
$index = new SolrIndexTest_FakeIndex();
|
|
|
|
$index->setService($serviceMock);
|
|
|
|
|
|
|
|
$query = new SearchQuery();
|
|
|
|
$query->search(
|
|
|
|
'term',
|
|
|
|
null,
|
|
|
|
array('Field1' => 1.5, 'HasOneObject_Field1' => 3)
|
|
|
|
);
|
|
|
|
$index->search($query);
|
|
|
|
}
|
2016-04-15 05:46:19 +02:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
/**
|
|
|
|
* Test boosting on field schema (via queried fields parameter)
|
|
|
|
*/
|
|
|
|
public function testBoostedField()
|
|
|
|
{
|
2017-12-04 21:11:51 +01:00
|
|
|
if (class_exists(Subsite::class)) {
|
|
|
|
Config::modify()->set(SearchVariantSubsites::class, 'enabled', false);
|
|
|
|
}
|
|
|
|
|
2017-04-26 12:52:20 +02:00
|
|
|
/** @var Solr3Service|PHPUnit_Framework_MockObject_MockObject $serviceMock */
|
|
|
|
$serviceMock = $this->getMockBuilder(Solr3Service::class)
|
|
|
|
->setMethods(['search'])
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$serviceMock->expects($this->once())
|
|
|
|
->method('search')
|
2017-11-14 04:31:16 +01:00
|
|
|
->with(
|
|
|
|
$this->equalTo('+term'),
|
2017-04-26 12:52:20 +02:00
|
|
|
$this->anything(),
|
|
|
|
$this->anything(),
|
2017-12-04 21:11:51 +01:00
|
|
|
$this->equalTo([
|
|
|
|
'qf' => SearchUpdaterTest_Container::class . '_Field1^1.5 '
|
|
|
|
. SearchUpdaterTest_Container::class . '_Field2^2.1 _text',
|
|
|
|
'fq' => '+(_versionedstage:"" (*:* -_versionedstage:[* TO *]))',
|
|
|
|
]),
|
2017-04-26 12:52:20 +02:00
|
|
|
$this->anything()
|
|
|
|
)->willReturn($this->getFakeRawSolrResponse());
|
2015-11-21 07:19:20 +01:00
|
|
|
|
|
|
|
$index = new SolrIndexTest_BoostedIndex();
|
|
|
|
$index->setService($serviceMock);
|
|
|
|
|
|
|
|
$query = new SearchQuery();
|
|
|
|
$query->search('term');
|
|
|
|
$index->search($query);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testHighlightQueryOnBoost()
|
|
|
|
{
|
2017-04-26 12:52:20 +02:00
|
|
|
/** @var SilverStripe\FullTextSearch\Solr\Services\Solr3Service|ObjectProphecy $serviceMock */
|
|
|
|
$serviceMock = $this->getMockBuilder(Solr3Service::class)
|
|
|
|
->setMethods(['search'])
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$serviceMock->expects($this->exactly(2))
|
|
|
|
->method('search')
|
2017-11-14 21:48:52 +01:00
|
|
|
->withConsecutive(
|
|
|
|
[
|
2017-04-26 12:52:20 +02:00
|
|
|
$this->equalTo('+(Field1:term^1.5 OR HasOneObject_Field1:term^3)'),
|
|
|
|
$this->anything(),
|
|
|
|
$this->anything(),
|
|
|
|
$this->logicalNot(
|
|
|
|
$this->arrayHasKey('hl.q')
|
|
|
|
),
|
|
|
|
$this->anything()
|
|
|
|
],
|
|
|
|
[
|
|
|
|
$this->equalTo('+(Field1:term^1.5 OR HasOneObject_Field1:term^3)'),
|
|
|
|
$this->anything(),
|
|
|
|
$this->anything(),
|
|
|
|
$this->arrayHasKey('hl.q'),
|
|
|
|
$this->anything()
|
|
|
|
]
|
|
|
|
)->willReturn($this->getFakeRawSolrResponse());
|
2015-11-21 07:19:20 +01:00
|
|
|
|
|
|
|
$index = new SolrIndexTest_FakeIndex();
|
|
|
|
$index->setService($serviceMock);
|
|
|
|
|
|
|
|
// Search without highlighting
|
|
|
|
$query = new SearchQuery();
|
|
|
|
$query->search(
|
|
|
|
'term',
|
|
|
|
null,
|
|
|
|
array('Field1' => 1.5, 'HasOneObject_Field1' => 3)
|
|
|
|
);
|
|
|
|
$index->search($query);
|
|
|
|
|
|
|
|
// Search with highlighting
|
|
|
|
$query = new SearchQuery();
|
|
|
|
$query->search(
|
|
|
|
'term',
|
|
|
|
null,
|
|
|
|
array('Field1' => 1.5, 'HasOneObject_Field1' => 3)
|
|
|
|
);
|
|
|
|
$index->search($query, -1, -1, array('hl' => true));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIndexExcludesNullValues()
|
|
|
|
{
|
2017-04-26 12:52:20 +02:00
|
|
|
/** @var Solr3Service|ObjectProphecy $serviceMock */
|
|
|
|
$serviceMock = $this->createMock(Solr3Service::class);
|
2015-11-21 07:19:20 +01:00
|
|
|
$index = new SolrIndexTest_FakeIndex();
|
|
|
|
$index->setService($serviceMock);
|
2017-04-26 12:52:20 +02:00
|
|
|
$obj = new SearchUpdaterTest_Container();
|
2015-11-21 07:19:20 +01:00
|
|
|
|
|
|
|
$obj->Field1 = 'Field1 val';
|
|
|
|
$obj->Field2 = null;
|
|
|
|
$obj->MyDate = null;
|
|
|
|
$docs = $index->add($obj);
|
2017-04-26 12:52:20 +02:00
|
|
|
$value = $docs[0]->getField(SearchUpdaterTest_Container::class . '_Field1');
|
2015-11-21 07:19:20 +01:00
|
|
|
$this->assertEquals('Field1 val', $value['value'], 'Writes non-NULL string fields');
|
2017-04-26 12:52:20 +02:00
|
|
|
$value = $docs[0]->getField(SearchUpdaterTest_Container::class . '_Field2');
|
2015-11-21 07:19:20 +01:00
|
|
|
$this->assertFalse($value, 'Ignores string fields if they are NULL');
|
2017-04-26 12:52:20 +02:00
|
|
|
$value = $docs[0]->getField(SearchUpdaterTest_Container::class . '_MyDate');
|
2015-11-21 07:19:20 +01:00
|
|
|
$this->assertFalse($value, 'Ignores date fields if they are NULL');
|
|
|
|
|
|
|
|
$obj->MyDate = '2010-12-30';
|
|
|
|
$docs = $index->add($obj);
|
2017-04-26 12:52:20 +02:00
|
|
|
$value = $docs[0]->getField(SearchUpdaterTest_Container::class . '_MyDate');
|
2015-11-21 07:19:20 +01:00
|
|
|
$this->assertEquals('2010-12-30T00:00:00Z', $value['value'], 'Writes non-NULL dates');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAddFieldExtraOptions()
|
|
|
|
{
|
2017-11-14 05:05:30 +01:00
|
|
|
Injector::inst()->get(Kernel::class)->setEnvironment('live');
|
2015-11-21 07:19:20 +01:00
|
|
|
|
|
|
|
$index = new SolrIndexTest_FakeIndex();
|
|
|
|
|
|
|
|
$defs = simplexml_load_string('<fields>' . $index->getFieldDefinitions() . '</fields>');
|
2017-04-26 12:52:20 +02:00
|
|
|
$defField1 = $defs->xpath('field[@name="' . SearchUpdaterTest_Container::class . '_Field1"]');
|
2015-11-21 07:19:20 +01:00
|
|
|
$this->assertEquals((string)$defField1[0]['stored'], 'false');
|
|
|
|
|
|
|
|
$index->addFilterField('Field1', null, array('stored' => 'true'));
|
|
|
|
$defs = simplexml_load_string('<fields>' . $index->getFieldDefinitions() . '</fields>');
|
2017-04-26 12:52:20 +02:00
|
|
|
$defField1 = $defs->xpath('field[@name="' . SearchUpdaterTest_Container::class . '_Field1"]');
|
2015-11-21 07:19:20 +01:00
|
|
|
$this->assertEquals((string)$defField1[0]['stored'], 'true');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAddAnalyzer()
|
|
|
|
{
|
|
|
|
$index = new SolrIndexTest_FakeIndex();
|
|
|
|
|
|
|
|
$defs = simplexml_load_string('<fields>' . $index->getFieldDefinitions() . '</fields>');
|
2017-04-26 12:52:20 +02:00
|
|
|
$defField1 = $defs->xpath('field[@name="' . SearchUpdaterTest_Container::class . '_Field1"]');
|
2015-11-21 07:19:20 +01:00
|
|
|
$analyzers = $defField1[0]->analyzer;
|
|
|
|
$this->assertFalse((bool)$analyzers);
|
|
|
|
|
|
|
|
$index->addAnalyzer('Field1', 'charFilter', array('class' => 'solr.HTMLStripCharFilterFactory'));
|
|
|
|
$defs = simplexml_load_string('<fields>' . $index->getFieldDefinitions() . '</fields>');
|
2017-04-26 12:52:20 +02:00
|
|
|
$defField1 = $defs->xpath('field[@name="' . SearchUpdaterTest_Container::class . '_Field1"]');
|
2015-11-21 07:19:20 +01:00
|
|
|
$analyzers = $defField1[0]->analyzer;
|
|
|
|
$this->assertTrue((bool)$analyzers);
|
|
|
|
$this->assertEquals('solr.HTMLStripCharFilterFactory', $analyzers[0]->charFilter[0]['class']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAddCopyField()
|
|
|
|
{
|
|
|
|
$index = new SolrIndexTest_FakeIndex();
|
|
|
|
$index->addCopyField('sourceField', 'destField');
|
|
|
|
|
|
|
|
$defs = simplexml_load_string('<fields>' . $index->getCopyFieldDefinitions() . '</fields>');
|
|
|
|
$copyField = $defs->xpath('copyField');
|
|
|
|
|
|
|
|
$this->assertEquals('sourceField', $copyField[0]['source']);
|
|
|
|
$this->assertEquals('destField', $copyField[0]['dest']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests the setting of the 'stored' flag
|
|
|
|
*/
|
|
|
|
public function testStoredFields()
|
|
|
|
{
|
|
|
|
// Test two fields
|
|
|
|
$index = new SolrIndexTest_FakeIndex2();
|
|
|
|
$index->addStoredField('Field1');
|
|
|
|
$index->addFulltextField('Field2');
|
|
|
|
$schema = $index->getFieldDefinitions();
|
|
|
|
$this->assertContains(
|
2017-04-26 12:52:20 +02:00
|
|
|
"<field name='" . SearchUpdaterTest_Container::class . "_Field1' type='text' indexed='true' stored='true'",
|
2015-11-21 07:19:20 +01:00
|
|
|
$schema
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
2017-04-26 12:52:20 +02:00
|
|
|
"<field name='" . SearchUpdaterTest_Container::class . "_Field2' type='text' indexed='true' stored='false'",
|
2015-11-21 07:19:20 +01:00
|
|
|
$schema
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test with addAllFulltextFields
|
|
|
|
$index2 = new SolrIndexTest_FakeIndex2();
|
|
|
|
$index2->addAllFulltextFields();
|
|
|
|
$index2->addStoredField('Field2');
|
|
|
|
$schema2 = $index2->getFieldDefinitions();
|
|
|
|
$this->assertContains(
|
2017-04-26 12:52:20 +02:00
|
|
|
"<field name='" . SearchUpdaterTest_Container::class . "_Field1' type='text' indexed='true' stored='false'",
|
2015-11-21 07:19:20 +01:00
|
|
|
$schema2
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
2017-04-26 12:52:20 +02:00
|
|
|
"<field name='" . SearchUpdaterTest_Container::class . "_Field2' type='text' indexed='true' stored='true'",
|
2015-11-21 07:19:20 +01:00
|
|
|
$schema2
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-11-16 01:59:15 +01:00
|
|
|
public function testSanitiseClassName()
|
|
|
|
{
|
|
|
|
$index = new SolrIndexTest_FakeIndex2;
|
2017-12-05 22:17:18 +01:00
|
|
|
|
2017-11-16 01:59:15 +01:00
|
|
|
$this->assertSame(
|
|
|
|
'SilverStripe\\\\FullTextSearch\\\\Tests\\\\SolrIndexTest',
|
|
|
|
$index->sanitiseClassName(static::class)
|
|
|
|
);
|
2017-12-05 22:17:18 +01:00
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
'SilverStripe-FullTextSearch-Tests-SolrIndexTest',
|
|
|
|
$index->sanitiseClassName(static::class, '-')
|
|
|
|
);
|
2017-11-16 01:59:15 +01:00
|
|
|
}
|
|
|
|
|
2017-11-29 22:40:25 +01:00
|
|
|
public function testGetIndexName()
|
|
|
|
{
|
|
|
|
$index = new SolrIndexTest_FakeIndex2;
|
2017-12-05 22:17:18 +01:00
|
|
|
$this->assertSame(
|
|
|
|
'SilverStripe-FullTextSearch-Tests-SolrIndexTest-SolrIndexTest_FakeIndex2',
|
|
|
|
$index->getIndexName()
|
|
|
|
);
|
2017-11-29 22:40:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetIndexNameWithPrefixAndSuffixFromEnvironment()
|
|
|
|
{
|
|
|
|
$index = new SolrIndexTest_FakeIndex2;
|
|
|
|
|
|
|
|
Environment::putEnv('SS_SOLR_INDEX_PREFIX="foo_"');
|
|
|
|
Environment::putEnv('SS_SOLR_INDEX_SUFFIX="_bar"');
|
|
|
|
|
2017-12-05 22:17:18 +01:00
|
|
|
$this->assertSame(
|
|
|
|
'foo_SilverStripe-FullTextSearch-Tests-SolrIndexTest-SolrIndexTest_FakeIndex2_bar',
|
|
|
|
$index->getIndexName()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider indexNameProvider
|
|
|
|
* @param string $indexName
|
|
|
|
* @param string $expected
|
|
|
|
*/
|
|
|
|
public function testGetClassNameFromIndex($indexName, $expected)
|
|
|
|
{
|
|
|
|
Environment::putEnv('SS_SOLR_INDEX_PREFIX="foo_"');
|
|
|
|
Environment::putEnv('SS_SOLR_INDEX_SUFFIX="_bar"');
|
|
|
|
|
|
|
|
$this->assertSame($expected, SolrIndex::getClassNameFromIndex($indexName));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array[]
|
|
|
|
*/
|
|
|
|
public function indexNameProvider()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
['foo_SilverStripe-FullTextSearch-Tests-SolrIndexTest_bar', __CLASS__],
|
|
|
|
['SilverStripe-FullTextSearch-Tests-SolrIndexTest', __CLASS__],
|
|
|
|
];
|
2017-11-29 22:40:25 +01:00
|
|
|
}
|
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
protected function getFakeRawSolrResponse()
|
|
|
|
{
|
2017-04-26 12:52:20 +02:00
|
|
|
return new \Apache_Solr_Response(
|
|
|
|
new \Apache_Solr_HttpTransport_Response(
|
2015-11-21 07:19:20 +01:00
|
|
|
null,
|
|
|
|
null,
|
|
|
|
'{}'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2012-08-23 17:49:32 +02:00
|
|
|
}
|