8 public function __construct($baseUrl)
10 $this->baseUrl = $baseUrl;
14 * @link https://www.elastic.co/guide/en/elasticsearch/guide/current/_finding_exact_values.html
16 public function isKnown($url)
18 $r = new Elasticsearch_Request(
19 $this->baseUrl . 'document/_search/exists',
20 \HTTP_Request2::METHOD_GET
38 $status = $r->send()->getStatus();
39 return $status !== 404;
42 public function get($url)
44 $r = new Elasticsearch_Request(
45 $this->baseUrl . 'document/' . rawurlencode($url),
46 \HTTP_Request2::METHOD_GET
50 if ($res->getStatus() != 200) {
53 $d = json_decode($res->getBody());
57 public function markQueued($url)
59 $r = new Elasticsearch_Request(
60 $this->baseUrl . 'document/' . rawurlencode($url),
61 \HTTP_Request2::METHOD_PUT
67 $r->setBody(json_encode($doc));
71 public function search($query, $filters, $site, $page, $perPage, $sort)
73 if (preg_match('#nick:([^ ]*)#', $query, $matches)) {
74 $authorName = $matches[1];
76 'nick:' . $authorName,
77 'author.name:' . $authorName,
82 $qMust = array();//query parts for the MUST section
84 //modification date filters
85 if (preg_match('#after:([^ ]+)#', $query, $matches)) {
86 $dateAfter = $matches[1];
87 $query = trim(str_replace($matches[0], '', $query));
91 'gt' => $dateAfter . '||/d',
96 if (preg_match('#before:([^ ]+)#', $query, $matches)) {
97 $dateBefore = $matches[1];
98 $query = trim(str_replace($matches[0], '', $query));
102 'lt' => $dateBefore . '||/d',
107 if (preg_match('#date:([^ ]+)#', $query, $matches)) {
108 $dateExact = $matches[1];
109 $query = trim(str_replace($matches[0], '', $query));
113 'gte' => $dateExact . '||/d',
114 'lte' => $dateExact . '||/d',
121 'query_string' => array(
122 'default_field' => '_all',
123 'default_operator' => 'AND',
129 'status' => 'indexed'
133 if ($sort == 'date') {
134 $sortCfg = array('modate' => array('order' => 'desc'));
139 $contentMatchSize = 100;
140 if ($GLOBALS['phinde']['showFullContent']) {
141 $contentMatchSize = 999999;
144 $r = new Elasticsearch_Request(
145 $this->baseUrl . 'document/_search',
146 \HTTP_Request2::METHOD_GET
160 'highlight' => array(
161 'pre_tags' => array('<em class="hl">'),
166 'require_field_match' => false,
167 'number_of_fragments' => 0,
170 'require_field_match' => false,
171 'number_of_fragments' => 0,
174 'require_field_match' => false,
175 'number_of_fragments' => 1,
176 'fragment_size' => $contentMatchSize,
177 'no_match_size' => $contentMatchSize,
181 'aggregations' => array(
189 'field' => 'language'
203 'from' => $page * $perPage,
207 foreach ($filters as $type => $value) {
208 $doc['query']['bool']['must'][] = array(
215 $doc['query']['bool']['must'][] = array(
217 'schemalessUrl' => array(
224 //unset($doc['_source']);
226 //ini_set('xdebug.var_display_max_depth', 10);
227 //echo json_encode($doc);die();
228 $r->setBody(json_encode($doc));
230 return json_decode($res->getBody());