author | ymh <ymh.work@gmail.com> |
Thu, 03 Nov 2016 01:52:26 +0100 | |
changeset 387 | 7fba86fa8604 |
parent 320 | 0fce13da58af |
child 407 | 2dba812c7ef2 |
permissions | -rw-r--r-- |
308
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
<?php |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
2 |
|
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
3 |
class GeoStatsControllerTest extends TestCase |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
4 |
{ |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
5 |
public function testGetIndex() |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
6 |
{ |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
7 |
$query = [ |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
8 |
'index' => env('ELASTICSEARCH_INDEX'), |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
9 |
'body' => [ |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
10 |
"size" => 0, |
320 | 11 |
"query" => [ |
12 |
'match_all' => [] |
|
13 |
], |
|
308
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
14 |
"aggs" => [ |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
15 |
"geos" => [ |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
16 |
"terms" => [ |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
17 |
"size" => 0, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
18 |
"field" => "geonames_hierarchy" |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
19 |
] |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
20 |
] |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
21 |
] |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
22 |
] |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
23 |
]; |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
24 |
|
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
25 |
Es::shouldReceive('search') |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
26 |
->once() |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
27 |
->with($query) |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
28 |
->andReturn(json_decode("{ |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
29 |
\"took\" : 17, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
30 |
\"timed_out\" : false, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
31 |
\"_shards\" : { |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
32 |
\"total\" : 1, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
33 |
\"successful\" : 1, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
34 |
\"failed\" : 0 |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
35 |
}, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
36 |
\"hits\" : { |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
37 |
\"total\" : 3011, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
38 |
\"max_score\" : 0.0, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
39 |
\"hits\" : [ ] |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
40 |
}, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
41 |
\"aggregations\" : { |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
42 |
\"geos\" : { |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
43 |
\"doc_count_error_upper_bound\" : 0, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
44 |
\"sum_other_doc_count\" : 0, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
45 |
\"buckets\" : [ { |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
46 |
\"key\" : 6255148, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
47 |
\"doc_count\" : 2684 |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
48 |
}, { |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
49 |
\"key\" : 3017382, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
50 |
\"doc_count\" : 2674 |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
51 |
}, { |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
52 |
\"key\" : 3027939, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
53 |
\"doc_count\" : 851 |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
54 |
} ] |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
55 |
} |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
56 |
} |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
57 |
}", true)); |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
58 |
|
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
59 |
$this->get('/api/v1/stats/geostats/')->assertTrue($this->response->isOk(), $this->response->content()); |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
60 |
$this->seeJsonEquals(["geostats" => [ |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
61 |
'6255148' => 2684, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
62 |
'3017382' => 2674, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
63 |
'3027939' => 851 |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
64 |
]]); |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
65 |
} |
320 | 66 |
|
67 |
||
68 |
public function testGetIndexEarth() |
|
69 |
{ |
|
70 |
$query = [ |
|
71 |
'index' => env('ELASTICSEARCH_INDEX'), |
|
72 |
'body' => [ |
|
73 |
"size" => 0, |
|
74 |
"query" => [ |
|
75 |
'match_all' => [] |
|
76 |
], |
|
77 |
"aggs" => [ |
|
78 |
"geos" => [ |
|
79 |
"terms" => [ |
|
80 |
"size" => 0, |
|
81 |
"field" => "geonames_hierarchy" |
|
82 |
] |
|
83 |
] |
|
84 |
] |
|
85 |
] |
|
86 |
]; |
|
87 |
||
88 |
Es::shouldReceive('search') |
|
89 |
->once() |
|
90 |
->with($query) |
|
91 |
->andReturn(json_decode("{ |
|
92 |
\"took\" : 17, |
|
93 |
\"timed_out\" : false, |
|
94 |
\"_shards\" : { |
|
95 |
\"total\" : 1, |
|
96 |
\"successful\" : 1, |
|
97 |
\"failed\" : 0 |
|
98 |
}, |
|
99 |
\"hits\" : { |
|
100 |
\"total\" : 3011, |
|
101 |
\"max_score\" : 0.0, |
|
102 |
\"hits\" : [ ] |
|
103 |
}, |
|
104 |
\"aggregations\" : { |
|
105 |
\"geos\" : { |
|
106 |
\"doc_count_error_upper_bound\" : 0, |
|
107 |
\"sum_other_doc_count\" : 0, |
|
108 |
\"buckets\" : [] |
|
109 |
} |
|
110 |
} |
|
111 |
}", true)); |
|
112 |
||
113 |
$this->get('/api/v1/stats/geostats/?area='.config('corpusparole.geonames_earth_geonamesid'))->assertTrue($this->response->isOk(), $this->response->content()); |
|
114 |
} |
|
115 |
||
116 |
||
117 |
public function testGetIndexArea() |
|
118 |
{ |
|
387 | 119 |
|
320 | 120 |
$query = [ |
387 | 121 |
"index" => env('ELASTICSEARCH_INDEX'), |
122 |
"body" => [ |
|
320 | 123 |
"size" => 0, |
124 |
"query" => [ |
|
387 | 125 |
"constant_score" => [ |
126 |
"filter" => [ |
|
127 |
"bool" => [ |
|
128 |
"must" => [ [ |
|
129 |
"term" => [ "geonames_hierarchy" => "code_area" ] |
|
130 |
] ] |
|
131 |
] |
|
132 |
] |
|
320 | 133 |
] |
134 |
], |
|
135 |
"aggs" => [ |
|
136 |
"geos" => [ |
|
137 |
"terms" => [ |
|
138 |
"size" => 0, |
|
139 |
"field" => "geonames_hierarchy" |
|
140 |
] |
|
141 |
] |
|
142 |
] |
|
143 |
] |
|
144 |
]; |
|
145 |
||
146 |
Es::shouldReceive('search') |
|
147 |
->once() |
|
148 |
->with($query) |
|
149 |
->andReturn(json_decode("{ |
|
150 |
\"took\" : 17, |
|
151 |
\"timed_out\" : false, |
|
152 |
\"_shards\" : { |
|
153 |
\"total\" : 1, |
|
154 |
\"successful\" : 1, |
|
155 |
\"failed\" : 0 |
|
156 |
}, |
|
157 |
\"hits\" : { |
|
158 |
\"total\" : 3011, |
|
159 |
\"max_score\" : 0.0, |
|
160 |
\"hits\" : [ ] |
|
161 |
}, |
|
162 |
\"aggregations\" : { |
|
163 |
\"geos\" : { |
|
164 |
\"doc_count_error_upper_bound\" : 0, |
|
165 |
\"sum_other_doc_count\" : 0, |
|
166 |
\"buckets\" : [] |
|
167 |
} |
|
168 |
} |
|
169 |
}", true)); |
|
170 |
||
171 |
$this->get('/api/v1/stats/geostats/?area=code_area')->assertTrue($this->response->isOk(), $this->response->content()); |
|
172 |
} |
|
173 |
||
308
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
174 |
} |