From: Vincent Vanwaelscappel Date: Tue, 12 Sep 2023 11:32:40 +0000 (+0200) Subject: wip #6188 @2 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=78d498257d43551987e901cc25c5efb24420ceb2;p=fluidbook-toolbox.git wip #6188 @2 --- diff --git a/app/Fluidbook/Compiler/Compiler.php b/app/Fluidbook/Compiler/Compiler.php index 95f2736bc..cc2b13bbf 100644 --- a/app/Fluidbook/Compiler/Compiler.php +++ b/app/Fluidbook/Compiler/Compiler.php @@ -53,6 +53,7 @@ class Compiler extends Base implements CompilerInterface use Sound; use Articles; use Cache; + use Search; protected static $uaPrefixes = array('-moz-', '-webkit-', '-o-', '-ms-', ''); @@ -721,8 +722,8 @@ class Compiler extends Base implements CompilerInterface $this->log('SEO written'); $this->writeSounds(); $this->log('Sound written'); - $this->writeTexts(); - $this->log('Texts written'); + $this->writeSearch(); + $this->log('Search written'); $this->writeAccessibility(); $this->log('Accessibility written'); $this->writeExtras(); @@ -1690,30 +1691,6 @@ class Compiler extends Base implements CompilerInterface return Files::mkdir(protected_path('fluidbookpublication/cache/' . $path)); } - public function writeTexts() - { - $cache = sha1($this->fluidbookSettings->highlightResults . '/--/' . $this->fluidbookSettings->searchWordSelectionAlgorithm . '///' . $this->fluidbookSettings->textExtraction . '|--|' . $this->fluidbookSettings->ignoreSearchSeparators . '|||' . $this->getFluidbook()->getCompositionUpdate() . '()()()' . FWSTK::lastUpdate()); - $cacheDir = Files::mkdir(protected_path('fluidbookpublication/index/' . $this->book_id . '/' . $cache . '/')); - $indexFile = $cacheDir . '/search.index.js'; - $textFile = $cacheDir . '/search.texts.js'; - $hightlightsFile = $cacheDir . '/search.highlight.js'; - - if (!file_exists($indexFile) || !file_exists($textFile)) { - SearchIndex::makeTextsIndexes($this, $cacheDir, $index, $texts, true); - file_put_contents($indexFile, 'var INDEX=' . $index . ';' . "\r"); - file_put_contents($textFile, 'var TEXTS=' . $texts . ";\r"); - } - if ($this->fluidbookSettings->highlightResults && !file_exists($hightlightsFile)) { - file_put_contents($hightlightsFile, 'var HIGHLIGHTS=' . json_encode(SearchIndex::makeHighlightIndex($this)) . ";\r"); - } - $this->vdir->copy($cacheDir . '/search.index.js', 'data/search.index.js'); - if ($this->fluidbookSettings->highlightResults) { - $this->vdir->copy($cacheDir . '/search.highlight.js', 'data/search.highlight.js'); - } - if ($this->fluidbookSettings->searchWordSelectionAlgorithm == 'expression') { - $this->vdir->copy($cacheDir . '/search.texts.js', 'data/search.texts.js'); - } - } protected function _SVGCleanAsset($a) { diff --git a/app/Fluidbook/Compiler/Search.php b/app/Fluidbook/Compiler/Search.php new file mode 100644 index 000000000..a10a8bb96 --- /dev/null +++ b/app/Fluidbook/Compiler/Search.php @@ -0,0 +1,35 @@ +fluidbookSettings->highlightResults . '/--/' . $this->fluidbookSettings->searchWordSelectionAlgorithm . '///' . $this->fluidbookSettings->textExtraction . '|--|' . $this->fluidbookSettings->ignoreSearchSeparators . '|||' . $this->getFluidbook()->getCompositionUpdate() . '()()()' . FWSTK::lastUpdate()); + $cacheDir = Files::mkdir(protected_path('fluidbookpublication/index/' . $this->book_id . '/' . $cache . '/')); + $indexFile = $cacheDir . '/search.index.js'; + $textFile = $cacheDir . '/search.texts.js'; + $hightlightsFile = $cacheDir . '/search.highlight.js'; + + if (!file_exists($indexFile) || !file_exists($textFile)) { + SearchIndex::makeTextsIndexes($this, $cacheDir, $index, $texts, true); + file_put_contents($indexFile, 'var INDEX=' . $index . ';' . "\r"); + file_put_contents($textFile, 'var TEXTS=' . $texts . ";\r"); + } + if ($this->fluidbookSettings->highlightResults && !file_exists($hightlightsFile)) { + file_put_contents($hightlightsFile, 'var HIGHLIGHTS=' . json_encode(SearchIndex::makeHighlightIndex($this)) . ";\r"); + } + $this->vdir->copy($cacheDir . '/search.index.js', 'data/search.index.js'); + if ($this->fluidbookSettings->highlightResults) { + $this->vdir->copy($cacheDir . '/search.highlight.js', 'data/search.highlight.js'); + } + if ($this->fluidbookSettings->search_mode==='robust' || $this->fluidbookSettings->searchWordSelectionAlgorithm == 'expression') { + $this->vdir->copy($cacheDir . '/search.texts.js', 'data/search.texts.js'); + } + } +}