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 Database_Adapter_Elasticsearch_HTTPRequest(
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(
38 'default_operator' => 'AND'
42 'has_child' => (object)array(
44 'query' => (object)array(
45 'query_string' => (object)array(
47 'default_operator' => 'AND'
58 $httpRes = $r->send();
59 $jRes = json_decode($httpRes->getBody());
60 if (isset($jRes->error)) {
62 'Search exception: ' . $jRes->error, $jRes->status
66 $sres = new Search_Result();
67 $sres->results = $jRes->hits->total;
69 $sres->perPage = $perPage;
71 foreach ($jRes->hits->hits as $hit) {
72 $r = new Repository();
73 //FIXME: error handling. what about deleted repos?
74 $r->loadById($hit->_source->id);