From 7459bb34a13af94c307feab04e8234beda20a9ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Myszka?= Date: Mon, 20 Jan 2020 14:00:13 +0100 Subject: [PATCH 1/6] EZP-31226 - Indexing depth doesn't work properly in Solr when LocationQuery is in use // debug --- .../Tests/SearchServiceFulltextTestTMP.php | 309 ++++++++++++++++++ 1 file changed, 309 insertions(+) create mode 100644 eZ/Publish/API/Repository/Tests/SearchServiceFulltextTestTMP.php diff --git a/eZ/Publish/API/Repository/Tests/SearchServiceFulltextTestTMP.php b/eZ/Publish/API/Repository/Tests/SearchServiceFulltextTestTMP.php new file mode 100644 index 00000000000..10fce1b13f8 --- /dev/null +++ b/eZ/Publish/API/Repository/Tests/SearchServiceFulltextTestTMP.php @@ -0,0 +1,309 @@ +getRepository(false) + ->getSearchService()->supports(SearchService::CAPABILITY_ADVANCED_FULLTEXT) + ) { + $this->markTestSkipped('Engine says it does not support advance fulltext format'); + } + } + + /** + * Create test Content and return Content ID map for subsequent testing. + */ + public function testPrepareContent() + { + $repository = $this->getRepository(); + + $contentService = $repository->getContentService(); + $contentTypeService = $repository->getContentTypeService(); + $locationService = $repository->getLocationService(); + + $contentType = $contentTypeService->loadContentTypeByIdentifier('article'); + $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); + $contentCreateStruct->setField('title', 'testtt'); + + $bodyDocument = new \DOMDocument(); + $bodyDocument->loadXML(<< +
+ +
+EOT + ); + + $introDocument = new \DOMDocument(); + $introDocument->loadXML(<< +
+paragraph +
+EOT + ); + + $contentCreateStruct->setField('body', new RichTextValue($bodyDocument), 'eng-GB'); + $contentCreateStruct->setField('intro', new RichTextValue($introDocument), 'eng-GB'); + + $idMap = []; + + $content = $contentService->publishVersion( + $contentService->createContent( + $contentCreateStruct, + [$locationService->newLocationCreateStruct(2)] + )->versionInfo + ); + + $idMap[1] = $content->id; + +// SECOND ARTICLE + + $contentType = $contentTypeService->loadContentTypeByIdentifier('article'); + $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); + $contentCreateStruct->setField('title', 'testtt111'); + + $bodyDocument = new \DOMDocument(); + $bodyDocument->loadXML(<< +
+​body-content +
+EOT + ); + + $introDocument = new \DOMDocument(); + $introDocument->loadXML(<< +
+paragraph 2 +
+EOT + ); + + $contentCreateStruct->setField('body', new RichTextValue($bodyDocument), 'eng-GB'); + $contentCreateStruct->setField('intro', new RichTextValue($introDocument), 'eng-GB'); + + $content = $contentService->publishVersion( + $contentService->createContent( + $contentCreateStruct, + [$locationService->newLocationCreateStruct(2)] + )->versionInfo + ); + + $idMap[2] = $content->id; + + + $this->refreshSearch($repository); + + return $idMap; + } + + /** + * Return pairs of arguments: + * - search string for testing + * - an array of corresponding Content keys as defined in testPrepareContent() method, + * ordered and grouped by relevancy. + * + * @see testPrepareContent + */ + public function providerForTestFulltextSearchSolr7(): array + { + return [ + [ + 'test', + [3, [6, 8, 10], [11, 13, 14], 15], + ], + ]; + } + + /** + * Test for the findContent() method on Solr >= 7. + * + * @param string $searchString + * @param array $expectedKeys + * @param array $idMap + * + * @depends testPrepareContent + * @dataProvider providerForTestFulltextSearchSolr7 + */ + public function testFulltextContentSearchSolr7(string $searchString, array $expectedKeys, array $idMap): void + { + if (($solrVersion = getenv('SOLR_VERSION')) < 7) { + $this->markTestSkipped('This test is only relevant for Solr >= 7'); + } + + $this->doTestFulltextContentSearch($searchString, $expectedKeys, $idMap); + } + + private function doTestFulltextContentSearch(string $searchString, array $expectedKeys, array $idMap): void + { + $repository = $this->getRepository(false); + $searchService = $repository->getSearchService(); + + $query = new Query(['query' => new Criterion\FullText($searchString)]); + $searchResult = $searchService->findContent($query); + + $this->assertFulltextSearch($searchResult, $expectedKeys, $idMap); + } + + /** + * Test for the findLocations() method on Solr >= 7. + * + * @param $searchString + * @param array $expectedKeys + * @param array $idMap + * + * @depends testPrepareContent + * @dataProvider providerForTestFulltextSearchSolr7 + */ + public function testFulltextLocationSearchSolr7($searchString, array $expectedKeys, array $idMap): void + { + if (($solrVersion = getenv('SOLR_VERSION')) < 7) { + $this->markTestSkipped('This test is only relevant for Solr >= 7'); + } + + $this->doTestFulltextLocationSearch($searchString, $expectedKeys, $idMap); + } + + private function doTestFulltextLocationSearch($searchString, array $expectedKeys, array $idMap): void + { + $repository = $this->getRepository(false); + $searchService = $repository->getSearchService(); + + $query = new LocationQuery(['query' => new Criterion\FullText($searchString)]); + $searchResult = $searchService->findLocations($query); + + $this->assertFulltextSearch($searchResult, $expectedKeys, $idMap); + } + + /** + * Assert given $searchResult using $expectedKeys and $idMap. + * + * @param \eZ\Publish\API\Repository\Values\Content\Search\SearchResult $searchResult + * @param array $expectedKeys + * @param array $idMap + */ + public function assertFulltextSearch(SearchResult $searchResult, array $expectedKeys, array $idMap) + { + $this->assertEquals( + array_reduce( + $expectedKeys, + function ($carry, $item) { + $carry += count((array)$item); + + return $carry; + }, + 0 + ), + $searchResult->totalCount + ); + + $expectedIds = $this->mapKeysToIds($expectedKeys, $idMap); + $actualIds = $this->mapSearchResultToIds($searchResult); + + $this->assertEquals($expectedIds, $actualIds); + } + + /** + * Map given array of $expectedKeys to Content IDs, using $idMap. + * + * @param array $expectedKeys + * @param array $idMap + * + * @return array + */ + private function mapKeysToIds(array $expectedKeys, array $idMap) + { + $expectedIds = []; + + foreach ($expectedKeys as $keyGroup) { + if (is_array($keyGroup)) { + $idGroup = []; + + /** @var array $keyGroup */ + foreach ($keyGroup as $key) { + $idGroup[] = $idMap[$key]; + } + + sort($idGroup); + $expectedIds[] = $idGroup; + + continue; + } + + $key = $keyGroup; + $expectedIds[] = $idMap[$key]; + } + + return $expectedIds; + } + + /** + * Map given $searchResult to an array of Content IDs, ordered and grouped by relevancy score. + * + * @param \eZ\Publish\API\Repository\Values\Content\Search\SearchResult $searchResult + * + * @return array + */ + private function mapSearchResultToIds(SearchResult $searchResult) + { + $scoreGroupedIds = []; + + foreach ($searchResult->searchHits as $index => $searchHit) { + if ($searchHit->valueObject instanceof Content || $searchHit->valueObject instanceof Location) { + $contentInfo = $searchHit->valueObject->contentInfo; + } elseif ($searchHit->valueObject instanceof ContentInfo) { + $contentInfo = $searchHit->valueObject; + } else { + throw new RuntimeException('Unknown search hit value'); + } + + $scoreGroupedIds[(string)$searchHit->score][] = $contentInfo->id; + } + + return array_map( + function (array $idGroup) { + if (count($idGroup) === 1) { + return reset($idGroup); + } + + sort($idGroup); + + return $idGroup; + }, + array_values($scoreGroupedIds) + ); + } +} From 1b3c82c4e74dda79f583be02fa2b454cc3036043 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Myszka?= Date: Mon, 20 Jan 2020 14:15:36 +0100 Subject: [PATCH 2/6] EZP-31226 - Indexing depth doesn't work properly in Solr when LocationQuery is in use --- .gitignore | 1 + .../Tests/SearchServiceFulltextEmbedTest.php | 181 ++++++++++ .../Tests/SearchServiceFulltextTestTMP.php | 309 ------------------ phpunit-integration-legacy-solr.xml | 1 + 4 files changed, 183 insertions(+), 309 deletions(-) create mode 100644 eZ/Publish/API/Repository/Tests/SearchServiceFulltextEmbedTest.php delete mode 100644 eZ/Publish/API/Repository/Tests/SearchServiceFulltextTestTMP.php diff --git a/.gitignore b/.gitignore index 45038da1c1a..b7ff6a9732b 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ composer.phar var/ composer.lock .php_cs.cache +.idea diff --git a/eZ/Publish/API/Repository/Tests/SearchServiceFulltextEmbedTest.php b/eZ/Publish/API/Repository/Tests/SearchServiceFulltextEmbedTest.php new file mode 100644 index 00000000000..9b153ac8116 --- /dev/null +++ b/eZ/Publish/API/Repository/Tests/SearchServiceFulltextEmbedTest.php @@ -0,0 +1,181 @@ +getRepository(false); + + if (false === $repository->getSearchService()->supports(SearchService::CAPABILITY_ADVANCED_FULLTEXT)) { + $this->markTestSkipped('Engine says it does not support advance fulltext format'); + } + } + + public function testPrepareContent(): void + { + $contentService = $this->getRepository()->getContentService(); + $baseArticleStruct = $this->prepareBaseArticleStruct(); + + $slaveArticleStruct = $this->fillSlaveArticleStruct(clone $baseArticleStruct); + $slaveArticleContent = $contentService->publishVersion( + $this->createContent($slaveArticleStruct)->versionInfo + ); + + $mainArticleStruct = $this->fillMainArticleStruct(clone $baseArticleStruct, $slaveArticleContent->id); + $mainArticleContent = $contentService->publishVersion( + $this->createContent($mainArticleStruct)->versionInfo + ); + + $this->refreshSearch($this->getRepository()); + + self::$createdIds = [ + $slaveArticleContent->id, + $mainArticleContent->id, + ]; + } + + /** + * @depends testPrepareContent + */ + public function testFulltextContentSearch(): void + { + $searchService = $this->getRepository()->getSearchService(); + + $query = new Query([ + 'query' => new Criterion\FullText(self::SLAVE_ARTICLE_NAME), + ]); + + $searchResult = $searchService->findContent($query); + + $this->assertGreaterThanOrEqual(2, $searchResult->totalCount); + $this->assertResults($searchResult->searchHits); + } + + /** + * @depends testPrepareContent + */ + public function testFulltextLocationSearch(): void + { + $searchService = $this->getRepository()->getSearchService(); + + $query = new LocationQuery([ + 'query' => new Criterion\FullText(self::SLAVE_ARTICLE_NAME), + ]); + + $searchResult = $searchService->findLocations($query); + + $this->assertGreaterThanOrEqual(2, $searchResult->totalCount); + $this->assertResults($searchResult->searchHits); + } + + private function prepareBaseArticleStruct(): ContentCreateStruct + { + $introDocument = new \DOMDocument(); + $introDocument->loadXML( + << +
+some paragraph +
+EOT + ); + + $repository = $this->getRepository(); + $contentType = $repository->getContentTypeService()->loadContentTypeByIdentifier('article'); + + /** @var ContentCreateStruct $articleStruct */ + $articleStruct = $repository->getContentService()->newContentCreateStruct($contentType, 'eng-GB'); + $articleStruct->setField('intro', new RichTextValue($introDocument), 'eng-GB'); + + return $articleStruct; + } + + private function fillSlaveArticleStruct(ContentCreateStruct $articleStruct): ContentCreateStruct + { + $articleBodyDoc = new \DOMDocument(); + $articleBodyDoc->loadXML( + << +
+​body-content +
+EOT + ); + + $articleStruct->setField('title', self::SLAVE_ARTICLE_NAME); + $articleStruct->setField('body', new RichTextValue($articleBodyDoc), 'eng-GB'); + + return $articleStruct; + } + + private function fillMainArticleStruct(ContentCreateStruct $articleStruct, int $embedContentId): ContentCreateStruct + { + $mainArticleBodyDoc = new \DOMDocument(); + $mainArticleBodyDoc->loadXML( + << +
+ +
+EOT + ); + + $articleStruct->setField('title', 'test'); + $articleStruct->setField('body', new RichTextValue($mainArticleBodyDoc), 'eng-GB'); + + return $articleStruct; + } + + private function createContent(ContentCreateStruct $contentCreateStruct): Content + { + $repository = $this->getRepository(); + + return $repository->getContentService()->createContent( + $contentCreateStruct, + [$repository->getLocationService()->newLocationCreateStruct(2)] + ); + } + + private function assertResults(array $searchHits): void + { + $resultIds = []; + + /** @var SearchHit $contentItem */ + foreach ($searchHits as $contentItem) { + $resultIds[] = $contentItem->valueObject->contentInfo->id; + } + + $this->assertTrue( + count(array_intersect($resultIds, self::$createdIds)) === 2 + ); + } +} diff --git a/eZ/Publish/API/Repository/Tests/SearchServiceFulltextTestTMP.php b/eZ/Publish/API/Repository/Tests/SearchServiceFulltextTestTMP.php deleted file mode 100644 index 10fce1b13f8..00000000000 --- a/eZ/Publish/API/Repository/Tests/SearchServiceFulltextTestTMP.php +++ /dev/null @@ -1,309 +0,0 @@ -getRepository(false) - ->getSearchService()->supports(SearchService::CAPABILITY_ADVANCED_FULLTEXT) - ) { - $this->markTestSkipped('Engine says it does not support advance fulltext format'); - } - } - - /** - * Create test Content and return Content ID map for subsequent testing. - */ - public function testPrepareContent() - { - $repository = $this->getRepository(); - - $contentService = $repository->getContentService(); - $contentTypeService = $repository->getContentTypeService(); - $locationService = $repository->getLocationService(); - - $contentType = $contentTypeService->loadContentTypeByIdentifier('article'); - $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); - $contentCreateStruct->setField('title', 'testtt'); - - $bodyDocument = new \DOMDocument(); - $bodyDocument->loadXML(<< -
- -
-EOT - ); - - $introDocument = new \DOMDocument(); - $introDocument->loadXML(<< -
-paragraph -
-EOT - ); - - $contentCreateStruct->setField('body', new RichTextValue($bodyDocument), 'eng-GB'); - $contentCreateStruct->setField('intro', new RichTextValue($introDocument), 'eng-GB'); - - $idMap = []; - - $content = $contentService->publishVersion( - $contentService->createContent( - $contentCreateStruct, - [$locationService->newLocationCreateStruct(2)] - )->versionInfo - ); - - $idMap[1] = $content->id; - -// SECOND ARTICLE - - $contentType = $contentTypeService->loadContentTypeByIdentifier('article'); - $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); - $contentCreateStruct->setField('title', 'testtt111'); - - $bodyDocument = new \DOMDocument(); - $bodyDocument->loadXML(<< -
-​body-content -
-EOT - ); - - $introDocument = new \DOMDocument(); - $introDocument->loadXML(<< -
-paragraph 2 -
-EOT - ); - - $contentCreateStruct->setField('body', new RichTextValue($bodyDocument), 'eng-GB'); - $contentCreateStruct->setField('intro', new RichTextValue($introDocument), 'eng-GB'); - - $content = $contentService->publishVersion( - $contentService->createContent( - $contentCreateStruct, - [$locationService->newLocationCreateStruct(2)] - )->versionInfo - ); - - $idMap[2] = $content->id; - - - $this->refreshSearch($repository); - - return $idMap; - } - - /** - * Return pairs of arguments: - * - search string for testing - * - an array of corresponding Content keys as defined in testPrepareContent() method, - * ordered and grouped by relevancy. - * - * @see testPrepareContent - */ - public function providerForTestFulltextSearchSolr7(): array - { - return [ - [ - 'test', - [3, [6, 8, 10], [11, 13, 14], 15], - ], - ]; - } - - /** - * Test for the findContent() method on Solr >= 7. - * - * @param string $searchString - * @param array $expectedKeys - * @param array $idMap - * - * @depends testPrepareContent - * @dataProvider providerForTestFulltextSearchSolr7 - */ - public function testFulltextContentSearchSolr7(string $searchString, array $expectedKeys, array $idMap): void - { - if (($solrVersion = getenv('SOLR_VERSION')) < 7) { - $this->markTestSkipped('This test is only relevant for Solr >= 7'); - } - - $this->doTestFulltextContentSearch($searchString, $expectedKeys, $idMap); - } - - private function doTestFulltextContentSearch(string $searchString, array $expectedKeys, array $idMap): void - { - $repository = $this->getRepository(false); - $searchService = $repository->getSearchService(); - - $query = new Query(['query' => new Criterion\FullText($searchString)]); - $searchResult = $searchService->findContent($query); - - $this->assertFulltextSearch($searchResult, $expectedKeys, $idMap); - } - - /** - * Test for the findLocations() method on Solr >= 7. - * - * @param $searchString - * @param array $expectedKeys - * @param array $idMap - * - * @depends testPrepareContent - * @dataProvider providerForTestFulltextSearchSolr7 - */ - public function testFulltextLocationSearchSolr7($searchString, array $expectedKeys, array $idMap): void - { - if (($solrVersion = getenv('SOLR_VERSION')) < 7) { - $this->markTestSkipped('This test is only relevant for Solr >= 7'); - } - - $this->doTestFulltextLocationSearch($searchString, $expectedKeys, $idMap); - } - - private function doTestFulltextLocationSearch($searchString, array $expectedKeys, array $idMap): void - { - $repository = $this->getRepository(false); - $searchService = $repository->getSearchService(); - - $query = new LocationQuery(['query' => new Criterion\FullText($searchString)]); - $searchResult = $searchService->findLocations($query); - - $this->assertFulltextSearch($searchResult, $expectedKeys, $idMap); - } - - /** - * Assert given $searchResult using $expectedKeys and $idMap. - * - * @param \eZ\Publish\API\Repository\Values\Content\Search\SearchResult $searchResult - * @param array $expectedKeys - * @param array $idMap - */ - public function assertFulltextSearch(SearchResult $searchResult, array $expectedKeys, array $idMap) - { - $this->assertEquals( - array_reduce( - $expectedKeys, - function ($carry, $item) { - $carry += count((array)$item); - - return $carry; - }, - 0 - ), - $searchResult->totalCount - ); - - $expectedIds = $this->mapKeysToIds($expectedKeys, $idMap); - $actualIds = $this->mapSearchResultToIds($searchResult); - - $this->assertEquals($expectedIds, $actualIds); - } - - /** - * Map given array of $expectedKeys to Content IDs, using $idMap. - * - * @param array $expectedKeys - * @param array $idMap - * - * @return array - */ - private function mapKeysToIds(array $expectedKeys, array $idMap) - { - $expectedIds = []; - - foreach ($expectedKeys as $keyGroup) { - if (is_array($keyGroup)) { - $idGroup = []; - - /** @var array $keyGroup */ - foreach ($keyGroup as $key) { - $idGroup[] = $idMap[$key]; - } - - sort($idGroup); - $expectedIds[] = $idGroup; - - continue; - } - - $key = $keyGroup; - $expectedIds[] = $idMap[$key]; - } - - return $expectedIds; - } - - /** - * Map given $searchResult to an array of Content IDs, ordered and grouped by relevancy score. - * - * @param \eZ\Publish\API\Repository\Values\Content\Search\SearchResult $searchResult - * - * @return array - */ - private function mapSearchResultToIds(SearchResult $searchResult) - { - $scoreGroupedIds = []; - - foreach ($searchResult->searchHits as $index => $searchHit) { - if ($searchHit->valueObject instanceof Content || $searchHit->valueObject instanceof Location) { - $contentInfo = $searchHit->valueObject->contentInfo; - } elseif ($searchHit->valueObject instanceof ContentInfo) { - $contentInfo = $searchHit->valueObject; - } else { - throw new RuntimeException('Unknown search hit value'); - } - - $scoreGroupedIds[(string)$searchHit->score][] = $contentInfo->id; - } - - return array_map( - function (array $idGroup) { - if (count($idGroup) === 1) { - return reset($idGroup); - } - - sort($idGroup); - - return $idGroup; - }, - array_values($scoreGroupedIds) - ); - } -} diff --git a/phpunit-integration-legacy-solr.xml b/phpunit-integration-legacy-solr.xml index 3335138287f..63d4bf96912 100644 --- a/phpunit-integration-legacy-solr.xml +++ b/phpunit-integration-legacy-solr.xml @@ -53,6 +53,7 @@ eZ/Publish/API/Repository/Tests/ObjectStateServiceAuthorizationTest.php eZ/Publish/API/Repository/Tests/SearchServiceTest.php eZ/Publish/API/Repository/Tests/SearchServiceFulltextTest.php + eZ/Publish/API/Repository/Tests/SearchServiceFulltextEmbedTest.php eZ/Publish/API/Repository/Tests/SearchServiceTranslationLanguageFallbackTest.php eZ/Publish/API/Repository/Tests/SearchServiceLocationTest.php eZ/Publish/API/Repository/Tests/SearchServiceAuthorizationTest.php From a8f7b218088474e4dbf666e201d583e3a15feb14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Myszka?= Date: Wed, 22 Jan 2020 10:31:11 +0100 Subject: [PATCH 3/6] EZP-31226 - Indexing depth doesn't work properly in Solr when LocationQuery is in use --- .../API/Repository/Tests/SearchServiceFulltextEmbedTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eZ/Publish/API/Repository/Tests/SearchServiceFulltextEmbedTest.php b/eZ/Publish/API/Repository/Tests/SearchServiceFulltextEmbedTest.php index 9b153ac8116..fb8cc68c4ea 100644 --- a/eZ/Publish/API/Repository/Tests/SearchServiceFulltextEmbedTest.php +++ b/eZ/Publish/API/Repository/Tests/SearchServiceFulltextEmbedTest.php @@ -126,7 +126,7 @@ private function fillSlaveArticleStruct(ContentCreateStruct $articleStruct): Con <<
-​body-content +body-content
EOT ); @@ -144,7 +144,7 @@ private function fillMainArticleStruct(ContentCreateStruct $articleStruct, int $ <<
- +
EOT ); From eb5a9dd97e2276b87b9f5be3ca6a8d73fce37c64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Myszka?= Date: Wed, 22 Jan 2020 16:28:09 +0100 Subject: [PATCH 4/6] Moved SearchServcieFulltextEmbedTest to new namespace, undo edit .gitignore file, better fitted variable name for embedded article in test --- .gitignore | 1 - .../SearchServiceFulltextEmbedTest.php | 29 ++++++++++--------- phpunit-integration-legacy-solr.xml | 2 +- 3 files changed, 17 insertions(+), 15 deletions(-) rename eZ/Publish/API/Repository/Tests/{ => SearchService}/SearchServiceFulltextEmbedTest.php (84%) diff --git a/.gitignore b/.gitignore index b7ff6a9732b..45038da1c1a 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,3 @@ composer.phar var/ composer.lock .php_cs.cache -.idea diff --git a/eZ/Publish/API/Repository/Tests/SearchServiceFulltextEmbedTest.php b/eZ/Publish/API/Repository/Tests/SearchService/SearchServiceFulltextEmbedTest.php similarity index 84% rename from eZ/Publish/API/Repository/Tests/SearchServiceFulltextEmbedTest.php rename to eZ/Publish/API/Repository/Tests/SearchService/SearchServiceFulltextEmbedTest.php index fb8cc68c4ea..a4a67477e88 100644 --- a/eZ/Publish/API/Repository/Tests/SearchServiceFulltextEmbedTest.php +++ b/eZ/Publish/API/Repository/Tests/SearchService/SearchServiceFulltextEmbedTest.php @@ -1,12 +1,15 @@ getRepository(false); if (false === $repository->getSearchService()->supports(SearchService::CAPABILITY_ADVANCED_FULLTEXT)) { - $this->markTestSkipped('Engine says it does not support advance fulltext format'); + $this->markTestSkipped('Advanced FullText search is not supported by the current search engine'); } } @@ -45,12 +48,12 @@ public function testPrepareContent(): void $contentService = $this->getRepository()->getContentService(); $baseArticleStruct = $this->prepareBaseArticleStruct(); - $slaveArticleStruct = $this->fillSlaveArticleStruct(clone $baseArticleStruct); - $slaveArticleContent = $contentService->publishVersion( - $this->createContent($slaveArticleStruct)->versionInfo + $embeddedArticleStruct = $this->fillEmbeddedArticleStruct(clone $baseArticleStruct); + $embeddedArticleContent = $contentService->publishVersion( + $this->createContent($embeddedArticleStruct)->versionInfo ); - $mainArticleStruct = $this->fillMainArticleStruct(clone $baseArticleStruct, $slaveArticleContent->id); + $mainArticleStruct = $this->fillMainArticleStruct(clone $baseArticleStruct, $embeddedArticleContent->id); $mainArticleContent = $contentService->publishVersion( $this->createContent($mainArticleStruct)->versionInfo ); @@ -58,7 +61,7 @@ public function testPrepareContent(): void $this->refreshSearch($this->getRepository()); self::$createdIds = [ - $slaveArticleContent->id, + $embeddedArticleContent->id, $mainArticleContent->id, ]; } @@ -71,7 +74,7 @@ public function testFulltextContentSearch(): void $searchService = $this->getRepository()->getSearchService(); $query = new Query([ - 'query' => new Criterion\FullText(self::SLAVE_ARTICLE_NAME), + 'query' => new Criterion\FullText(self::EMBEDDED_ARTICLE_NAME), ]); $searchResult = $searchService->findContent($query); @@ -88,7 +91,7 @@ public function testFulltextLocationSearch(): void $searchService = $this->getRepository()->getSearchService(); $query = new LocationQuery([ - 'query' => new Criterion\FullText(self::SLAVE_ARTICLE_NAME), + 'query' => new Criterion\FullText(self::EMBEDDED_ARTICLE_NAME), ]); $searchResult = $searchService->findLocations($query); @@ -112,14 +115,14 @@ private function prepareBaseArticleStruct(): ContentCreateStruct $repository = $this->getRepository(); $contentType = $repository->getContentTypeService()->loadContentTypeByIdentifier('article'); - /** @var ContentCreateStruct $articleStruct */ + /** @var \eZ\Publish\Core\Repository\Values\Content\ContentCreateStruct $articleStruct */ $articleStruct = $repository->getContentService()->newContentCreateStruct($contentType, 'eng-GB'); $articleStruct->setField('intro', new RichTextValue($introDocument), 'eng-GB'); return $articleStruct; } - private function fillSlaveArticleStruct(ContentCreateStruct $articleStruct): ContentCreateStruct + private function fillEmbeddedArticleStruct(ContentCreateStruct $articleStruct): ContentCreateStruct { $articleBodyDoc = new \DOMDocument(); $articleBodyDoc->loadXML( @@ -131,7 +134,7 @@ private function fillSlaveArticleStruct(ContentCreateStruct $articleStruct): Con EOT ); - $articleStruct->setField('title', self::SLAVE_ARTICLE_NAME); + $articleStruct->setField('title', self::EMBEDDED_ARTICLE_NAME); $articleStruct->setField('body', new RichTextValue($articleBodyDoc), 'eng-GB'); return $articleStruct; diff --git a/phpunit-integration-legacy-solr.xml b/phpunit-integration-legacy-solr.xml index 63d4bf96912..b1c6a46ea0b 100644 --- a/phpunit-integration-legacy-solr.xml +++ b/phpunit-integration-legacy-solr.xml @@ -27,6 +27,7 @@ --> eZ/Publish/API/Repository/Tests/Values/User/Limitation eZ/Publish/API/Repository/Tests/FieldType/ + eZ/Publish/API/Repository/Tests/SearchService/ eZ/Publish/API/Repository/Tests/RepositoryTest.php eZ/Publish/API/Repository/Tests/SectionServiceTest.php eZ/Publish/API/Repository/Tests/LanguageServiceTest.php @@ -53,7 +54,6 @@ eZ/Publish/API/Repository/Tests/ObjectStateServiceAuthorizationTest.php eZ/Publish/API/Repository/Tests/SearchServiceTest.php eZ/Publish/API/Repository/Tests/SearchServiceFulltextTest.php - eZ/Publish/API/Repository/Tests/SearchServiceFulltextEmbedTest.php eZ/Publish/API/Repository/Tests/SearchServiceTranslationLanguageFallbackTest.php eZ/Publish/API/Repository/Tests/SearchServiceLocationTest.php eZ/Publish/API/Repository/Tests/SearchServiceAuthorizationTest.php From 32ec53127e93bfbbbaf2837f73d2f37554ee189d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Myszka?= Date: Wed, 29 Jan 2020 11:54:59 +0100 Subject: [PATCH 5/6] After CR small changes --- .../SearchService/SearchServiceFulltextEmbedTest.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/eZ/Publish/API/Repository/Tests/SearchService/SearchServiceFulltextEmbedTest.php b/eZ/Publish/API/Repository/Tests/SearchService/SearchServiceFulltextEmbedTest.php index a4a67477e88..aa65279fe29 100644 --- a/eZ/Publish/API/Repository/Tests/SearchService/SearchServiceFulltextEmbedTest.php +++ b/eZ/Publish/API/Repository/Tests/SearchService/SearchServiceFulltextEmbedTest.php @@ -1,11 +1,11 @@ getRepository(false); - if (false === $repository->getSearchService()->supports(SearchService::CAPABILITY_ADVANCED_FULLTEXT)) { + if ( + false === $repository->getSearchService()->supports( + SearchService::CAPABILITY_ADVANCED_FULLTEXT + ) + ) { $this->markTestSkipped('Advanced FullText search is not supported by the current search engine'); } } From f80b953a4294825aacb6cf881b3d62034a65a73b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Myszka?= Date: Wed, 29 Jan 2020 16:24:28 +0100 Subject: [PATCH 6/6] Removed "preparing test", removed tests depends, small changes after CR --- ...php => SearchServiceFullTextEmbedTest.php} | 100 ++++++++++-------- 1 file changed, 54 insertions(+), 46 deletions(-) rename eZ/Publish/API/Repository/Tests/SearchService/{SearchServiceFulltextEmbedTest.php => SearchServiceFullTextEmbedTest.php} (81%) diff --git a/eZ/Publish/API/Repository/Tests/SearchService/SearchServiceFulltextEmbedTest.php b/eZ/Publish/API/Repository/Tests/SearchService/SearchServiceFullTextEmbedTest.php similarity index 81% rename from eZ/Publish/API/Repository/Tests/SearchService/SearchServiceFulltextEmbedTest.php rename to eZ/Publish/API/Repository/Tests/SearchService/SearchServiceFullTextEmbedTest.php index aa65279fe29..ff223a05049 100644 --- a/eZ/Publish/API/Repository/Tests/SearchService/SearchServiceFulltextEmbedTest.php +++ b/eZ/Publish/API/Repository/Tests/SearchService/SearchServiceFullTextEmbedTest.php @@ -10,13 +10,12 @@ use eZ\Publish\API\Repository\SearchService; use eZ\Publish\API\Repository\Tests\BaseTest; +use eZ\Publish\API\Repository\Values\Content\Content; +use eZ\Publish\API\Repository\Values\Content\ContentCreateStruct; use eZ\Publish\API\Repository\Values\Content\LocationQuery; use eZ\Publish\API\Repository\Values\Content\Query; use eZ\Publish\API\Repository\Values\Content\Query\Criterion; -use eZ\Publish\API\Repository\Values\Content\Search\SearchHit; use eZ\Publish\Core\FieldType\RichText\Value as RichTextValue; -use eZ\Publish\Core\Repository\Values\Content\Content; -use eZ\Publish\Core\Repository\Values\Content\ContentCreateStruct; /** * Test case for full text search in the SearchService (for embed). @@ -26,13 +25,13 @@ * @group search * @group fulltext */ -class SearchServiceFulltextEmbedTest extends BaseTest +class SearchServiceFullTextEmbedTest extends BaseTest { private const EMBEDDED_ARTICLE_NAME = 'test1'; private static $createdIds = []; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -40,41 +39,19 @@ protected function setUp() if ( false === $repository->getSearchService()->supports( - SearchService::CAPABILITY_ADVANCED_FULLTEXT + SearchService::CAPABILITY_ADVANCED_FULLTEXT ) ) { - $this->markTestSkipped('Advanced FullText search is not supported by the current search engine'); + $this->markTestSkipped( + 'Advanced FullText search is not supported by the current search engine' + ); } } - public function testPrepareContent(): void + public function testFullTextContentSearch(): void { - $contentService = $this->getRepository()->getContentService(); - $baseArticleStruct = $this->prepareBaseArticleStruct(); - - $embeddedArticleStruct = $this->fillEmbeddedArticleStruct(clone $baseArticleStruct); - $embeddedArticleContent = $contentService->publishVersion( - $this->createContent($embeddedArticleStruct)->versionInfo - ); - - $mainArticleStruct = $this->fillMainArticleStruct(clone $baseArticleStruct, $embeddedArticleContent->id); - $mainArticleContent = $contentService->publishVersion( - $this->createContent($mainArticleStruct)->versionInfo - ); - - $this->refreshSearch($this->getRepository()); - - self::$createdIds = [ - $embeddedArticleContent->id, - $mainArticleContent->id, - ]; - } + $this->prepareTestContent(); - /** - * @depends testPrepareContent - */ - public function testFulltextContentSearch(): void - { $searchService = $this->getRepository()->getSearchService(); $query = new Query([ @@ -87,11 +64,10 @@ public function testFulltextContentSearch(): void $this->assertResults($searchResult->searchHits); } - /** - * @depends testPrepareContent - */ - public function testFulltextLocationSearch(): void + public function testFullTextLocationSearch(): void { + $this->prepareTestContent(); + $searchService = $this->getRepository()->getSearchService(); $query = new LocationQuery([ @@ -104,6 +80,38 @@ public function testFulltextLocationSearch(): void $this->assertResults($searchResult->searchHits); } + private function hasTestPreparedContent(): bool + { + return !empty(self::$createdIds); + } + + private function prepareTestContent(): void + { + if ($this->hasTestPreparedContent()) { + return; + } + + $contentService = $this->getRepository()->getContentService(); + $baseArticleStruct = $this->prepareBaseArticleStruct(); + + $embeddedArticleStruct = $this->fillEmbeddedArticleStruct(clone $baseArticleStruct); + $embeddedArticleContent = $contentService->publishVersion( + $this->createContent($embeddedArticleStruct)->versionInfo + ); + + $mainArticleStruct = $this->fillMainArticleStruct(clone $baseArticleStruct, $embeddedArticleContent->id); + $mainArticleContent = $contentService->publishVersion( + $this->createContent($mainArticleStruct)->versionInfo + ); + + $this->refreshSearch($this->getRepository()); + + self::$createdIds = [ + $embeddedArticleContent->id, + $mainArticleContent->id, + ]; + } + private function prepareBaseArticleStruct(): ContentCreateStruct { $introDocument = new \DOMDocument(); @@ -119,15 +127,15 @@ private function prepareBaseArticleStruct(): ContentCreateStruct $repository = $this->getRepository(); $contentType = $repository->getContentTypeService()->loadContentTypeByIdentifier('article'); - /** @var \eZ\Publish\Core\Repository\Values\Content\ContentCreateStruct $articleStruct */ $articleStruct = $repository->getContentService()->newContentCreateStruct($contentType, 'eng-GB'); $articleStruct->setField('intro', new RichTextValue($introDocument), 'eng-GB'); return $articleStruct; } - private function fillEmbeddedArticleStruct(ContentCreateStruct $articleStruct): ContentCreateStruct - { + private function fillEmbeddedArticleStruct( + ContentCreateStruct $articleStruct + ): ContentCreateStruct { $articleBodyDoc = new \DOMDocument(); $articleBodyDoc->loadXML( <<loadXML( <<valueObject->contentInfo->id; } - $this->assertTrue( - count(array_intersect($resultIds, self::$createdIds)) === 2 - ); + self::assertCount(2, array_intersect($resultIds, self::$createdIds)); } }