فهرست منبع

黑体字检索移入getParaContent

visuddhinanda 6 ماه پیش
والد
کامیت
73eb6ec388
1فایلهای تغییر یافته به همراه64 افزوده شده و 46 حذف شده
  1. 64 46
      api-v8/app/Services/SearchPaliDataService.php

+ 64 - 46
api-v8/app/Services/SearchPaliDataService.php

@@ -27,42 +27,9 @@ class SearchPaliDataService
 
         for ($iPara = $start; $iPara < $endOfPara; $iPara++) {
             $content = $this->getParaContent($book, $iPara);
-            // Retrieve bold words
-            $words = WbwTemplate::where('book', $book)
-                ->where('paragraph', $iPara)
-                ->orderBy('wid')
-                ->get();
-
-            $bold1 = [];
-            $bold2 = [];
-            $bold3 = [];
-            $currBold = [];
-
-            foreach ($words as $word) {
-                if ($word->style === 'bld') {
-                    $currBold[] = $word->real;
-                } else {
-                    $countBold = count($currBold);
-                    if ($countBold === 1) {
-                        $bold1[] = $currBold[0];
-                    } elseif ($countBold === 2) {
-                        $bold2 = array_merge($bold2, $currBold);
-                    } elseif ($countBold > 0) {
-                        $bold3 = array_merge($bold3, $currBold);
-                    }
-                    $currBold = [];
-                }
-            }
 
-            // Handle any remaining bold words
-            $countBold = count($currBold);
-            if ($countBold === 1) {
-                $bold1[] = $currBold[0];
-            } elseif ($countBold === 2) {
-                $bold2 = array_merge($bold2, $currBold);
-            } elseif ($countBold > 0) {
-                $bold3 = array_merge($bold3, $currBold);
-            }
+
+
 
             // Retrieve book ID
             $pcd_book = BookTitle::where('book', $book)
@@ -78,9 +45,9 @@ class SearchPaliDataService
                 'uid' => PaliText::where('book', $book)->where('paragraph', $iPara)->value('uid'),
                 'book' => $book,
                 'paragraph' => $iPara,
-                'bold1' => implode(' ', $bold1),
-                'bold2' => implode(' ', $bold2),
-                'bold3' => implode(' ', $bold3),
+                'bold1' => implode(' ', $content['bold1']),
+                'bold2' => implode(' ', $content['bold2']),
+                'bold3' => implode(' ', $content['bold3']),
                 'content' => $content['markdown'],
                 'markdown' => $content['markdown'],
                 'text' => $content['text'],
@@ -142,16 +109,61 @@ class SearchPaliDataService
         }
         $markdown = [];
         $text = [];
+        $wordList = [];
         foreach ($sentences as $key => $sentence) {
             $content = $this->getSentenceText($book, $para, $sentence->word_begin, $sentence->word_end);
             $id = "{$book}-{$para}-{$sentence->word_begin}-{$sentence->word_end}";
             $markdown[] = $content['markdown'];
             $text[] = $content['text'];
+            $wordList = array_merge($wordList, $content['words']);
         }
-        return [
+
+        // Retrieve bold words
+        $words = WbwTemplate::where('book', $book)
+            ->where('paragraph', $para)
+            ->orderBy('wid')
+            ->get();
+
+        $bold1 = [];
+        $bold2 = [];
+        $bold3 = [];
+        $currBold = [];
+
+        foreach ($words as $word) {
+            if ($word->type === '.ctl.') {
+                //检测义注段落号
+                if (preg_match('/^para\d+_[a-zA-Z].*$/', $word->real)) {
+                    $commentary = $word->real;
+                }
+            } else {
+                if ($word->style === 'bld') {
+                    $currBold[] = $word->real;
+                } else {
+                    $countBold = count($currBold);
+                    if ($countBold === 1) {
+                        $bold1[] = $currBold[0];
+                    } elseif ($countBold === 2) {
+                        $bold2 = array_merge($bold2, $currBold);
+                    } elseif ($countBold > 0) {
+                        $bold3 = array_merge($bold3, $currBold);
+                    }
+                    $currBold = [];
+                }
+            }
+        }
+
+        $data = [
             'markdown' => implode("\n", $markdown),
-            'text' => implode("", $text),
+            'text' => implode(" ", $text),
+            'words' => $wordList,
+            'bold1' => $bold1,
+            'bold2' => $bold2,
+            'bold3' => $bold3,
         ];
+        if (isset($commentary)) {
+            $data['commentary'] = $commentary;
+        }
+        return $data;
     }
 
     /**
@@ -170,15 +182,17 @@ class SearchPaliDataService
             ->orderBy('wid')
             ->get();
 
-        $text = [];
+        $arrText = [];
         $markdown = '';
+        $wordList = [];
         foreach ($words as $word) {
-            $text[] = str_replace(['{', '}'], ['', ''], $word->word);
+            $arrText[] = str_replace(['{', '}'], ['', ''], $word->word);
+            $wordList[] = $word->real;
             if ($word->style === 'bld') {
                 if (strpos($word->word, '{') === false) {
                     $markdown .= "**{$word->word}** ";
                 } else {
-                    $markdown .= str_replace(['{', '}'], ['**', '** '], $word->word);
+                    $markdown .= str_replace(['{', '}'], ['**', '**'], $word->word) . ' ';
                 }
             } elseif ($word->style === 'note') {
                 $markdown .= " ~~{$word->word}~~ ";
@@ -186,10 +200,14 @@ class SearchPaliDataService
                 $markdown .= $word->word . ' ';
             }
         }
-
+        $markdown = str_replace([' ti', ' ,', ' .', ' ?'], ['ti', ',', '.', '?'], $markdown);
+        $markdown = str_replace(['~~  ~~', '** **'], [' ', ' '], $markdown);
+        $text = implode(' ', $arrText);
+        $text = str_replace([' ti', ' ,', ' .', ' ?'], ['ti', ',', '.', '?'], $text);
         return [
-            'markdown' => $this->abbrReplace(trim(str_replace(['~~  ~~', '** **'], [' ', ' '], $markdown))),
-            'text' => $this->abbrReplace(implode(' ', $text)),
+            'markdown' => $this->abbrReplace(trim($markdown)),
+            'text' => $this->abbrReplace($text),
+            'words' => $wordList,
         ];
     }
     private function abbrReplace($input)