visuddhinanda 2 år sedan
förälder
incheckning
7ceee8f03b

+ 27 - 0
app/Tools/PaliSearch.php

@@ -0,0 +1,27 @@
+<?php
+namespace App\Tools;
+use Illuminate\Support\Str;
+use Illuminate\Support\Facades\Log;
+
+class PaliSearch
+{
+    public static function search($words,$book,$page){
+        $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->setBook($book);
+        $request->setPage($page);
+
+        list($response, $status) = $client->Pali($request)->wait();
+        if ($status->code !== \Grpc\STATUS_OK) {
+            Log::error("ERROR: " . $status->code . ", " . $status->details);
+            return $text;
+        }
+        return $response->getPayload();
+    }
+
+}

+ 33 - 0
grpc/Mint/Tulip/V1/SearchClient.php

@@ -0,0 +1,33 @@
+<?php
+// GENERATED CODE -- DO NOT EDIT!
+
+namespace Mint\Tulip\V1;
+
+/**
+ */
+class SearchClient extends \Grpc\BaseStub {
+
+    /**
+     * @param string $hostname hostname
+     * @param array $opts channel options
+     * @param \Grpc\Channel $channel (optional) re-use channel object
+     */
+    public function __construct($hostname, $opts, $channel = null) {
+        parent::__construct($hostname, $opts, $channel);
+    }
+
+    /**
+     * @param \Mint\Tulip\V1\SearchRequest $argument input argument
+     * @param array $metadata metadata
+     * @param array $options call options
+     * @return \Grpc\UnaryCall
+     */
+    public function Pali(\Mint\Tulip\V1\SearchRequest $argument,
+      $metadata = [], $options = []) {
+        return $this->_simpleRequest('/mint.tulip.v1.Search/Pali',
+        $argument,
+        ['\Mint\Tulip\V1\SearchResponse', 'decode'],
+        $metadata, $options);
+    }
+
+}

+ 124 - 0
grpc/Mint/Tulip/V1/SearchRequest.php

@@ -0,0 +1,124 @@
+<?php
+# Generated by the protocol buffer compiler.  DO NOT EDIT!
+# source: tulip.proto
+
+namespace Mint\Tulip\V1;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * ----------------------------------------------------------------------------
+ *
+ * Generated from protobuf message <code>mint.tulip.v1.SearchRequest</code>
+ */
+class SearchRequest extends \Google\Protobuf\Internal\Message
+{
+    /**
+     * Generated from protobuf field <code>repeated string keywords = 1;</code>
+     */
+    private $keywords;
+    /**
+     * Generated from protobuf field <code>int32 book = 2;</code>
+     */
+    protected $book = 0;
+    /**
+     * Generated from protobuf field <code>optional .mint.tulip.v1.SearchRequest.Page page = 99;</code>
+     */
+    protected $page = null;
+
+    /**
+     * Constructor.
+     *
+     * @param array $data {
+     *     Optional. Data for populating the Message object.
+     *
+     *     @type array<string>|\Google\Protobuf\Internal\RepeatedField $keywords
+     *     @type int $book
+     *     @type \Mint\Tulip\V1\SearchRequest\Page $page
+     * }
+     */
+    public function __construct($data = NULL) {
+        \GPBMetadata\Tulip::initOnce();
+        parent::__construct($data);
+    }
+
+    /**
+     * Generated from protobuf field <code>repeated string keywords = 1;</code>
+     * @return \Google\Protobuf\Internal\RepeatedField
+     */
+    public function getKeywords()
+    {
+        return $this->keywords;
+    }
+
+    /**
+     * Generated from protobuf field <code>repeated string keywords = 1;</code>
+     * @param array<string>|\Google\Protobuf\Internal\RepeatedField $var
+     * @return $this
+     */
+    public function setKeywords($var)
+    {
+        $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING);
+        $this->keywords = $arr;
+
+        return $this;
+    }
+
+    /**
+     * Generated from protobuf field <code>int32 book = 2;</code>
+     * @return int
+     */
+    public function getBook()
+    {
+        return $this->book;
+    }
+
+    /**
+     * Generated from protobuf field <code>int32 book = 2;</code>
+     * @param int $var
+     * @return $this
+     */
+    public function setBook($var)
+    {
+        GPBUtil::checkInt32($var);
+        $this->book = $var;
+
+        return $this;
+    }
+
+    /**
+     * Generated from protobuf field <code>optional .mint.tulip.v1.SearchRequest.Page page = 99;</code>
+     * @return \Mint\Tulip\V1\SearchRequest\Page|null
+     */
+    public function getPage()
+    {
+        return $this->page;
+    }
+
+    public function hasPage()
+    {
+        return isset($this->page);
+    }
+
+    public function clearPage()
+    {
+        unset($this->page);
+    }
+
+    /**
+     * Generated from protobuf field <code>optional .mint.tulip.v1.SearchRequest.Page page = 99;</code>
+     * @param \Mint\Tulip\V1\SearchRequest\Page $var
+     * @return $this
+     */
+    public function setPage($var)
+    {
+        GPBUtil::checkMessage($var, \Mint\Tulip\V1\SearchRequest\Page::class);
+        $this->page = $var;
+
+        return $this;
+    }
+
+}
+

