author | ymh <ymh.work@gmail.com> |
Thu, 20 Oct 2016 17:27:36 +0200 | |
changeset 377 | 52169c718513 |
parent 307 | 07b44a378ad8 |
child 378 | 5b47eab083f3 |
permissions | -rw-r--r-- |
160 | 1 |
<?php |
2 |
||
3 |
namespace CorpusParole\Http\Controllers\Api; |
|
4 |
||
5 |
use CorpusParole\Http\Controllers\Controller; |
|
6 |
||
7 |
use Illuminate\Http\Request; |
|
8 |
||
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:
307
diff
changeset
|
9 |
use Es; |
160 | 10 |
|
11 |
class DiscourseController extends Controller |
|
12 |
{ |
|
13 |
||
14 |
/** |
|
15 |
* Display the specified resource. |
|
16 |
* |
|
17 |
* @return \Illuminate\Http\Response |
|
18 |
*/ |
|
19 |
public function index(Request $request) |
|
20 |
{ |
|
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:
307
diff
changeset
|
22 |
$query = [ "match_all" => []]; |
160 | 23 |
|
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:
307
diff
changeset
|
24 |
$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:
307
diff
changeset
|
25 |
'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:
307
diff
changeset
|
26 |
'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:
307
diff
changeset
|
27 |
"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:
307
diff
changeset
|
28 |
"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:
307
diff
changeset
|
29 |
"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:
307
diff
changeset
|
30 |
"discourses" => [ |
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:
307
diff
changeset
|
31 |
"terms" => [ "field" => "discourse_types", "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:
307
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:
307
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:
307
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:
307
diff
changeset
|
35 |
]; |
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:
307
diff
changeset
|
36 |
|
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:
307
diff
changeset
|
37 |
$esRes = Es::search($esQuery); |
160 | 38 |
|
39 |
$discourses = []; |
|
40 |
||
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:
307
diff
changeset
|
41 |
foreach ($esRes['aggregations']['discourses']['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:
307
diff
changeset
|
42 |
$key = $b['key']; |
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:
307
diff
changeset
|
43 |
$count = $b['doc_count']; |
160 | 44 |
$label = config('corpusparole.corpus_discourse_type')[$key]; |
45 |
$discourses[$key] = [ |
|
46 |
"label" => $label, |
|
47 |
"count" => $count |
|
48 |
]; |
|
49 |
} |
|
50 |
||
51 |
return response()->json(['discourses' => $discourses ]); |
|
52 |
||
53 |
} |
|
54 |
||
55 |
} |