Skip to content

Commit

Permalink
Merge pull request #2 from NilsFGFriedrich/elasticsearch7-testing
Browse files Browse the repository at this point in the history
Elasticsearch7 testing.
IndexingServiceTest at first didn't worked because the elasticsearch node didn't refreshed fast enough.
SearchQueryTest wasn't working because the TermSuggestFeature is referring to the deprecated and removed _all field. Creating an _all field fixes this, but it isn't the best optimal way of dealing with this. Giving the user an option of setting their own fields could be a possible solution.
  • Loading branch information
NilsFGFriedrich authored Jun 20, 2022
2 parents 4a90087 + d2cdd69 commit f86c6cc
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
pull_request:
branches:
- master
- elasticsearch7
- elasticsearch7-testing
schedule:
- cron: '0 7 * * *'

Expand All @@ -26,6 +26,7 @@ jobs:
- '^10.4'
elasticsearch:
- '5'
- '7'

steps:
- uses: actions/checkout@v3
Expand Down
85 changes: 82 additions & 3 deletions Tests/Functional/AbstractElasticsearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,26 @@ protected function setUp(): void
'pid' => 1,
],
],
'mapping' => [
"dynamic_templates" => [
[
"all_text" => [
"match_mapping_type" => "string",
"mapping" => [
"copy_to" => "_all",
"type" => "text",
],
],
],
],
"properties" => [
"_all" => [
"type" => "text",
],
],
],
],
],
],
'bar_pages' => [
'className' => PagesIndexer::class,
'config' => [
Expand All @@ -137,6 +155,24 @@ protected function setUp(): void
'pid' => 100,
],
],
'mapping' => [
"dynamic_templates" => [
[
"all_text" => [
"match_mapping_type" => "string",
"mapping" => [
"copy_to" => "_all",
"type" => "text",
],
],
],
],
"properties" => [
"_all" => [
"type" => "text",
],
],
],
],
],
'qux_pages' => [
Expand All @@ -148,6 +184,24 @@ protected function setUp(): void
'pid' => 200,
],
],
'mapping' => [
"dynamic_templates" => [
[
"all_text" => [
"match_mapping_type" => "string",
"mapping" => [
"copy_to" => "_all",
"type" => "text",
],
],
],
],
"properties" => [
"_all" => [
"type" => "text",
],
],
],
],
],
'content' => [
Expand All @@ -166,10 +220,28 @@ protected function setUp(): void
'preview' => [
'className' => ContentPreviewRenderer::class,
],
'mapping' => [
"dynamic_templates" => [
[
"all_text" => [
"match_mapping_type" => "string",
"mapping" => [
"copy_to" => "_all",
"type" => "text",
],
],
],
],
"properties" => [
"_all" => [
"type" => "text",
],
],
],
],
],
],
]
],
);

$this->getDatabaseConnection()->insertArray('pages', [
Expand Down Expand Up @@ -243,6 +315,9 @@ protected function assertIndexeEmpty(int $languageId = 0): void
$this->syncIndices();
$indexe = ExtconfService::getLanguageIndicies($languageId);
$indexString = implode(',', $indexe);
$client->indices()->refresh([
'index' => $indexString,
]);

$response = $client->search([
'index' => $indexString,
Expand Down Expand Up @@ -281,6 +356,10 @@ protected function searchDocumentByUid(int $uid, int $languageId): array
$indexe = ExtconfService::getLanguageIndicies($languageId);
$indexString = implode(',', $indexe);

$client->indices()->refresh([
'index' => $indexString,
]);

$response = $client->search([
'index' => $indexString,
'body' => [
Expand All @@ -304,7 +383,7 @@ protected function searchDocumentByUid(int $uid, int $languageId): array
*/
protected function syncIndices(): void
{
$this->getElasticsearchClient()->indices()->flushSynced([
$this->getElasticsearchClient()->indices()->flush([
'index' => implode(',', array_merge(
$this->indexNames,
['searchable_updates']
Expand Down
5 changes: 3 additions & 2 deletions Tests/Functional/Query/SearchQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ public function searchesByTerm(): void
'doktype' => PageRepository::DOKTYPE_DEFAULT,
'title' => 'Unrelated page',
]);

$this->indexingService->indexFull();
$this->syncIndices();

$query = GeneralUtility::makeInstance(SearchQuery::class);
$query->setTerm('test');
$client = $this->getElasticsearchClient();
$client->indices()->refresh();

$result = $query->execute();

Expand Down
11 changes: 10 additions & 1 deletion Tests/Functional/Service/IndexingServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ public function appliesLanguageForRecordTranslationIndexing(): void
$this->indexingService->setup();
$this->indexingService->indexFull('content');

$client = $this->getElasticsearchClient();
$client->indices()->refresh();

$this->assertDocumentInIndex(
1,
[
Expand Down Expand Up @@ -193,9 +196,12 @@ public function indexesRecordsPartially(): void
);

$this->syncIndices();

$client = $this->getElasticsearchClient();
$client->indices()->refresh();
$this->indexingService->indexPartial();

$client = $this->getElasticsearchClient();
$client->indices()->refresh();
$this->assertDocumentInIndex(
2,
[
Expand Down Expand Up @@ -282,6 +288,9 @@ public function respectsSiteBase(): void

$this->indexingService->indexFull();

$client = $this->getElasticsearchClient();
$client->indices()->refresh();

$this->assertDocumentInIndex(
101,
[
Expand Down
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@ services:

elasticsearch:
image: elasticsearch:${ELASTICSEARCH_VERSION:-5}
# image: elasticsearch:${ELASTICSEARCH_VERSION:-7.17.4}
# environment:
# - ingest.geoip.downloader.enabled=false
# - discovery.type=single-node
# command: ["elasticsearch", "-Elogger.level=DEBUG"]

0 comments on commit f86c6cc

Please sign in to comment.