author | ymh <ymh.work@gmail.com> |
Thu, 20 Oct 2016 17:27:36 +0200 | |
changeset 377 | 52169c718513 |
parent 126 | e87a340711a4 |
child 378 | 5b47eab083f3 |
permissions | -rw-r--r-- |
126
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
<?php |
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
2 |
|
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
3 |
namespace CorpusParole\Http\Controllers\Api; |
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
4 |
|
377
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
5 |
use Illuminate\Http\Request; |
126
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
6 |
use CorpusParole\Http\Controllers\Controller; |
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
7 |
|
377
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
8 |
use Es; |
126
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
9 |
|
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
10 |
class LanguageController extends Controller |
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
11 |
{ |
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
12 |
/** |
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
13 |
* Display the specified resource. |
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
14 |
* |
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
15 |
* @return \Illuminate\Http\Response |
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
16 |
*/ |
377
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
17 |
public function index(Request $request) |
126
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
18 |
{ |
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
19 |
|
377
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
20 |
$query = [ "match_all" => []]; |
126
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
21 |
|
377
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
22 |
$esQuery = [ |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
23 |
'index' => env('ELASTICSEARCH_INDEX'), |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
24 |
'body' => [ |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
25 |
"size" => 0, |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
26 |
"query" => $query, |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
27 |
"aggs" => [ |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
28 |
"languages" => [ |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
29 |
"terms" => [ "field" => "language", "order" => [ "_count" => "desc" ], "size" => 0 ] |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
30 |
] |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
31 |
] |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
32 |
] |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
33 |
]; |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
34 |
|
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
35 |
$esRes = Es::search($esQuery); |
126
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
36 |
|
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
37 |
$languages = []; |
377
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
38 |
|
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
39 |
foreach ($esRes['aggregations']['languages']['buckets'] as $b) { |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
40 |
$languages[$b['key']] = $b['doc_count']; |
126
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
41 |
} |
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
42 |
|
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
43 |
return response()->json(['languages' => $languages ]); |
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
44 |
|
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
45 |
} |
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
46 |
|
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
47 |
} |