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 search($query, $filters, $site, $page, $perPage, $sort)
63 if (preg_match_all('#nick:([^ ]*)#', $query, $matches)) {
64 foreach ($matches[1] as $authorName) {
66 'nick:' . $authorName,
67 'author.name:' . $authorName,
73 $qMust = array();//query parts for the MUST section
75 //modification date filters
76 if (preg_match('#after:([^ ]+)#', $query, $matches)) {
77 $dateAfter = $matches[1];
78 $query = trim(str_replace($matches[0], '', $query));
82 'gt' => $dateAfter . '||/d',
87 if (preg_match('#before:([^ ]+)#', $query, $matches)) {
88 $dateBefore = $matches[1];
89 $query = trim(str_replace($matches[0], '', $query));
93 'lt' => $dateBefore . '||/d',
98 if (preg_match('#date:([^ ]+)#', $query, $matches)) {
99 $dateExact = $matches[1];
100 $query = trim(str_replace($matches[0], '', $query));
104 'gte' => $dateExact . '||/d',
105 'lte' => $dateExact . '||/d',
112 'query_string' => array(
113 'default_field' => '_all',
114 'default_operator' => 'AND',
120 'status.findable' => true
124 if ($sort == 'date') {
125 $sortCfg = array('status.modate' => array('order' => 'desc'));
130 $contentMatchSize = 100;
131 if ($GLOBALS['phinde']['showFullContent']) {
132 $contentMatchSize = 999999;
135 $r = new Elasticsearch_Request(
136 $this->baseUrl . 'document/_search',
137 \HTTP_Request2::METHOD_GET
151 'highlight' => array(
152 'pre_tags' => array('<em class="hl">'),
157 'require_field_match' => false,
158 'number_of_fragments' => 0,
161 'require_field_match' => false,
162 'number_of_fragments' => 0,
165 'require_field_match' => false,
166 'number_of_fragments' => 1,
167 'fragment_size' => $contentMatchSize,
168 'no_match_size' => $contentMatchSize,
172 'aggregations' => array(
180 'field' => 'language'
194 'from' => $page * $perPage,
198 foreach ($filters as $type => $value) {
199 $doc['query']['bool']['must'][] = array(
206 $doc['query']['bool']['must'][] = array(
208 'schemalessUrl' => array(
215 //unset($doc['_source']);
217 //ini_set('xdebug.var_display_max_depth', 10);
218 //echo json_encode($doc);die();
219 $r->setBody(json_encode($doc));
221 return json_decode($res->getBody());