author | ymh <ymh.work@gmail.com> |
Mon, 12 Jun 2017 14:53:59 +0200 | |
changeset 537 | d2e6ee099125 |
parent 465 | 9df336529b2f |
permissions | -rw-r--r-- |
160 | 1 |
<?php |
2 |
||
3 |
namespace CorpusParole\Http\Controllers\Api; |
|
4 |
||
5 |
use CorpusParole\Http\Controllers\Controller; |
|
378
5b47eab083f3
implement filters on stats controller, put all filter logic in CorpusFilterManager
ymh <ymh.work@gmail.com>
parents:
377
diff
changeset
|
6 |
use CorpusParole\Libraries\Filters\CorpusFilterManager; |
160 | 7 |
|
8 |
use Illuminate\Http\Request; |
|
9 |
||
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
|
10 |
use Es; |
160 | 11 |
|
12 |
class DiscourseController extends Controller |
|
13 |
{ |
|
14 |
||
15 |
/** |
|
16 |
* Display the specified resource. |
|
17 |
* |
|
18 |
* @return \Illuminate\Http\Response |
|
19 |
*/ |
|
20 |
public function index(Request $request) |
|
21 |
{ |
|
22 |
||
378
5b47eab083f3
implement filters on stats controller, put all filter logic in CorpusFilterManager
ymh <ymh.work@gmail.com>
parents:
377
diff
changeset
|
23 |
$filterManager = new CorpusFilterManager(); |
5b47eab083f3
implement filters on stats controller, put all filter logic in CorpusFilterManager
ymh <ymh.work@gmail.com>
parents:
377
diff
changeset
|
24 |
$filters = $filterManager->prepareFilters($request); |
465
9df336529b2f
make filter and theme visualisatiion change on filter modification
ymh <ymh.work@gmail.com>
parents:
407
diff
changeset
|
25 |
//unset($filters['discourses']); |
378
5b47eab083f3
implement filters on stats controller, put all filter logic in CorpusFilterManager
ymh <ymh.work@gmail.com>
parents:
377
diff
changeset
|
26 |
$qFilterParts = $filterManager->buildESFilters($filters); |
5b47eab083f3
implement filters on stats controller, put all filter logic in CorpusFilterManager
ymh <ymh.work@gmail.com>
parents:
377
diff
changeset
|
27 |
|
5b47eab083f3
implement filters on stats controller, put all filter logic in CorpusFilterManager
ymh <ymh.work@gmail.com>
parents:
377
diff
changeset
|
28 |
$query = $filterManager->buildQuery($qFilterParts); |
5b47eab083f3
implement filters on stats controller, put all filter logic in CorpusFilterManager
ymh <ymh.work@gmail.com>
parents:
377
diff
changeset
|
29 |
|
5b47eab083f3
implement filters on stats controller, put all filter logic in CorpusFilterManager
ymh <ymh.work@gmail.com>
parents:
377
diff
changeset
|
30 |
|
160 | 31 |
|
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
|
32 |
$esQuery = [ |
406
cf0f23803a53
upgrade elasticsearch to 5.0, upgrade ember
ymh <ymh.work@gmail.com>
parents:
378
diff
changeset
|
33 |
'index' => config('elasticsearch.index'), |
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
|
34 |
'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
|
35 |
"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
|
36 |
"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
|
37 |
"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
|
38 |
"discourses" => [ |
407
2dba812c7ef2
add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents:
406
diff
changeset
|
39 |
"terms" => [ "field" => "discourse_types", "order" => [ "_count" => "desc" ], "size" => 2147483647 ] |
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
|
40 |
] |
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 |
] |
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 |
] |
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 |
]; |
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
|
44 |
|
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
|
45 |
$esRes = Es::search($esQuery); |
160 | 46 |
|
47 |
$discourses = []; |
|
48 |
||
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
|
49 |
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
|
50 |
$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
|
51 |
$count = $b['doc_count']; |
160 | 52 |
$label = config('corpusparole.corpus_discourse_type')[$key]; |
53 |
$discourses[$key] = [ |
|
54 |
"label" => $label, |
|
55 |
"count" => $count |
|
56 |
]; |
|
57 |
} |
|
58 |
||
59 |
return response()->json(['discourses' => $discourses ]); |
|
60 |
||
61 |
} |
|
62 |
||
63 |
} |