use httprequest wrapper to automatically check for errors
[phorkie.git] / src / phorkie / Database / Setup / Elasticsearch.php
1 <?php
2 namespace phorkie;
3
4 class Database_Setup_Elasticsearch
5 {
6     public function __construct()
7     {
8         $this->searchInstance = $GLOBALS['phorkie']['cfg']['elasticsearch'];
9     }
10
11     public function setup()
12     {
13         $r = new Database_Adapter_Elasticsearch_HTTPRequest(
14             $this->searchInstance . 'repo/_mapping',
15             \HTTP_Request2::METHOD_DELETE
16         );
17         $r->send();
18
19         //create mapping
20         //mapping for repositories
21         $r = new Database_Adapter_Elasticsearch_HTTPRequest(
22             $this->searchInstance . 'repo/_mapping',
23             \HTTP_Request2::METHOD_PUT
24         );
25         $r->setBody(
26             json_encode(
27                 (object)array(
28                     'repo' => (object)array(
29                         '_timestamp' => (object)array(
30                             'enabled' => true,
31                             'path'    => 'tstamp',
32                         ),
33                         'properties' => (object)array(
34                             'id' => (object)array(
35                                 'type' => 'long'
36                             ),
37                             'description' => (object)array(
38                                 'type'  => 'string',
39                                 'boost' => 2.0
40                             ),
41                             'crdate' => (object)array(
42                                 //creation date
43                                 'type' => 'date',
44                             ),
45                             'tstamp' => (object)array(
46                                 //modification date
47                                 'type' => 'date',
48                             )
49                         )
50                     )
51                 )
52             )
53         );
54         $r->send();
55
56         //mapping for files
57         $r = new Database_Adapter_Elasticsearch_HTTPRequest(
58             $this->searchInstance . 'file/_mapping',
59             \HTTP_Request2::METHOD_PUT
60         );
61         $r->setBody(
62             json_encode(
63                 (object)array(
64                     'file' => (object)array(
65                         '_parent' => (object)array(
66                             'type' => 'repo'
67                         ),
68                         'properties' => (object)array(
69                             'name' => (object)array(
70                                 'type'  => 'string',
71                                 'boost' => 1.5
72                             ),
73                             'extension' => (object)array(
74                                 'type'  => 'string',
75                                 'boost' => 1.0
76                             ),
77                             'content' => (object)array(
78                                 'type'  => 'string',
79                                 'boost' => 0.8
80                             )
81                         )
82                     )
83                 )
84             )
85         );
86         $r->send();
87     }
88
89 }
90
91 ?>