automatic mapping setup for elasticsearch through setupcheck
[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         //create mapping
14         //mapping for repositories
15         $r = new \HTTP_Request2(
16             $this->searchInstance . 'repo/_mapping',
17             \HTTP_Request2::METHOD_PUT
18         );
19         $r->setBody(
20             json_encode(
21                 (object)array(
22                     'repo' => (object)array(
23                         'properties' => (object)array(
24                             'id' => (object)array(
25                                 'type' => 'long'
26                             ),
27                             'description' => (object)array(
28                                 'type'  => 'string',
29                                 'boost' => 2.0
30                             )
31                         )
32                     )
33                 )
34             )
35         );
36         $r->send();
37
38         //mapping for files
39         $r = new \HTTP_Request2(
40             $this->searchInstance . 'file/_mapping',
41             \HTTP_Request2::METHOD_PUT
42         );
43         $r->setBody(
44             json_encode(
45                 (object)array(
46                     'file' => (object)array(
47                         '_parent' => (object)array(
48                             'type' => 'repo'
49                         ),
50                         'properties' => (object)array(
51                             'name' => (object)array(
52                                 'type'  => 'string',
53                                 'boost' => 1.5
54                             ),
55                             'extension' => (object)array(
56                                 'type'  => 'string',
57                                 'boost' => 1.0
58                             ),
59                             'content' => (object)array(
60                                 'type'  => 'string',
61                                 'boost' => 0.8
62                             )
63                         )
64                     )
65                 )
66             )
67         );
68         $r->send();
69     }
70
71 }
72
73 ?>