|
1
|
|
|
<?php declare(strict_types = 1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Suilven\ManticoreSearch\Tests\Service; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\CMS\Model\SiteTree; |
|
6
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
7
|
|
|
use Suilven\FreeTextSearch\Helper\BulkIndexingHelper; |
|
8
|
|
|
use Suilven\FreeTextSearch\Indexes; |
|
9
|
|
|
use Suilven\FreeTextSearch\Types\SearchParamTypes; |
|
|
|
|
|
|
10
|
|
|
use Suilven\ManticoreSearch\Helper\ReconfigureIndexesHelper; |
|
11
|
|
|
use Suilven\ManticoreSearch\Service\Searcher; |
|
12
|
|
|
use Suilven\ManticoreSearch\Tests\Models\FlickrAuthor; |
|
13
|
|
|
use Suilven\ManticoreSearch\Tests\Models\FlickrPhoto; |
|
14
|
|
|
use Suilven\ManticoreSearch\Tests\Models\FlickrSet; |
|
15
|
|
|
use Suilven\ManticoreSearch\Tests\Models\FlickrTag; |
|
16
|
|
|
|
|
17
|
|
|
class SearchFixturesTest extends SapphireTest |
|
18
|
|
|
{ |
|
19
|
|
|
protected static $fixture_file = ['tests/fixtures/sitetree.yml', 'tests/fixtures/flickrphotos.yml']; |
|
20
|
|
|
|
|
21
|
|
|
protected static $extra_dataobjects = [ |
|
22
|
|
|
FlickrPhoto::class, |
|
23
|
|
|
FlickrTag::class, |
|
24
|
|
|
FlickrSet::class, |
|
25
|
|
|
FlickrAuthor::class, |
|
26
|
|
|
]; |
|
27
|
|
|
|
|
28
|
|
|
/** @var int */ |
|
29
|
|
|
private static $pageID; |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
public function setUp(): void |
|
32
|
|
|
{ |
|
33
|
|
|
parent::setUp(); |
|
34
|
|
|
|
|
35
|
|
|
/** @var \Suilven\FreeTextSearch\Indexes $indexesService */ |
|
36
|
|
|
$indexesService = new Indexes(); |
|
37
|
|
|
$indexesArray = $indexesService->getIndexes(); |
|
38
|
|
|
$helper = new ReconfigureIndexesHelper(); |
|
39
|
|
|
$helper->reconfigureIndexes($indexesArray); |
|
40
|
|
|
|
|
41
|
|
|
\error_log('INDEXING'); |
|
42
|
|
|
$helper = new BulkIndexingHelper(); |
|
43
|
|
|
$helper->bulkIndex('sitetree'); |
|
44
|
|
|
\error_log('/INDEXING'); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
public function testSimilar(): void |
|
49
|
|
|
{ |
|
50
|
|
|
$page = $this->objFromFixture(SiteTree::class, 'sitetree_49'); |
|
51
|
|
|
$searcher = new Searcher(); |
|
52
|
|
|
$searcher->setIndexName('sitetree'); |
|
53
|
|
|
$result = $searcher->searchForSimilar($page); |
|
54
|
|
|
|
|
55
|
|
|
// 1 is the original doc, 3 others contain sheep, 1 contains mussy an 1 contains shuttlecock |
|
56
|
|
|
$this->assertEquals(6, $result->getTotaNumberOfResults()); |
|
57
|
|
|
$hits = $result->getRecords(); |
|
58
|
|
|
$ids = []; |
|
59
|
|
|
foreach ($hits as $hit) { |
|
60
|
|
|
$ids[] = $hit->ID; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
$this->assertEquals([49, 40, 45, 21, 36, 47], $ids); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
public function testAndSearch(): void |
|
68
|
|
|
{ |
|
69
|
|
|
$searcher = new Searcher(); |
|
70
|
|
|
$searcher->setIndexName('sitetree'); |
|
71
|
|
|
$searcher->setSearchType(SearchParamTypes::AND); |
|
|
|
|
|
|
72
|
|
|
$result = $searcher->search('sheep shuttlecock'); |
|
73
|
|
|
$this->assertEquals(1, $result->getTotaNumberOfResults()); |
|
74
|
|
|
$hits = $result->getRecords(); |
|
75
|
|
|
$ids = []; |
|
76
|
|
|
foreach ($hits as $hit) { |
|
77
|
|
|
$ids[] = $hit->ID; |
|
78
|
|
|
} |
|
79
|
|
|
$this->assertEquals([49], $ids); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
public function testORSearch(): void |
|
84
|
|
|
{ |
|
85
|
|
|
$searcher = new Searcher(); |
|
86
|
|
|
$searcher->setIndexName('sitetree'); |
|
87
|
|
|
$searcher->setSearchType(SearchParamTypes::OR); |
|
88
|
|
|
$result = $searcher->search('sheep shuttlecock'); |
|
89
|
|
|
$this->assertEquals(5, $result->getTotaNumberOfResults()); |
|
90
|
|
|
$hits = $result->getRecords(); |
|
91
|
|
|
$ids = []; |
|
92
|
|
|
foreach ($hits as $hit) { |
|
93
|
|
|
$ids[] = $hit->ID; |
|
94
|
|
|
} |
|
95
|
|
|
$this->assertEquals([49, 45, 21, 36, 47], $ids); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths