8 public function __construct($baseUrl)
10 $this->baseUrl = $baseUrl;
13 public static function getDocId($url)
15 return hash('sha256', $url);
18 public function isKnown($url)
20 $r = new Elasticsearch_Request(
21 $this->baseUrl . 'document/' . static::getDocId($url),
22 \HTTP_Request2::METHOD_HEAD
26 return $res->getStatus() == 200;
29 public function get($url)
31 $r = new Elasticsearch_Request(
32 $this->baseUrl . 'document/' . static::getDocId($url),
33 \HTTP_Request2::METHOD_GET
37 if ($res->getStatus() != 200) {
40 $d = json_decode($res->getBody());
44 public function markQueued($url)
46 $r = new Elasticsearch_Request(
47 $this->baseUrl . 'document/' . static::getDocId($url),
48 \HTTP_Request2::METHOD_PUT
50 $doc = (object) array(
52 'status' => (object) array(
57 $r->setBody(json_encode($doc));
61 public function countDocuments()
63 $r = new Elasticsearch_Request(
64 $this->baseUrl . 'document/_count',
65 \HTTP_Request2::METHOD_GET
68 return json_decode($res->getBody())->count;
71 public function search($query, $filters, $site, $page, $perPage, $sort)
73 if (preg_match_all('#nick:([^ ]*)#', $query, $matches)) {
74 foreach ($matches[1] as $authorName) {
76 'nick:' . $authorName,
77 'author.name:' . $authorName,
83 $qMust = array();//query parts for the MUST section
85 //modification date filters
86 if (preg_match('#after:([^ ]+)#', $query, $matches)) {
87 $dateAfter = $matches[1];
88 $query = trim(str_replace($matches[0], '', $query));
92 'gt' => $dateAfter . '||/d',
97 if (preg_match('#before:([^ ]+)#', $query, $matches)) {
98 $dateBefore = $matches[1];
99 $query = trim(str_replace($matches[0], '', $query));
103 'lt' => $dateBefore . '||/d',
108 if (preg_match('#date:([^ ]+)#', $query, $matches)) {
109 $dateExact = $matches[1];
110 $query = trim(str_replace($matches[0], '', $query));
114 'gte' => $dateExact . '||/d',
115 'lte' => $dateExact . '||/d',
122 'query_string' => array(
123 'default_field' => '_all',
124 'default_operator' => 'AND',
130 'status.findable' => true
134 if ($sort == 'date') {
135 $sortCfg = array('status.modate' => array('order' => 'desc'));
140 $contentMatchSize = 100;
141 if ($GLOBALS['phinde']['showFullContent']) {
142 $contentMatchSize = 999999;
145 $r = new Elasticsearch_Request(
146 $this->baseUrl . 'document/_search',
147 \HTTP_Request2::METHOD_GET
161 'highlight' => array(
162 'pre_tags' => array('<em class="hl">'),
167 'require_field_match' => false,
168 'number_of_fragments' => 0,
171 'require_field_match' => false,
172 'number_of_fragments' => 0,
175 'require_field_match' => false,
176 'number_of_fragments' => 1,
177 'fragment_size' => $contentMatchSize,
178 'no_match_size' => $contentMatchSize,
182 'aggregations' => array(
190 'field' => 'language'
204 'from' => $page * $perPage,
208 foreach ($filters as $type => $value) {
209 $doc['query']['bool']['must'][] = array(
216 $doc['query']['bool']['must'][] = array(
218 'schemalessUrl' => array(
225 //unset($doc['_source']);
227 //ini_set('xdebug.var_display_max_depth', 10);
228 //echo json_encode($doc);die();
229 $r->setBody(json_encode($doc));
231 return json_decode($res->getBody());