Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip pages with "no_search" via query #24

Merged
merged 1 commit into from
Oct 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Classes/DataCollector/PagesDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,13 @@ protected function getPageRecords($pid = null)

$rawList = $this->pageRepository->getMenu(
$pid,
'uid, doktype, shortcut, shortcut_mode, no_search',
implode(',', [
'uid',
'doktype',
'shortcut',
'shortcut_mode',
'no_search',
]),
'sorting',
$whereClause
);
Expand Down
42 changes: 32 additions & 10 deletions Tests/Functional/AbstractElasticsearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,29 +182,51 @@ protected function assertIndexEmpty(int $languageId = 0): void
$this->assertEquals(0, $total, 'Documents in index');
}

protected function assertDocumentInIndex(array $documentSubset, int $languageId = 0): void
protected function assertDocumentInIndex(int $uid, array $documentSubset = [], int $languageId = 0): void
{
$client = $this->getElasticsearchClient();
$this->syncIndices();

$response = $client->search([
'index' => $this->indexNames[$languageId],
]);
$hits = $response['hits']['hits'];
$document = $hits[0]['_source'] ?? [];
$document = $this->searchDocumentByUid($uid, $languageId);

$this->assertGreaterThanOrEqual(1, count($hits), 'No document in index');
$this->assertNotEmpty($document, 'Document not in index');
$this->assertArraySubset($documentSubset, $document, false, 'Document source mismatch');
}

protected function assertDocumentNotInIndex(int $uid, int $languageId = 0): void
{
$document = $this->searchDocumentByUid($uid, $languageId);

$this->assertEmpty($document, 'Document in index');
}

protected function getElasticsearchClient(): ElasticsearchClient
{
$client = Connection::getClient();

return $client;
}

protected function searchDocumentByUid(int $uid, int $languageId): array
{
$client = $this->getElasticsearchClient();
$this->syncIndices();

$response = $client->search([
'index' => $this->indexNames[$languageId],
'body' => [
'query' => [
'term' => [
'uid' => [
'value' => $uid,
],
],
],
],
]);
$hits = $response['hits']['hits'];
$document = $hits[0]['_source'] ?? [];

return $document;
}

/**
* Ensure all queued changes are persisted
*/
Expand Down
119 changes: 88 additions & 31 deletions Tests/Functional/Service/IndexingServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ public function indexesRecordsFully(): void

$this->indexingService->indexFull();

$this->assertDocumentInIndex([
'uid' => 2,
'title' => 'Test page',
'searchable_meta' => [
'renderedLink' => version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9', '>=') ? '/test-page/' : 'index.php?id=2',
],
]);
$this->assertDocumentInIndex(
2,
[
'title' => 'Test page',
'searchable_meta' => [
'renderedLink' => version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9', '>=') ? '/test-page/' : 'index.php?id=2',
],
]
);
}

/**
Expand Down Expand Up @@ -117,13 +119,16 @@ public function indexesRecordTranslations(): void

$this->indexingService->indexFull();

$this->assertDocumentInIndex([
'uid' => 2,
'title' => 'Translated test page',
'searchable_meta' => [
'renderedLink' => version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9', '>=') ? '/da/translated-test-page/' : 'index.php?id=2&L=1',
$this->assertDocumentInIndex(
2,
[
'title' => 'Translated test page',
'searchable_meta' => [
'renderedLink' => version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9', '>=') ? '/da/translated-test-page/' : 'index.php?id=2&L=1',
],
],
], 1);
1
);
}

/**
Expand Down Expand Up @@ -154,20 +159,26 @@ public function appliesLanguageForRecordTranslationIndexing(): void
$this->indexingService->setup();
$this->indexingService->indexFull('content');

$this->assertDocumentInIndex([
'uid' => 1,
'header' => 'Test content',
'searchable_meta' => [
'preview' => 'Preview: Test content [1]',
$this->assertDocumentInIndex(
1,
[
'header' => 'Test content',
'searchable_meta' => [
'preview' => 'Preview: Test content [1]',
],
],
], 0);
$this->assertDocumentInIndex([
'uid' => 1,
'header' => 'Translated test content',
'searchable_meta' => [
'preview' => 'Preview: Translated test content [2]',
0
);
$this->assertDocumentInIndex(
1,
[
'header' => 'Translated test content',
'searchable_meta' => [
'preview' => 'Preview: Translated test content [2]',
],
],
], 1);
1
);
}

/**
Expand All @@ -188,10 +199,12 @@ public function indexesRecordsPartially(): void

$this->indexingService->indexFull();

$this->assertDocumentInIndex([
'uid' => 2,
'title' => 'Test page',
]);
$this->assertDocumentInIndex(
2,
[
'title' => 'Test page',
]
);

$connection = GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionForTable('pages');
Expand All @@ -209,10 +222,54 @@ public function indexesRecordsPartially(): void

$this->indexingService->indexPartial();

$this->assertDocumentInIndex([
$this->assertDocumentInIndex(
2,
[
'title' => 'Updated test page',
]
);
}

/**
* @test
*/
public function skipsPagesWithNoSearchFromIndexing(): void
{
$this->getDatabaseConnection()->insertArray('pages', [
'uid' => 2,
'title' => 'Updated test page',
'pid' => 1,
'doktype' => PageRepository::DOKTYPE_DEFAULT,
'title' => 'First page to exclude',
'no_search' => 1,
]);
$this->getDatabaseConnection()->insertArray('pages', [
'uid' => 3,
'pid' => 2,
'doktype' => PageRepository::DOKTYPE_DEFAULT,
'title' => 'First regular page',
]);
$this->getDatabaseConnection()->insertArray('pages', [
'uid' => 4,
'pid' => 3,
'doktype' => PageRepository::DOKTYPE_DEFAULT,
'title' => 'Second page to exclude',
'no_search' => 1,
]);
$this->getDatabaseConnection()->insertArray('pages', [
'uid' => 5,
'pid' => 4,
'doktype' => PageRepository::DOKTYPE_DEFAULT,
'title' => 'Second regular page',
]);

$this->assertIndexEmpty();

$this->indexingService->indexFull();

$this->assertDocumentNotInIndex(2);
$this->assertDocumentInIndex(3);
$this->assertDocumentNotInIndex(4);
$this->assertDocumentInIndex(5);
}

/**
Expand Down