1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
5
|
|
|
* |
6
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
7
|
|
|
* |
8
|
|
|
* @license GNU General Public License version 3 or later. |
9
|
|
|
* For the full copyright and license information, please read the |
10
|
|
|
* LICENSE.txt file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Kitodo\Dlf\Tests\Functional\Common; |
14
|
|
|
|
15
|
|
|
use Kitodo\Dlf\Common\Solr\Solr; |
16
|
|
|
use Kitodo\Dlf\Domain\Repository\DocumentRepository; |
17
|
|
|
use Kitodo\Dlf\Domain\Repository\SolrCoreRepository; |
18
|
|
|
use Kitodo\Dlf\Tests\Functional\FunctionalTestCase; |
19
|
|
|
|
20
|
|
|
class SolrTest extends FunctionalTestCase |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
private static array $databaseFixtures = [ |
24
|
|
|
__DIR__ . '/../../Fixtures/Common/documents_1.csv', |
25
|
|
|
__DIR__ . '/../../Fixtures/Common/pages.csv', |
26
|
|
|
__DIR__ . '/../../Fixtures/Common/solrcores.csv' |
27
|
|
|
]; |
28
|
|
|
|
29
|
|
|
private static array $solrFixtures = [ |
30
|
|
|
__DIR__ . '/../../Fixtures/Common/documents_1.solr.json' |
31
|
|
|
]; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @test |
35
|
|
|
*/ |
36
|
|
|
public function canCreateCore() |
37
|
|
|
{ |
38
|
|
|
$this->assertEquals('newCoreName', Solr::createCore('newCoreName')); |
39
|
|
|
$this->assertEquals('newCoreName', Solr::getInstance('newCoreName')->core); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @test |
44
|
|
|
*/ |
45
|
|
|
public function canEscapeQuery() |
46
|
|
|
{ |
47
|
|
|
$query1 = Solr::escapeQuery('"custom query with special characters: "testvalue"\n"'); |
48
|
|
|
$this->assertEquals('"custom query with special characters\: "testvalue"\\\\n"', $query1); |
49
|
|
|
|
50
|
|
|
$query2 = Solr::escapeQuery('+ - && || ! ( ) { } [ ] ^ " ~ * ? : \ /'); |
51
|
|
|
$this->assertEquals('+ - && || ! ( ) \{ \} \[ \] ^ " ~ * ? \: \\\ \/', $query2); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @test |
56
|
|
|
*/ |
57
|
|
|
public function canEscapeQueryKeepField() |
58
|
|
|
{ |
59
|
|
|
$query1 = Solr::escapeQueryKeepField('abc_uui:(abc)', 0); |
60
|
|
|
$this->assertEquals('abc_uui\:(abc)', $query1); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @test |
65
|
|
|
*/ |
66
|
|
|
public function canGetNextCoreNumber() |
67
|
|
|
{ |
68
|
|
|
$this->assertEquals(5, Solr::getNextCoreNumber()); |
69
|
|
|
$this->assertEquals(5, Solr::getNextCoreNumber()); |
70
|
|
|
Solr::createCore(); |
71
|
|
|
$this->assertEquals(6, Solr::getNextCoreNumber()); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @test |
76
|
|
|
*/ |
77
|
|
|
public function canSearchRaw() |
78
|
|
|
{ |
79
|
|
|
$this->setUpData(self::$databaseFixtures); |
80
|
|
|
$solr = $this->setUpSolr(4, 0, self::$solrFixtures); |
81
|
|
|
$resultSet = $solr->searchRaw(['core' => 4, 'collection' => 1]); |
82
|
|
|
|
83
|
|
|
$this->assertCount(33, $resultSet); |
84
|
|
|
$this->assertEquals('Solarium\QueryType\Select\Result\Document', get_class($resultSet[0])); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
protected function setUpData($databaseFixtures): void |
88
|
|
|
{ |
89
|
|
|
foreach ($databaseFixtures as $filePath) { |
90
|
|
|
$this->importCSVDataSet($filePath); |
91
|
|
|
} |
92
|
|
|
$this->initializeRepository(DocumentRepository::class, 0); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
protected function setUpSolr($uid, $storagePid, $solrFixtures) |
96
|
|
|
{ |
97
|
|
|
$solrCoreRepository = $this->initializeRepository(SolrCoreRepository::class, $storagePid); |
98
|
|
|
|
99
|
|
|
// Setup Solr only once for all tests in this suite |
100
|
|
|
static $solr = null; |
101
|
|
|
|
102
|
|
|
if ($solr === null) { |
103
|
|
|
$coreName = Solr::createCore(); |
104
|
|
|
$solr = Solr::getInstance($coreName); |
105
|
|
|
foreach ($solrFixtures as $filePath) { |
106
|
|
|
$this->importSolrDocuments($solr, $filePath); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
$coreModel = $solrCoreRepository->findByUid($uid); |
111
|
|
|
$coreModel->setIndexName($solr->core); |
112
|
|
|
$solrCoreRepository->update($coreModel); |
113
|
|
|
$this->persistenceManager->persistAll(); |
114
|
|
|
return $solr; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|