+ 88 - 0
grpc/Mint/Tulip/V1/SearchRequest/Page.php

@@ -0,0 +1,88 @@
+<?php
+# Generated by the protocol buffer compiler.  DO NOT EDIT!
+# source: tulip.proto
+
+namespace Mint\Tulip\V1\SearchRequest;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * Generated from protobuf message <code>mint.tulip.v1.SearchRequest.Page</code>
+ */
+class Page extends \Google\Protobuf\Internal\Message
+{
+    /**
+     * Generated from protobuf field <code>int32 index = 1;</code>
+     */
+    protected $index = 0;
+    /**
+     * Generated from protobuf field <code>int32 size = 2;</code>
+     */
+    protected $size = 0;
+
+    /**
+     * Constructor.
+     *
+     * @param array $data {
+     *     Optional. Data for populating the Message object.
+     *
+     *     @type int $index
+     *     @type int $size
+     * }
+     */
+    public function __construct($data = NULL) {
+        \GPBMetadata\Tulip::initOnce();
+        parent::__construct($data);
+    }
+
+    /**
+     * Generated from protobuf field <code>int32 index = 1;</code>
+     * @return int
+     */
+    public function getIndex()
+    {
+        return $this->index;
+    }
+
+    /**
+     * Generated from protobuf field <code>int32 index = 1;</code>
+     * @param int $var
+     * @return $this
+     */
+    public function setIndex($var)
+    {
+        GPBUtil::checkInt32($var);
+        $this->index = $var;
+
+        return $this;
+    }
+
+    /**
+     * Generated from protobuf field <code>int32 size = 2;</code>
+     * @return int
+     */
+    public function getSize()
+    {
+        return $this->size;
+    }
+
+    /**
+     * Generated from protobuf field <code>int32 size = 2;</code>
+     * @param int $var
+     * @return $this
+     */
+    public function setSize($var)
+    {
+        GPBUtil::checkInt32($var);
+        $this->size = $var;
+
+        return $this;
+    }
+
+}
+
+// Adding a class alias for backwards compatibility with the previous class name.
+class_alias(Page::class, \Mint\Tulip\V1\SearchRequest_Page::class);
+

+ 122 - 0
grpc/Mint/Tulip/V1/SearchResponse.php

