Skip to content

Commit

Permalink
Merge pull request TYPO3-Documentation#41 from TYPO3-Documentation/mi…
Browse files Browse the repository at this point in the history
…grate_to_main

Migrate search indexer from "master" branch name to "main"
  • Loading branch information
linawolf authored Jun 21, 2023
2 parents 4739596 + e645def commit 89aa83b
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 86 deletions.
26 changes: 16 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,32 @@ TYPO3 Documentation Search
Install locally
---------------

* create ``docs_server`` folder (on the same level where cloned repository is)
and put rendered documentation inside. This folder will be mounted inside DDEV under ``/var/www/docs_server``.

* install DDEV
* Clone this repo ``git clone https://github.com/TYPO3-Documentation/t3docs-search-indexer.git``

* Run ``ddev start``
* Enter the `t3docs-search-indexer`` folder and run ``ddev start``

* Run ``ddev exec composer install`` to install all dependencies.

* Run ``ddev exec composer global require t3g/elasticorn:7.0`` to install Elasticorn
* Run ``ddev exec composer global require t3g/elasticorn:^7.0`` to install Elasticorn

* Create elasticsearch index via Elasticorn:

``ddev exec ~/.composer/vendor/bin/elasticorn.php index:init -c config/Elasticorn``

* Adapt ``DOCS_ROOT_PATH`` in your ``.env`` file if needed (see .env.dist for examples).
DDEV environment has ``DOCS_ROOT_PATH=../docs_server/docs.typo3.org/Web`` set up by default.
* If necessary adapt ``DOCS_ROOT_PATH`` in your ``.env`` file if needed (see .env.dist for examples).
DDEV environment has ``DOCS_ROOT_PATH=../docs_server/docs.typo3.org/Web`` set up by default, so usually
you don't need to change it if you followed the folder structure.

* Create ``docs_server`` folder (on the same level where ``t3docs-search-indexer`` folder is)
and put rendered documentation inside. This folder will be mounted inside DDEV under ``/var/www/docs_server``.
You should have a structure like ``docs_server/docs.typo3.org/Web``

* Index documents as described below in "Usage" section

* Enjoy the local search under ``https://t3docs-search-indexer.ddev.site/``

Configuration
-------
-------------

Configure assets
^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -58,7 +64,7 @@ Index docs
root path (DOCS_ROOT_PATH) folder (taking into account configured ``allowed_paths``
and ``excluded_directories``).

* Open `https://t3docs-search-indexer.ddev.site:9201/docsearch_english_a/_search?q=*:*` to see indexed
* Open `https://t3docs-search-indexer.ddev.site:9201/docsearch/_search?q=*:*` to see indexed
documents.

