]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6188 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 12 Sep 2023 11:32:40 +0000 (13:32 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 12 Sep 2023 11:32:40 +0000 (13:32 +0200)
app/Fluidbook/Compiler/Compiler.php
app/Fluidbook/Compiler/Search.php [new file with mode: 0644]

index 95f2736bc492e5e1fb4367aadb19c58b7e5007fc..cc2b13bbf9ce7024c1706c0067298b2a04fe8757 100644 (file)
@@ -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 (file)
index 0000000..a10a8bb
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+
+namespace App\Fluidbook\Compiler;
+
+use App\Fluidbook\SearchIndex;
+use Cubist\PDF\CommandLine\FWSTK;
+use Cubist\Util\Files\Files;
+
+trait Search
+{
+    public function writeSearch()
+    {
+        $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->search_mode==='robust' || $this->fluidbookSettings->searchWordSelectionAlgorithm == 'expression') {
+            $this->vdir->copy($cacheDir . '/search.texts.js', 'data/search.texts.js');
+        }
+    }
+}