Update jQuery from 1.12.4 to 3.7.1
[phorkie.git] / src / phorkie / Database / Adapter / Elasticsearch / Setup.php
1 <?php
2 namespace phorkie;
3
4 class Database_Adapter_Elasticsearch_Setup implements Database_ISetup
5 {
6     public function __construct()
7     {
8         $this->searchInstance = $GLOBALS['phorkie']['cfg']['elasticsearch'];
9     }
10
11     public function setup()
12     {
13         $r = new \HTTP_Request2(
14             $this->searchInstance . '/_mapping', \HTTP_Request2::METHOD_GET
15         );
16         $res = $r->send();
17         if ($res->getStatus() == 404) {
18             $this->reset();
19         }
20     }
21
22     public function reset()
23     {
24         $r = new \HTTP_Request2(
25             $this->searchInstance,
26             \HTTP_Request2::METHOD_DELETE
27         );
28         $r->send();
29
30         $r = new Database_Adapter_Elasticsearch_HTTPRequest(
31             $this->searchInstance,
32             \HTTP_Request2::METHOD_PUT
33         );
34         $r->send();
35
36         //mapping for files
37         $r = new Database_Adapter_Elasticsearch_HTTPRequest(
38             $this->searchInstance . 'file/_mapping',
39             \HTTP_Request2::METHOD_PUT
40         );
41         $r->setBody(
42             json_encode(
43                 (object)array(
44                     'file' => (object)array(
45                         '_parent' => (object)array(
46                             'type' => 'repo'
47                         ),
48                         'properties' => (object)array(
49                             'name' => (object)array(
50                                 'type'  => 'string',
51                                 'boost' => 1.5
52                             ),
53                             'extension' => (object)array(
54                                 'type'  => 'string',
55                                 'boost' => 1.0
56                             ),
57                             'content' => (object)array(
58                                 'type'  => 'string',
59                                 'boost' => 0.8
60                             )
61                         )
62                     )
63                 )
64             )
65         );
66         $r->send();
67
68         //create mapping
69         //mapping for repositories
70         $r = new Database_Adapter_Elasticsearch_HTTPRequest(
71             $this->searchInstance . 'repo/_mapping',
72             \HTTP_Request2::METHOD_PUT
73         );
74         $r->setBody(
75             json_encode(
76                 (object)array(
77                     'repo' => (object)array(
78                         '_timestamp' => (object)array(
79                             'enabled' => true,
80                             //'path'    => 'tstamp',
81                         ),
82                         'properties' => (object)array(
83                             'id' => (object)array(
84                                 'type' => 'long'
85                             ),
86                             'description' => (object)array(
87                                 'type'  => 'string',
88                                 'boost' => 2.0
89                             ),
90                             'crdate' => (object)array(
91                                 //creation date
92                                 'type' => 'date',
93                             ),
94                             'modate' => (object)array(
95                                 //modification date
96                                 'type' => 'date',
97                             ),
98                             'tstamp' => (object)array(
99                                 //last indexed date
100                                 'type' => 'date',
101                             )
102                         )
103                     )
104                 )
105             )
106         );
107         $r->send();
108     }
109
110 }
111
112 ?>