mirror of
https://github.com/Codappix/search_core.git
synced 2024-11-22 15:56:11 +01:00
Merge pull request #139 from Codappix/hotfix/135-limit-page-indexing
Hotfix: Limit page indexing for own conten elements
This commit is contained in:
commit
ad7befb911
4 changed files with 51 additions and 19 deletions
|
@ -79,8 +79,14 @@ class PagesIndexer extends TcaIndexer
|
||||||
protected function fetchContentForPage(int $uid) : array
|
protected function fetchContentForPage(int $uid) : array
|
||||||
{
|
{
|
||||||
if ($this->contentTableService instanceof TcaTableService) {
|
if ($this->contentTableService instanceof TcaTableService) {
|
||||||
$contentElements = $this->contentTableService->getQuery()
|
$queryBuilder = $this->contentTableService->getQuery();
|
||||||
->execute()->fetchAll();
|
$queryBuilder->andWhere(
|
||||||
|
$queryBuilder->expr()->eq(
|
||||||
|
$this->contentTableService->getTableName() . '.pid',
|
||||||
|
$queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$contentElements = $queryBuilder->execute()->fetchAll();
|
||||||
} else {
|
} else {
|
||||||
$contentElements = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
|
$contentElements = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
|
||||||
$this->contentTableService->getFields(),
|
$this->contentTableService->getFields(),
|
||||||
|
|
|
@ -49,12 +49,11 @@ class IndexTcaTableTest extends AbstractFunctionalTestCase
|
||||||
|
|
||||||
$response = $this->client->request('typo3content/_search?q=*:*');
|
$response = $this->client->request('typo3content/_search?q=*:*');
|
||||||
|
|
||||||
$this->assertTrue($response->isOK(), 'Elastica did not answer with ok code.');
|
$this->assertTrue($response->isOk(), 'Elastica did not answer with ok code.');
|
||||||
$this->assertSame($response->getData()['hits']['total'], 2, 'Not exactly 2 documents were indexed.');
|
$this->assertSame($response->getData()['hits']['total'], 3, 'Not exactly 3 documents were indexed.');
|
||||||
$this->assertArraySubset(
|
$this->assertSame(
|
||||||
['_source' => ['header' => 'indexed content element']],
|
'indexed content element',
|
||||||
$response->getData()['hits']['hits'][1],
|
$response->getData()['hits']['hits'][2]['_source']['header'],
|
||||||
false,
|
|
||||||
'Record was not indexed.'
|
'Record was not indexed.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -72,7 +71,7 @@ class IndexTcaTableTest extends AbstractFunctionalTestCase
|
||||||
|
|
||||||
$response = $this->client->request('typo3content/_search?q=*:*');
|
$response = $this->client->request('typo3content/_search?q=*:*');
|
||||||
|
|
||||||
$this->assertTrue($response->isOK(), 'Elastica did not answer with ok code.');
|
$this->assertTrue($response->isOk(), 'Elastica did not answer with ok code.');
|
||||||
$this->assertSame($response->getData()['hits']['total'], 1, 'Not exactly 1 document was indexed.');
|
$this->assertSame($response->getData()['hits']['total'], 1, 'Not exactly 1 document was indexed.');
|
||||||
$this->assertArraySubset(
|
$this->assertArraySubset(
|
||||||
['_source' => ['header' => 'indexed content element']],
|
['_source' => ['header' => 'indexed content element']],
|
||||||
|
@ -112,8 +111,8 @@ class IndexTcaTableTest extends AbstractFunctionalTestCase
|
||||||
|
|
||||||
$response = $this->client->request('typo3content/_search?q=*:*');
|
$response = $this->client->request('typo3content/_search?q=*:*');
|
||||||
|
|
||||||
$this->assertTrue($response->isOK(), 'Elastica did not answer with ok code.');
|
$this->assertTrue($response->isOk(), 'Elastica did not answer with ok code.');
|
||||||
$this->assertSame($response->getData()['hits']['total'], 2, 'Not exactly 2 documents were indexed.');
|
$this->assertSame($response->getData()['hits']['total'], 3, 'Not exactly 3 documents were indexed.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -135,8 +134,8 @@ class IndexTcaTableTest extends AbstractFunctionalTestCase
|
||||||
|
|
||||||
$response = $this->client->request('typo3content/_search?q=*:*');
|
$response = $this->client->request('typo3content/_search?q=*:*');
|
||||||
|
|
||||||
$this->assertTrue($response->isOK(), 'Elastica did not answer with ok code.');
|
$this->assertTrue($response->isOk(), 'Elastica did not answer with ok code.');
|
||||||
$this->assertSame($response->getData()['hits']['total'], 3, 'Not exactly 3 documents were indexed.');
|
$this->assertSame($response->getData()['hits']['total'], 4, 'Not exactly 4 documents were indexed.');
|
||||||
$response = $this->client->request('typo3content/_search?q=uid:11');
|
$response = $this->client->request('typo3content/_search?q=uid:11');
|
||||||
$this->assertArraySubset(
|
$this->assertArraySubset(
|
||||||
['_source' => ['header' => 'Also indexable record']],
|
['_source' => ['header' => 'Also indexable record']],
|
||||||
|
@ -167,8 +166,8 @@ class IndexTcaTableTest extends AbstractFunctionalTestCase
|
||||||
;
|
;
|
||||||
|
|
||||||
$response = $this->client->request('typo3content/_search?q=*:*');
|
$response = $this->client->request('typo3content/_search?q=*:*');
|
||||||
$this->assertTrue($response->isOK(), 'Elastica did not answer with ok code.');
|
$this->assertTrue($response->isOk(), 'Elastica did not answer with ok code.');
|
||||||
$this->assertSame($response->getData()['hits']['total'], 4, 'Not exactly 4 documents were indexed.');
|
$this->assertSame($response->getData()['hits']['total'], 5, 'Not exactly 5 documents were indexed.');
|
||||||
|
|
||||||
$response = $this->client->request('typo3content/_search?q=uid:11');
|
$response = $this->client->request('typo3content/_search?q=uid:11');
|
||||||
$this->assertArraySubset(
|
$this->assertArraySubset(
|
||||||
|
@ -209,7 +208,7 @@ class IndexTcaTableTest extends AbstractFunctionalTestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function indexingDeltedRecordIfRecordShouldBeIndexedButIsNoLongerAvailableAndWasAlreadyIndexed()
|
public function indexingDeletedRecordIfRecordShouldBeIndexedButIsNoLongerAvailableAndWasAlreadyIndexed()
|
||||||
{
|
{
|
||||||
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class)
|
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class)
|
||||||
->get(IndexerFactory::class)
|
->get(IndexerFactory::class)
|
||||||
|
@ -218,7 +217,7 @@ class IndexTcaTableTest extends AbstractFunctionalTestCase
|
||||||
;
|
;
|
||||||
|
|
||||||
$response = $this->client->request('typo3content/_search?q=*:*');
|
$response = $this->client->request('typo3content/_search?q=*:*');
|
||||||
$this->assertSame($response->getData()['hits']['total'], 2, 'Not exactly 2 documents were indexed.');
|
$this->assertSame($response->getData()['hits']['total'], 3, 'Not exactly 3 documents were indexed.');
|
||||||
|
|
||||||
if ($this->isLegacyVersion()) {
|
if ($this->isLegacyVersion()) {
|
||||||
$this->getDatabaseConnection()
|
$this->getDatabaseConnection()
|
||||||
|
@ -239,6 +238,6 @@ class IndexTcaTableTest extends AbstractFunctionalTestCase
|
||||||
;
|
;
|
||||||
|
|
||||||
$response = $this->client->request('typo3content/_search?q=*:*');
|
$response = $this->client->request('typo3content/_search?q=*:*');
|
||||||
$this->assertSame($response->getData()['hits']['total'], 1, 'Not exactly 1 document is in index.');
|
$this->assertSame($response->getData()['hits']['total'], 2, 'Not exactly 2 document is in index.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,4 +99,31 @@
|
||||||
<colPos>0</colPos>
|
<colPos>0</colPos>
|
||||||
<filelink_sorting>0</filelink_sorting>
|
<filelink_sorting>0</filelink_sorting>
|
||||||
</tt_content>
|
</tt_content>
|
||||||
|
|
||||||
|
<tt_content>
|
||||||
|
<uid>100</uid>
|
||||||
|
<pid>2</pid>
|
||||||
|
<tstamp>1480686370</tstamp>
|
||||||
|
<crdate>1480686370</crdate>
|
||||||
|
<hidden>0</hidden>
|
||||||
|
<sorting>72</sorting>
|
||||||
|
<CType>header</CType>
|
||||||
|
<header>Indexed on page 2</header>
|
||||||
|
<bodytext>This element is on a different page</bodytext>
|
||||||
|
<media>0</media>
|
||||||
|
<layout>0</layout>
|
||||||
|
<deleted>0</deleted>
|
||||||
|
<cols>0</cols>
|
||||||
|
<starttime>0</starttime>
|
||||||
|
<endtime>0</endtime>
|
||||||
|
<colPos>0</colPos>
|
||||||
|
<filelink_sorting>0</filelink_sorting>
|
||||||
|
</tt_content>
|
||||||
|
|
||||||
|
<pages>
|
||||||
|
<uid>2</uid>
|
||||||
|
<pid>1</pid>
|
||||||
|
<title>Second page with content</title>
|
||||||
|
<description>Used to check whether content is indexed only for parent page.</description>
|
||||||
|
</pages>
|
||||||
</dataset>
|
</dataset>
|
||||||
|
|
|
@ -48,7 +48,7 @@ class PagesIndexerTest extends AbstractFunctionalTestCase
|
||||||
->with(
|
->with(
|
||||||
$this->stringContains($tableName),
|
$this->stringContains($tableName),
|
||||||
$this->callback(function ($documents) {
|
$this->callback(function ($documents) {
|
||||||
return count($documents) === 1
|
return count($documents) === 2
|
||||||
&& isset($documents[0]['content']) && $documents[0]['content'] ===
|
&& isset($documents[0]['content']) && $documents[0]['content'] ===
|
||||||
'this is the content of header content element that should get indexed Some text in paragraph'
|
'this is the content of header content element that should get indexed Some text in paragraph'
|
||||||
&& isset($documents[0]['search_abstract']) && $documents[0]['search_abstract'] ===
|
&& isset($documents[0]['search_abstract']) && $documents[0]['search_abstract'] ===
|
||||||
|
|
Loading…
Reference in a new issue