]> _ Git - psq.git/commitdiff
max length instead of num paragraphs
authorLouis Jeckel <louis.jeckel@outlook.cm>
Fri, 11 Sep 2020 11:29:59 +0000 (13:29 +0200)
committerLouis Jeckel <louis.jeckel@outlook.cm>
Fri, 11 Sep 2020 11:29:59 +0000 (13:29 +0200)
app/PdfFile.php
config/scout.php

index 8b97a8a73d7e03a4a59be9a83c98fb45f267025e..2ed6489327ee1872b4eb43f120466409759de2b1 100644 (file)
@@ -463,7 +463,6 @@ class PdfFile extends TwillModel implements Sortable
             $page_i++;
 
             $buffer = "";
-            $count = 0;
 
             foreach ($page->find('p') as $paragraph){
 
@@ -473,27 +472,26 @@ class PdfFile extends TwillModel implements Sortable
 
                 $text = preg_replace('/^([A-Z]) /', '$1', $text);
 
-                $buffer .= ' ' . Str::lower(trim($text));
+                $newBuffer = $buffer . ' ' . Str::lower(trim($text));
 
-                if($count === 10) {
+                if(Str::length($newBuffer) > config('scout.text_max_length')) {
                     $result[] = [
                         'content' => $buffer,
                         'page' => $page_i,
                     ];
-                    $count = 0;
-                } else {
-                    $count++;
                 }
 
-            }
+                $buffer = $newBuffer;
 
-            if($count > 0) {
-                $result[] = [
-                    'content' => $buffer,
-                    'page' => $page_i,
-                ];
             }
 
+
+            $result[] = [
+                'content' => $buffer,
+                'page' => $page_i,
+            ];
+
+
         }
 
         $this->searchableTexts()->createMany($result);
index a5a65d505ed41d915925da9fcb830d210af5cb77..70c1ebff763695d4ecccc5eb8d04aa353bd62724 100644 (file)
@@ -59,6 +59,8 @@ return [
         'unsearchable' => 500,
     ],
 
+    'text_max_length' => env('SEARCHABLE_TEXT_MAX_LENGTH', 9000),
+
     /*
     |--------------------------------------------------------------------------
     | Soft Deletes