visuddhinanda vor 2 Jahren
Ursprung
Commit
aa841abc84
2 geänderte Dateien mit 49 neuen und 4 gelöschten Zeilen
  1. 3 1
      app/Console/Commands/TestSearchPali.php
  2. 46 3
      app/Tools/PaliSearch.php

+ 3 - 1
app/Console/Commands/TestSearchPali.php

@@ -38,7 +38,9 @@ class TestSearchPali extends Command
      */
     public function handle()
     {
-        $result = PaliSearch::search(['citta'],2,0,10);
+        //$result = PaliSearch::search(['citta'],[93,94],'case',0,10);
+        //var_dump($result);
+        $result = PaliSearch::book_list(['citta'],[93,94],'case',0,10);
         var_dump($result);
         return 0;
     }

+ 46 - 3
app/Tools/PaliSearch.php

@@ -5,7 +5,7 @@ use Illuminate\Support\Facades\Log;
 
 class PaliSearch
 {
-    public static function search($words,$book,$index,$size){
+    public static function search($words,$books,$matchMode='case',$index=0,$size=10){
         $host = config('mint.server.rpc.tulip');
         Log::debug('tulip host='.$host);
         $client = new \Mint\Tulip\V1\SearchClient($host, [
@@ -14,7 +14,8 @@ class PaliSearch
 
         $request = new \Mint\Tulip\V1\SearchRequest();
         $request->setKeywords($words);
-        $request->setBook($book);
+        $request->setBooks($books);
+        $request->setMatchMode($matchMode);
         $page = new \Mint\Tulip\V1\SearchRequest\Page;
         $page->setIndex($index);
         $page->setSize($size);
@@ -25,8 +26,50 @@ class PaliSearch
             Log::error("ERROR: " . $status->code . ", " . $status->details);
             return false;
         }
-        return $response->getItems();
+        $output = [];
+        $output['total'] = $response->getTotal();
+        $output['rows'] = [];
+        foreach ($response->getItems() as $key => $value) {
+            $output['rows'][] = [
+                'rank' => $value->getRank(),
+                'highlight' => $value->getHighlight(),
+                'book' => $value->getBook(),
+                'paragraph' => $value->getParagraph(),
+                'content' => $value->getContent(),
+            ];
+        }
+        return $output;
     }
 
+    public static function book_list($words,$books,$matchMode='case',$index=0,$size=10){
+        $host = config('mint.server.rpc.tulip');
+        Log::debug('tulip host='.$host);
+        $client = new \Mint\Tulip\V1\SearchClient($host, [
+            'credentials' => \Grpc\ChannelCredentials::createInsecure(),
+        ]);
 
+        $request = new \Mint\Tulip\V1\SearchRequest();
+        $request->setKeywords($words);
+        $request->setBooks($books);
+        $request->setMatchMode($matchMode);
+        $page = new \Mint\Tulip\V1\SearchRequest\Page;
+        $page->setIndex($index);
+        $page->setSize($size);
+        $request->setPage($page);
+
+        list($response, $status) = $client->BookList($request)->wait();
+        if ($status->code !== \Grpc\STATUS_OK) {
+            Log::error("ERROR: " . $status->code . ", " . $status->details);
+            return false;
+        }
+        $output = [];
+        $output['rows'] = [];
+        foreach ($response->getItems() as $key => $value) {
+            $output['rows'][] = [
+                'pcd_book_id' => $value->getBook(),
+                'co' => $value->getCount(),
+            ];
+        }
+        return $output;
+    }
 }