39 $index = $request->input('index', 0); |
39 $index = $request->input('index', 0); |
40 $limit = $request->input('limit', config('corpusparole.theme_default_limit')); |
40 $limit = $request->input('limit', config('corpusparole.theme_default_limit')); |
41 $sort = $request->input('sort', 'count'); |
41 $sort = $request->input('sort', 'count'); |
42 |
42 |
43 if($filter === 'bnf') { |
43 if($filter === 'bnf') { |
44 $include = ".*\|bnf\|.*"; |
44 $include = ".*\\|bnf\\|.*"; |
45 } |
45 } |
46 elseif($filter === 'lexvo') { |
46 elseif($filter === 'lexvo') { |
47 $include = ".*\|lxv\|.*"; |
47 $include = ".*\\|lxv\\|.*"; |
|
48 } |
|
49 elseif($filter === 'olac') { |
|
50 $include = ".*\\|olac\\|.*"; |
|
51 } |
|
52 elseif($filter === 'txt') { |
|
53 $include = ".*\\|txt\\|.*"; |
48 } |
54 } |
49 elseif($filter === 'all') { |
55 elseif($filter === 'all') { |
50 $include = false; |
56 $include = false; |
51 } |
57 } |
52 else { |
58 else { |
53 abort(401,"Value for filter parameter must be in 'bnf', 'lexvo', 'all'"); |
59 abort(401,"Value for filter parameter must be in 'bnf', 'lexvo', 'olac', 'txt', 'all'"); |
54 } |
60 } |
55 |
61 |
56 if($sort == "count" || $sort == "descending") { |
62 if($sort == "count" || $sort == "descending") { |
57 $order_field = "_count"; |
63 $order_field = "_count"; |
58 $order_dir = "desc"; |
64 $order_dir = "desc"; |
97 |
103 |
98 $esRes = Es::search($query); |
104 $esRes = Es::search($query); |
99 |
105 |
100 $themes = []; |
106 $themes = []; |
101 |
107 |
102 $bucketList = array_slice($esRes['aggregations']['subjects']['subjects']['buckets'], $index*$limit, $limit); |
108 $bucketList = $esRes['aggregations']['subjects']['subjects']['buckets']; |
|
109 if($limit > 0) { |
|
110 $bucketList = array_slice($bucketList, $index*$limit, $limit); |
|
111 } |
103 |
112 |
104 foreach($bucketList as $bucket) { |
113 foreach($bucketList as $bucket) { |
105 $parts = explode("|", $bucket['key']); |
114 $parts = explode("|", $bucket['key']); |
106 $label = $parts[0]; |
115 $label = $parts[0]; |
107 $url = ['bnf' => config('corpusparole.bnf_ark_base_url'), 'lxv' => config('corpusparole.lexvo_base_url')][$parts[1]].$parts[2]; |
116 if($parts[1] === 'bnf' || $parts[1] === 'lxv') { |
|
117 $url = ['bnf' => config('corpusparole.bnf_ark_base_url'), 'lxv' => config('corpusparole.lexvo_base_url')][$parts[1]].$parts[2]; |
|
118 } |
|
119 else { |
|
120 $url = $parts[2]; |
|
121 } |
108 $themes[$url] = [ |
122 $themes[$url] = [ |
109 "label" => $label, |
123 "label" => $label, |
110 "count" => $bucket['doc_count'] |
124 "count" => $bucket['doc_count'] |
111 ]; |
125 ]; |
112 } |
126 } |