* enter `https://t3docs-search-indexer.ddev.site` to see application
Expand Down
2 changes: 1 addition & 1 deletion src/Dto/Manual.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function getSubManuals(): array
if ($this->getTitle() !== 'typo3/cms-core') {
return [];
}
if ($this->getVersion() !== 'master') {
if ($this->getVersion() !== 'main') {
return [];
}
$finder = new Finder();
Expand Down
3 changes: 2 additions & 1 deletion src/Dto/SearchDemand.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ public static function createFromRequest(Request $request): SearchDemand
}
}
$page = (int)$request->query->get('page', '1');
$query = $request->query->get('q', '');
return new self(
$request->query->get('q', ''),
$query,
max($page, 1),
$filters,
);
Expand Down
4 changes: 2 additions & 2 deletions src/Helper/VersionSorter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class VersionSorter
public static function sortVersions(array $versions, string $direction='asc'):array
{
usort($versions, function ($a, $b) {
if ($a === 'master') {
if ($a === 'main') {
return 1;
}
if ($b === 'master') {
if ($b === 'main') {
return -1;
}
return version_compare($a, $b);
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/ElasticRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public function findByQuery(SearchDemand $searchDemand): array
[
'filter' => [
// query matching recent version
'terms' => ['manual_version' => ['master', '11.5', '10.5', '9.4']]
'terms' => ['manual_version' => ['main', '12.4', '11.5', '10.5']]
],
'weight' => 5
],
Expand Down
2 changes: 1 addition & 1 deletion templates/layout/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<script type="text/javascript">
let DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: 'master',
VERSION: 'main',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
Expand Down
16 changes: 4 additions & 12 deletions tests/Unit/Controller/SearchControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,10 @@ public function searchActionAssignsQueryToTemplate()
$subject = new SearchController();
$this->setProperty($subject, 'container', $this->container->reveal());

$query = $this->prophesize(ParameterBag::class);
$query->get('q')->willReturn('searchTerm');
$query->get('page', 1)->willReturn(1);
$query->get('filters')->willReturn(null);
$query = new ParameterBag(['q' => 'searchTerm', 'page' => '1']);

$request = $this->prophesize(Request::class);
$request->query = $query->reveal();

$request->query = $query;

$this->view->render(Argument::any(), Argument::that(function (array $variables) {
return isset($variables['q'])
Expand Down Expand Up @@ -114,14 +110,10 @@ public function searchActionRendersSearchTemplate()
$subject = new SearchController();
$this->setProperty($subject, 'container', $this->container->reveal());

$query = $this->prophesize(ParameterBag::class);
$query->get('q')->willReturn('searchTerm');
$query->get('page', 1)->willReturn(1);
$query->get('filters')->willReturn(null);

$query = new ParameterBag(['q' => 'searchTerm', 'page' => '1']);

$request = $this->prophesize(Request::class);
$request->query = $query->reveal();
$request->query = $query;

$this->view->render('search/search.html.twig', Argument::any())->shouldBeCalledTimes(1);

Expand Down
38 changes: 33 additions & 5 deletions tests/Unit/Dto/ManualTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Dto\Manual;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Finder\SplFileInfo;

class ManualTest extends TestCase
{
Expand All @@ -13,16 +14,43 @@ class ManualTest extends TestCase
public function createFromFolder()
{
$folder = $this->prophesize(\SplFileInfo::class);
$folder->getPathname()->willReturn('_docsFolder/c/typo3/cms-core/master/en-us');
$folder->__toString()->willReturn('_docsFolder/c/typo3/cms-core/master/en-us');
$folder->getPathname()->willReturn('_docsFolder/c/typo3/cms-core/main/en-us');
$folder->__toString()->willReturn('_docsFolder/c/typo3/cms-core/main/en-us');
$returnedManual = Manual::createFromFolder($folder->reveal());

self::assertInstanceOf(Manual::class, $returnedManual);
self::assertSame('_docsFolder/c/typo3/cms-core/master/en-us', $returnedManual->getAbsolutePath());
self::assertSame('_docsFolder/c/typo3/cms-core/main/en-us', $returnedManual->getAbsolutePath());
self::assertSame('typo3/cms-core', $returnedManual->getTitle());
self::assertSame('System extension', $returnedManual->getType());
self::assertSame('en-us', $returnedManual->getLanguage());
self::assertSame('c/typo3/cms-core/master/en-us', $returnedManual->getSlug());
self::assertSame('master', $returnedManual->getVersion());
self::assertSame('c/typo3/cms-core/main/en-us', $returnedManual->getSlug());
self::assertSame('main', $returnedManual->getVersion());
}

/**
* @test
*/
public function returnsFilesWithSectionsForManual()
{
$filesRoot = implode(DIRECTORY_SEPARATOR, [
__DIR__,
'Fixtures',
'ParseDocumentationHTMLServiceTest',
'ReturnsFilesWithSectionsForManual',
'manual',
]);

$manual = new Manual($filesRoot, 'title', 'type', 'main', 'en_us', 'slug');
$files = $manual->getFilesWithSections();
self::assertCount(3, $files);
$expectedFiles = [
$filesRoot . '/index.html',
$filesRoot . '/another.html',
$filesRoot . '/additional/index.html',
];
foreach ($files as $file) {
/* @var $file SplFileInfo */
self::assertTrue(in_array((string)$file, $expectedFiles), 'Unexpected file: ' . $file);
}
}
}
8 changes: 4 additions & 4 deletions tests/Unit/Helper/VersionSorterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ public function sortVersionsDataProvider()
['11.0', '10', '9.3.2', '8.7']
],
[
['10', '8.7', 'master', '11.0', '9.3.2'],
['10', '8.7', 'main', '11.0', '9.3.2'],
'asc',
['8.7', '9.3.2', '10', '11.0', 'master']
['8.7', '9.3.2', '10', '11.0', 'main']
],
[
['10', '8.7', 'master', '11.0', '9.3.2'],
['10', '8.7', 'main', '11.0', '9.3.2'],
'desc',
['master', '11.0', '10', '9.3.2', '8.7']
['main', '11.0', '10', '9.3.2', '8.7']
]
];
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/Service/DirectoryFinderServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public function returnsManualsFromFolder()
'c' => [
'typo3' => [
'cms-core' => [
'master' => [
'main' => [
'en-us' => [
'objects.inv.json' => ''
],
],
],
'cms-form' => [
'master' => [
'main' => [
'en-us' => [
'objects.inv.json' => ''
],
Expand All @@ -44,7 +44,7 @@ public function returnsManualsFromFolder()
'objects.inv.json' => ''
],
],
'master' => [
'main' => [
'en-us' => [
'objects.inv.json' => ''
],
Expand All @@ -56,7 +56,7 @@ public function returnsManualsFromFolder()
'objects.inv.json' => ''
],
],
'master' => [
'main' => [
'en-us' => [
'objects.inv.json' => ''
],
Expand Down
27 changes: 14 additions & 13 deletions tests/Unit/Service/ImportManualHTMLServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use App\Service\ImportManualHTMLService;
use App\Service\ParseDocumentationHTMLService;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
Expand Down Expand Up @@ -43,7 +42,7 @@ public function allowsImportOfManual()
$manual = $this->prophesize(Manual::class);
$manual->getTitle()->willReturn('typo3/cms-core');
$manual->getType()->willReturn('c');
$manual->getVersion()->willReturn('master');
$manual->getVersion()->willReturn('main');
$manual->getLanguage()->willReturn('en-us');
$manual->getSlug()->willReturn('slug');
$manual->getFilesWithSections()->willReturn($finder->reveal());
Expand All @@ -53,7 +52,7 @@ public function allowsImportOfManual()
$parser = $this->prophesize(ParseDocumentationHTMLService::class);

$file = $this->prophesize(SplFileInfo::class);
$file->getRelativePathname()->willReturn('c/typo3/cms-core/master/en-us');
$file->getRelativePathname()->willReturn('c/typo3/cms-core/main/en-us');
$fileRevealed = $file->reveal();

$section1 = [
Expand All @@ -74,26 +73,28 @@ public function allowsImportOfManual()
$subject = new ImportManualHTMLService($repo->reveal(), $parser->reveal(), $this->prophesize(EventDispatcherInterface::class)->reveal());

$repo->addOrUpdateDocument([
'fragment' => 'features-and-basic-concept',
'snippet_title' => 'Features and Basic Concept',
'snippet_content' => 'The main goal for this blog extension was to use TYPO3s core concepts and elements to provide a full-blown blog that users of TYPO3 can instantly understand and use.',
'manual_title' => 'typo3/cms-core',
'manual_type' => 'c',
'manual_version' => 'master',
'manual_version' => 'main',
'manual_language' => 'en-us',
'manual_slug' => 'slug',
'relative_url' => 'c/typo3/cms-core/master/en-us',
'fragment' => 'features-and-basic-concept',
'snippet_title' => 'Features and Basic Concept',
'snippet_content' => 'The main goal for this blog extension was to use TYPO3s core concepts and elements to provide a full-blown blog that users of TYPO3 can instantly understand and use.'
'relative_url' => 'c/typo3/cms-core/main/en-us',
"content_hash" => "718ab540920b06f925f6ef7a34d6a5c7",
])->shouldBeCalledTimes(1);
$repo->addOrUpdateDocument([
'fragment' => 'pages-as-blog-entries',
'snippet_title' => 'Pages as blog entries',
'snippet_content' => 'Blog entries are simply pages with a special page type blog entry and can be created and edited via the well-known page module. Creating new entries is as simple as dragging a new entry into the page tree.',
'manual_title' => 'typo3/cms-core',
'manual_type' => 'c',
'manual_version' => 'master',
'manual_version' => 'main',
'manual_language' => 'en-us',
'manual_slug' => 'slug',
'relative_url' => 'c/typo3/cms-core/master/en-us',
'fragment' => 'pages-as-blog-entries',
'snippet_title' => 'Pages as blog entries',
'snippet_content' => 'Blog entries are simply pages with a special page type blog entry and can be created and edited via the well-known page module. Creating new entries is as simple as dragging a new entry into the page tree.'
'relative_url' => 'c/typo3/cms-core/main/en-us',
"content_hash" => "a248b5d0798e30e7c9389b81b499c5d9",
])->shouldBeCalledTimes(1);

$subject->importManual($manualRevealed);
Expand Down
32 changes: 0 additions & 32 deletions tests/Unit/Service/ParseDocumentationHTMLServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,12 @@

namespace App\Tests\Unit\Service;

use App\Dto\Manual;
use App\Service\ParseDocumentationHTMLService;
use org\bovigo\vfs\vfsStream;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Finder\SplFileInfo;

class ParseDocumentationHTMLServiceTest extends TestCase
{
/**
* @test
*/
public function returnsFilesWithSectionsForManual()
{
$filesRoot = implode(DIRECTORY_SEPARATOR, [
__DIR__,
'Fixtures',
'ParseDocumentationHTMLServiceTest',
'ReturnsFilesWithSectionsForManual',
'manual',
]);
$manual = $this->prophesize(Manual::class);
$manual->getAbsolutePath()->willReturn($filesRoot);

$subject = new ParseDocumentationHTMLService();
$files = $subject->getFilesWithSections($manual->reveal());

self::assertCount(3, $files);
$expectedFiles = [
$filesRoot . '/index.html',
$filesRoot . '/another.html',
$filesRoot . '/additional/index.html',
];
foreach ($files as $file) {
/* @var $file SplFileInfo */
self::assertTrue(in_array((string)$file, $expectedFiles), 'Unexpected file: ' . $file);
}
}

/**
* @test
* @dataProvider documentationDataProvider
Expand Down

0 comments on commit 89aa83b

Please sign in to comment.