1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Firesphere\SolrCompatibility\Tests; |
5
|
|
|
|
6
|
|
|
use Firesphere\SolrCompatibility\Extensions\FulltextSearchExtension; |
7
|
|
|
use Firesphere\SolrSearch\Indexes\BaseIndex; |
8
|
|
|
use Firesphere\SolrSearch\Queries\BaseQuery; |
9
|
|
|
use Firesphere\SolrSearch\Tasks\SolrConfigureTask; |
10
|
|
|
use Firesphere\SolrSearch\Tests\TestIndex; |
11
|
|
|
use Psr\Log\NullLogger; |
12
|
|
|
use SilverStripe\Control\NullHTTPRequest; |
13
|
|
|
use SilverStripe\Core\Injector\Injector; |
14
|
|
|
use SilverStripe\Dev\SapphireTest; |
15
|
|
|
use SilverStripe\View\ArrayData; |
16
|
|
|
|
17
|
|
|
class FulltextSearchExtensionTest extends SapphireTest |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var BaseIndex |
22
|
|
|
*/ |
23
|
|
|
protected $index; |
24
|
|
|
|
25
|
|
|
public function testSearch() |
26
|
|
|
{ |
27
|
|
|
$query = new BaseQuery(); |
28
|
|
|
$query->addTerm('Test'); |
29
|
|
|
|
30
|
|
|
$result = $this->index->search($query, 0, 10, [], true); |
31
|
|
|
|
32
|
|
|
$this->assertInstanceOf(ArrayData::class, $result); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testSearchWithFields() |
36
|
|
|
{ |
37
|
|
|
$query = new BaseQuery(); |
38
|
|
|
$query->addTerm('Test'); |
39
|
|
|
|
40
|
|
|
$result = $this->index->search($query, 0, 10, ['fq' => 'Title'], true); |
41
|
|
|
|
42
|
|
|
$this->assertInstanceOf(ArrayData::class, $result); |
43
|
|
|
|
44
|
|
|
$this->assertEquals(['Title'], $query->getFields()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testAddFulltextFields() |
48
|
|
|
{ |
49
|
|
|
$index = new TestIndex(); |
50
|
|
|
$index2 = new TestIndex(); |
51
|
|
|
|
52
|
|
|
$extension1 = new FulltextSearchExtension(); |
53
|
|
|
$extension1->setOwner($index); |
54
|
|
|
|
55
|
|
|
$this->assertEquals($extension1->addFulltextFields(), $index2->addAllFulltextFields()); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @expectedException \LogicException |
60
|
|
|
*/ |
61
|
|
|
public function testInitToYml() |
62
|
|
|
{ |
63
|
|
|
$this->index->initToYml(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
protected function setUp() |
68
|
|
|
{ |
69
|
|
|
$task = new SolrConfigureTask(); |
70
|
|
|
$task->setLogger(new NullLogger()); |
71
|
|
|
$task->run(new NullHTTPRequest()); |
72
|
|
|
|
73
|
|
|
$this->index = Injector::inst()->get(TestIndex::class, false); |
74
|
|
|
|
75
|
|
|
parent::setUp(); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.