8 public function __construct($baseUrl)
10 $this->baseUrl = $baseUrl;
13 public function isKnown($url)
15 $r = new Elasticsearch_Request(
16 $this->baseUrl . 'document/' . rawurlencode($url),
17 \HTTP_Request2::METHOD_HEAD
21 return $res->getStatus() == 200;
24 public function get($url)
26 $r = new Elasticsearch_Request(
27 $this->baseUrl . 'document/' . rawurlencode($url),
28 \HTTP_Request2::METHOD_GET
32 if ($res->getStatus() != 200) {
35 $d = json_decode($res->getBody());
39 public function markQueued($url)
41 $r = new Elasticsearch_Request(
42 $this->baseUrl . 'document/' . rawurlencode($url),
43 \HTTP_Request2::METHOD_PUT
49 $r->setBody(json_encode($doc));
53 public function search($query, $filters, $site, $page, $perPage, $sort)
55 if (preg_match_all('#nick:([^ ]*)#', $query, $matches)) {
56 foreach ($matches[1] as $authorName) {
58 'nick:' . $authorName,
59 'author.name:' . $authorName,
65 $qMust = array();//query parts for the MUST section
67 //modification date filters
68 if (preg_match('#after:([^ ]+)#', $query, $matches)) {
69 $dateAfter = $matches[1];
70 $query = trim(str_replace($matches[0], '', $query));
74 'gt' => $dateAfter . '||/d',
79 if (preg_match('#before:([^ ]+)#', $query, $matches)) {
80 $dateBefore = $matches[1];
81 $query = trim(str_replace($matches[0], '', $query));
85 'lt' => $dateBefore . '||/d',
90 if (preg_match('#date:([^ ]+)#', $query, $matches)) {
91 $dateExact = $matches[1];
92 $query = trim(str_replace($matches[0], '', $query));
96 'gte' => $dateExact . '||/d',
97 'lte' => $dateExact . '||/d',
104 'query_string' => array(
105 'default_field' => '_all',
106 'default_operator' => 'AND',
112 'status' => 'indexed'
116 if ($sort == 'date') {
117 $sortCfg = array('modate' => array('order' => 'desc'));
122 $contentMatchSize = 100;
123 if ($GLOBALS['phinde']['showFullContent']) {
124 $contentMatchSize = 999999;
127 $r = new Elasticsearch_Request(
128 $this->baseUrl . 'document/_search',
129 \HTTP_Request2::METHOD_GET
143 'highlight' => array(
144 'pre_tags' => array('<em class="hl">'),
149 'require_field_match' => false,
150 'number_of_fragments' => 0,
153 'require_field_match' => false,
154 'number_of_fragments' => 0,
157 'require_field_match' => false,
158 'number_of_fragments' => 1,
159 'fragment_size' => $contentMatchSize,
160 'no_match_size' => $contentMatchSize,
164 'aggregations' => array(
172 'field' => 'language'
186 'from' => $page * $perPage,
190 foreach ($filters as $type => $value) {
191 $doc['query']['bool']['must'][] = array(
198 $doc['query']['bool']['must'][] = array(
200 'schemalessUrl' => array(
207 //unset($doc['_source']);
209 //ini_set('xdebug.var_display_max_depth', 10);
210 //echo json_encode($doc);die();
211 $r->setBody(json_encode($doc));
213 return json_decode($res->getBody());