1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kitodo\Dlf\Tests\Functional\Common; |
4
|
|
|
|
5
|
|
|
use Kitodo\Dlf\Common\Doc; |
6
|
|
|
use Kitodo\Dlf\Common\Indexer; |
7
|
|
|
use Kitodo\Dlf\Common\Solr; |
8
|
|
|
use Kitodo\Dlf\Domain\Model\SolrCore; |
9
|
|
|
use Kitodo\Dlf\Domain\Repository\DocumentRepository; |
10
|
|
|
use Kitodo\Dlf\Domain\Repository\SolrCoreRepository; |
11
|
|
|
use Kitodo\Dlf\Tests\Functional\FunctionalTestCase; |
12
|
|
|
use TYPO3\CMS\Core\Core\Bootstrap; |
13
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
14
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManager; |
15
|
|
|
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager; |
16
|
|
|
|
17
|
|
|
class SolrIndexingTest extends FunctionalTestCase |
18
|
|
|
{ |
19
|
|
|
/** @var PersistenceManager */ |
20
|
|
|
protected $persistenceManager; |
21
|
|
|
|
22
|
|
|
/** @var DocumentRepository */ |
23
|
|
|
protected $documentRepository; |
24
|
|
|
|
25
|
|
|
/** @var SolrCoreRepository */ |
26
|
|
|
protected $solrCoreRepository; |
27
|
|
|
|
28
|
|
|
public function setUp(): void |
29
|
|
|
{ |
30
|
|
|
parent::setUp(); |
31
|
|
|
|
32
|
|
|
// Needed for Indexer::add, which uses the language service |
33
|
|
|
Bootstrap::initializeLanguageObject(); |
34
|
|
|
|
35
|
|
|
$this->persistenceManager = $this->objectManager->get(PersistenceManager::class); |
|
|
|
|
36
|
|
|
|
37
|
|
|
$this->documentRepository = $this->initializeRepository(DocumentRepository::class, 20000); |
38
|
|
|
$this->solrCoreRepository = $this->initializeRepository(SolrCoreRepository::class, 20000); |
39
|
|
|
|
40
|
|
|
$this->importDataSet(__DIR__ . '/../../Fixtures/Common/documents_1.xml'); |
41
|
|
|
$this->importDataSet(__DIR__ . '/../../Fixtures/Common/libraries.xml'); |
42
|
|
|
$this->importDataSet(__DIR__ . '/../../Fixtures/Common/metadata.xml'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @test |
47
|
|
|
*/ |
48
|
|
|
public function canCreateCore() |
49
|
|
|
{ |
50
|
|
|
$coreName = uniqid('testCore'); |
51
|
|
|
$solr = Solr::getInstance($coreName); |
52
|
|
|
$this->assertNull($solr->core); |
53
|
|
|
|
54
|
|
|
$actualCoreName = Solr::createCore($coreName); |
55
|
|
|
$this->assertEquals($actualCoreName, $coreName); |
56
|
|
|
|
57
|
|
|
$solr = Solr::getInstance($coreName); |
58
|
|
|
$this->assertNotNull($solr->core); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @test |
63
|
|
|
*/ |
64
|
|
|
public function canIndexAndSearchDocument() |
65
|
|
|
{ |
66
|
|
|
$core = $this->createSolrCore(); |
67
|
|
|
|
68
|
|
|
$document = $this->documentRepository->findByUid(1001); |
69
|
|
|
$document->setSolrcore($core->model->getUid()); |
70
|
|
|
$this->persistenceManager->persistAll(); |
71
|
|
|
|
72
|
|
|
$doc = Doc::getInstance($document->getLocation()); |
73
|
|
|
$document->setDoc($doc); |
74
|
|
|
|
75
|
|
|
$indexingSuccessful = Indexer::add($document); |
|
|
|
|
76
|
|
|
$this->assertTrue($indexingSuccessful); |
77
|
|
|
|
78
|
|
|
$solrSettings = [ |
79
|
|
|
'solrcore' => $core->solr->core, |
80
|
|
|
'storagePid' => $document->getPid(), |
81
|
|
|
]; |
82
|
|
|
|
83
|
|
|
$result = $this->documentRepository->findSolrByCollection(null, $solrSettings, ['query' => '*']); |
84
|
|
|
$this->assertEquals(1, $result['numberOfToplevels']); |
85
|
|
|
$this->assertEquals(15, count($result['solrResults']['documents'])); |
86
|
|
|
|
87
|
|
|
// Check that the title stored in Solr matches the title of database entry |
88
|
|
|
$docTitleInSolr = false; |
89
|
|
|
foreach ($result['solrResults']['documents'] as $solrDoc) { |
90
|
|
|
if ($solrDoc['toplevel'] && $solrDoc['uid'] === $document->getUid()) { |
91
|
|
|
$this->assertEquals($document->getTitle(), $solrDoc['title']); |
92
|
|
|
$docTitleInSolr = true; |
93
|
|
|
break; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
$this->assertTrue($docTitleInSolr); |
97
|
|
|
|
98
|
|
|
// $result['documents'] is hydrated from the database model |
99
|
|
|
$this->assertEquals($document->getTitle(), $result['documents'][$document->getUid()]['title']); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
protected function createSolrCore(): object |
103
|
|
|
{ |
104
|
|
|
$coreName = Solr::createCore(); |
105
|
|
|
$solr = Solr::getInstance($coreName); |
106
|
|
|
|
107
|
|
|
$model = GeneralUtility::makeInstance(SolrCore::class); |
108
|
|
|
$model->setLabel('Testing Solr Core'); |
109
|
|
|
$model->setIndexName($coreName); |
110
|
|
|
$this->solrCoreRepository->add($model); |
111
|
|
|
$this->persistenceManager->persistAll(); |
112
|
|
|
|
113
|
|
|
return (object) compact('solr', 'model'); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
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.