@@ -0,0 +1,122 @@
+<?php
+# Generated by the protocol buffer compiler.  DO NOT EDIT!
+# source: tulip.proto
+
+namespace Mint\Tulip\V1;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * Generated from protobuf message <code>mint.tulip.v1.SearchResponse</code>
+ */
+class SearchResponse extends \Google\Protobuf\Internal\Message
+{
+    /**
+     * Generated from protobuf field <code>repeated .mint.tulip.v1.SearchResponse.Item items = 1;</code>
+     */
+    private $items;
+    /**
+     * Generated from protobuf field <code>.mint.tulip.v1.SearchRequest.Page page = 98;</code>
+     */
+    protected $page = null;
+    /**
+     * Generated from protobuf field <code>int32 total = 99;</code>
+     */
+    protected $total = 0;
+
+    /**
+     * Constructor.
+     *
+     * @param array $data {
+     *     Optional. Data for populating the Message object.
+     *
+     *     @type array<\Mint\Tulip\V1\SearchResponse\Item>|\Google\Protobuf\Internal\RepeatedField $items
+     *     @type \Mint\Tulip\V1\SearchRequest\Page $page
+     *     @type int $total
+     * }
+     */
+    public function __construct($data = NULL) {
+        \GPBMetadata\Tulip::initOnce();
+        parent::__construct($data);
+    }
+
+    /**
+     * Generated from protobuf field <code>repeated .mint.tulip.v1.SearchResponse.Item items = 1;</code>
+     * @return \Google\Protobuf\Internal\RepeatedField
+     */
+    public function getItems()
+    {
+        return $this->items;
+    }
+
+    /**
+     * Generated from protobuf field <code>repeated .mint.tulip.v1.SearchResponse.Item items = 1;</code>
+     * @param array<\Mint\Tulip\V1\SearchResponse\Item>|\Google\Protobuf\Internal\RepeatedField $var
+     * @return $this
+     */
+    public function setItems($var)
+    {
+        $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Mint\Tulip\V1\SearchResponse\Item::class);
+        $this->items = $arr;
+
+        return $this;
+    }
+
+    /**
+     * Generated from protobuf field <code>.mint.tulip.v1.SearchRequest.Page page = 98;</code>
+     * @return \Mint\Tulip\V1\SearchRequest\Page|null
+     */
+    public function getPage()
+    {
+        return $this->page;
+    }
+
+    public function hasPage()
+    {
+        return isset($this->page);
+    }
+
+    public function clearPage()
+    {
+        unset($this->page);
+    }
+
+    /**
+     * Generated from protobuf field <code>.mint.tulip.v1.SearchRequest.Page page = 98;</code>
+     * @param \Mint\Tulip\V1\SearchRequest\Page $var
+     * @return $this
+     */
+    public function setPage($var)
+    {
+        GPBUtil::checkMessage($var, \Mint\Tulip\V1\SearchRequest\Page::class);
+        $this->page = $var;
+
+        return $this;
+    }
+
+    /**
+     * Generated from protobuf field <code>int32 total = 99;</code>
+     * @return int
+     */
+    public function getTotal()
+    {
+        return $this->total;
+    }
+
+    /**
+     * Generated from protobuf field <code>int32 total = 99;</code>
+     * @param int $var
+     * @return $this
+     */
+    public function setTotal($var)
+    {
+        GPBUtil::checkInt32($var);
+        $this->total = $var;
+
+        return $this;
+    }
+
+}
+

+ 169 - 0
grpc/Mint/Tulip/V1/SearchResponse/Item.php

