visuddhinanda пре 4 месеци
родитељ
комит
0f6251f3c0
1 измењених фајлова са 15 додато и 9 уклоњено
  1. 15 9
      api-v8/app/Console/Commands/IndexPaliText.php

+ 15 - 9
api-v8/app/Console/Commands/IndexPaliText.php

@@ -16,7 +16,12 @@ class IndexPaliText extends Command
      * php artisan opensearch:index-pali 93 --para=6
      * php artisan opensearch:index-pali 93 --para=6
      * @var string
      * @var string
      */
      */
-    protected $signature = 'opensearch:index-pali {book : The book ID to index data for} {--test} {--para= : index paragraph No. omit to all} {--summary=on} {--granularity= : The granularity to index (paragraph, sutta, sentence; omit to index all)}';
+    protected $signature = 'opensearch:index-pali {book : The book ID to index data for}
+    {--test}
+    {--para= : index paragraph No. omit to all}
+    {--summary=on}
+    {--resume}
+    {--granularity= : The granularity to index (paragraph, sutta, sentence; omit to index all)}';
 
 
     /**
     /**
      * The console command description.
      * The console command description.
@@ -29,7 +34,7 @@ class IndexPaliText extends Command
     protected $openSearchService;
     protected $openSearchService;
     protected $summaryService;
     protected $summaryService;
     private $isTest = false;
     private $isTest = false;
-    private $summary = 'on';
+    private $summary = false;
 
 
     /**
     /**
      * Create a new command instance.
      * Create a new command instance.
@@ -54,10 +59,10 @@ class IndexPaliText extends Command
      */
      */
     public function handle()
     public function handle()
     {
     {
-        $book = $this->argument('book');
+        $book = (int)$this->argument('book');
         $granularity = $this->option('granularity');
         $granularity = $this->option('granularity');
         $paragraph = $this->option('para');
         $paragraph = $this->option('para');
-        $this->summary = $this->option('summary');
+        $this->summary = $this->option('summary') === 'on';
 
 
         if ($this->option('test')) {
         if ($this->option('test')) {
             $this->isTest = true;
             $this->isTest = true;
@@ -74,10 +79,11 @@ class IndexPaliText extends Command
                 return 1;
                 return 1;
             }
             }
             $overallStatus = 0; // Track overall command status (0 for success, 1 for any failure)
             $overallStatus = 0; // Track overall command status (0 for success, 1 for any failure)
-
-            if ((int)$book === 0) {
-                $maxBookId = PaliText::max('book');
+            $maxBookId = PaliText::max('book');
+            if ($book === 0) {
                 $booksId = range(1, $maxBookId);
                 $booksId = range(1, $maxBookId);
+            } else if ($this->option('resume')) {
+                $booksId = range($book, $maxBookId);
             } else {
             } else {
                 $booksId = [$book];
                 $booksId = [$book];
             }
             }
@@ -114,7 +120,7 @@ class IndexPaliText extends Command
                 'pali' => $title,
                 'pali' => $title,
             ],
             ],
             'summary' => [
             'summary' => [
-                'text' => $this->summary === 'on' ? $this->summaryService->summarize($paraContent['markdown']) : ''
+                'text' => $this->summary  ? $this->summaryService->summarize($paraContent['markdown']) : ''
             ],
             ],
             'content' => [
             'content' => [
                 'pali' => $paraContent['markdown'],
                 'pali' => $paraContent['markdown'],
@@ -241,7 +247,7 @@ class IndexPaliText extends Command
             }
             }
             $this->indexPaliParagraph($para->toArray(), $paraContent, $commentaryId);
             $this->indexPaliParagraph($para->toArray(), $paraContent, $commentaryId);
             $this->info("{$para['book']}-[{$para['paragraph']}]-[{$commentaryId}]");
             $this->info("{$para['book']}-[{$para['paragraph']}]-[{$commentaryId}]");
-            usleep(100);
+            usleep(10000);
         }
         }
 
 
         $this->info("Successfully indexed $total paragraphs for book: $book");
         $this->info("Successfully indexed $total paragraphs for book: $book");