4 class Search_Elasticsearch
6 public function __construct()
8 $this->searchInstance = $GLOBALS['phorkie']['cfg']['elasticsearch'];
12 * Search for a given term and return repositories that contain it
13 * in their description, file names or file content
15 * @param string $term Search term
16 * @param integer $page Page of search results, starting with 0
17 * @param integer $perPage Number of results per page
19 * @return Search_Result Search result object
21 public function search($term, $page = 0, $perPage = 10)
23 $r = new \HTTP_Request2(
24 $this->searchInstance . 'repo/_search',
25 \HTTP_Request2::METHOD_GET
30 'from' => $page * $perPage,
32 'query' => (object)array(
33 'bool' => (object)array(
36 'query_string' => (object)array(
41 'has_child' => (object)array(
43 'query' => (object)array(
44 'query_string' => (object)array(
56 //FIXME: error handling
57 $httpRes = $r->send();
58 $jRes = json_decode($httpRes->getBody());
60 $sres = new Search_Result();
61 $sres->results = $jRes->hits->total;
63 $sres->perPage = $perPage;
65 foreach ($jRes->hits->hits as $hit) {
66 $r = new Repository();
67 //FIXME: error handling. what about deleted repos?
68 $r->loadById($hit->_source->id);