123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?php
- namespace Mall\Framework\SearchClient\Transport;
- abstract class Base
- {
-
- protected $host = "";
-
- protected $port = 9200;
-
- protected $index;
-
- protected $type;
-
- public function __construct($host, $port)
- {
- $this->host = $host;
- $this->port = $port;
- }
-
- abstract public function index($document, $id = false, array $options = array());
-
- abstract public function request($path, $method = "GET", $payload = false, $buildPath = true);
-
- abstract public function delete($id = false, array $options = array());
-
- abstract public function search($query, array $options = array());
- abstract public function scrollSearch($query, $scroll = '10s', $size = 2000, array $options = array());
- abstract public function batchUpdateFieldVaule($data, $query);
- abstract public function createBase($index, $mappings);
- abstract public function deleteBase($index);
-
- public function deleteByQuery($query, array $options = array())
- {
- throw new \Mall\Framework\SearchClient\Exception(__FUNCTION__ . ' not implemented for ' . __CLASS__);
- }
-
- public function setIndex($index)
- {
- $this->index = $index;
- }
-
- public function setType($type)
- {
- $this->type = $type;
- }
-
- protected function buildUrl($path = false, array $options = array())
- {
- $isAbsolute = (is_array($path) ? isset($path[0][0])?$path[0][0] : '' : $path[0]) === '/';
- $url = $isAbsolute ? '' : "/" . $this->index;
- if ($path && is_array($path) && count($path) > 0)
- $url .= "/" . implode("/", array_filter($path));
- if (substr($url, -1) == "/")
- $url = substr($url, 0, -1);
- if (count($options) > 0)
- $url .= "?" . http_build_query($options, '', '&');
- return $url;
- }
- }
|