@@ -0,0 +1,169 @@
+<?php
+# Generated by the protocol buffer compiler.  DO NOT EDIT!
+# source: tulip.proto
+
+namespace Mint\Tulip\V1\SearchResponse;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * Generated from protobuf message <code>mint.tulip.v1.SearchResponse.Item</code>
+ */
+class Item extends \Google\Protobuf\Internal\Message
+{
+    /**
+     * Generated from protobuf field <code>int32 rank = 1;</code>
+     */
+    protected $rank = 0;
+    /**
+     * Generated from protobuf field <code>string highlight = 2;</code>
+     */
+    protected $highlight = '';
+    /**
+     * Generated from protobuf field <code>int32 book = 3;</code>
+     */
+    protected $book = 0;
+    /**
+     * Generated from protobuf field <code>int32 paragraph = 4;</code>
+     */
+    protected $paragraph = 0;
+    /**
+     * Generated from protobuf field <code>string content = 5;</code>
+     */
+    protected $content = '';
+
+    /**
+     * Constructor.
+     *
+     * @param array $data {
+     *     Optional. Data for populating the Message object.
+     *
+     *     @type int $rank
+     *     @type string $highlight
+     *     @type int $book
+     *     @type int $paragraph
+     *     @type string $content
+     * }
+     */
+    public function __construct($data = NULL) {
+        \GPBMetadata\Tulip::initOnce();
+        parent::__construct($data);
+    }
+
+    /**
+     * Generated from protobuf field <code>int32 rank = 1;</code>
+     * @return int
+     */
+    public function getRank()
+    {
+        return $this->rank;
+    }
+
+    /**
+     * Generated from protobuf field <code>int32 rank = 1;</code>
+     * @param int $var
+     * @return $this
+     */
+    public function setRank($var)
+    {
+        GPBUtil::checkInt32($var);
+        $this->rank = $var;
+
+        return $this;
+    }
+
+    /**
+     * Generated from protobuf field <code>string highlight = 2;</code>
+     * @return string
+     */
+    public function getHighlight()
+    {
+        return $this->highlight;
+    }
+
+    /**
+     * Generated from protobuf field <code>string highlight = 2;</code>
+     * @param string $var
+     * @return $this
+     */
+    public function setHighlight($var)
+    {
+        GPBUtil::checkString($var, True);
+        $this->highlight = $var;
+
+        return $this;
+    }
+
+    /**
+     * Generated from protobuf field <code>int32 book = 3;</code>
+     * @return int
+     */
+    public function getBook()
+    {
+        return $this->book;
+    }
+
+    /**
+     * Generated from protobuf field <code>int32 book = 3;</code>
+     * @param int $var
+     * @return $this
+     */
+    public function setBook($var)
+    {
+        GPBUtil::checkInt32($var);
+        $this->book = $var;
+
+        return $this;
+    }
+
+    /**
+     * Generated from protobuf field <code>int32 paragraph = 4;</code>
+     * @return int
+     */
+    public function getParagraph()
+    {
+        return $this->paragraph;
+    }
+
+    /**
+     * Generated from protobuf field <code>int32 paragraph = 4;</code>
+     * @param int $var
+     * @return $this
+     */
+    public function setParagraph($var)
+    {
+        GPBUtil::checkInt32($var);
+        $this->paragraph = $var;
+
+        return $this;
+    }
+
+    /**
+     * Generated from protobuf field <code>string content = 5;</code>
+     * @return string
+     */
+    public function getContent()
+    {
+        return $this->content;
+    }
+
+    /**
+     * Generated from protobuf field <code>string content = 5;</code>
+     * @param string $var
+     * @return $this
+     */
+    public function setContent($var)
+    {
+        GPBUtil::checkString($var, True);
+        $this->content = $var;
+
+        return $this;
+    }
+
+}
+
+// Adding a class alias for backwards compatibility with the previous class name.
+class_alias(Item::class, \Mint\Tulip\V1\SearchResponse_Item::class);
+

+ 41 - 0
grpc/Mint/Tulip/V1/SearchStub.php

@@ -0,0 +1,41 @@
+<?php
+// GENERATED CODE -- DO NOT EDIT!
+
+namespace Mint\Tulip\V1;
+
+/**
+ */
+class SearchStub {
+
+    /**
+     * @param \Mint\Tulip\V1\SearchRequest $request client request
+     * @param \Grpc\ServerContext $context server request context
+     * @return \Mint\Tulip\V1\SearchResponse for response data, null if if error occured
+     *     initial metadata (if any) and status (if not ok) should be set to $context
+     */
+    public function Pali(
+        \Mint\Tulip\V1\SearchRequest $request,
+        \Grpc\ServerContext $context
+    ): ?\Mint\Tulip\V1\SearchResponse {
+        $context->setStatus(\Grpc\Status::unimplemented());
+        return null;
+    }
+
+    /**
+     * Get the method descriptors of the service for server registration
+     *
+     * @return array of \Grpc\MethodDescriptor for the service methods
+     */
+    public final function getMethodDescriptors(): array
+    {
+        return [
+            '/mint.tulip.v1.Search/Pali' => new \Grpc\MethodDescriptor(
+                $this,
+                'Pali',
+                '\Mint\Tulip\V1\SearchRequest',
+                \Grpc\MethodDescriptor::UNARY_CALL
+            ),
+        ];
+    }
+
+}