Completed
Push — master ( 5fab5d...33debe )
by Dan Michael O.
03:28
created
app/Search/DocumentsIndex.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
     public function sanitizeForQuery($value)
96 96
     {
97 97
         $chars = preg_quote('\\+-&|!(){}[]^~*?:');
98
-        $value = preg_replace('/([' . $chars . '])/', '\\\\\1', $value);
98
+        $value = preg_replace('/(['.$chars.'])/', '\\\\\1', $value);
99 99
 
100 100
         return $value;
101 101
         //
@@ -127,20 +127,20 @@  discard block
 block discarded – undo
127 127
         }
128 128
         if ($request->has('collection')) {
129 129
             $col = Collection::findOrFail($request->collection);
130
-            $query[] = 'collections:"' . $this->sanitizeForQuery($col->name) . '"';
130
+            $query[] = 'collections:"'.$this->sanitizeForQuery($col->name).'"';
131 131
         }
132 132
         if ($request->has('subject')) {
133
-            $query[] = '(subjects.noubomn.prefLabel:"' . $this->sanitizeForQuery($request->subject) . '"' .
134
-                    ' OR subjects.bare.prefLabel:"' . $this->sanitizeForQuery($request->subject) . '"' .
135
-                    ' OR genres.noubomn.prefLabel:"' . $this->sanitizeForQuery($request->subject) . '")';
133
+            $query[] = '(subjects.noubomn.prefLabel:"'.$this->sanitizeForQuery($request->subject).'"'.
134
+                    ' OR subjects.bare.prefLabel:"'.$this->sanitizeForQuery($request->subject).'"'.
135
+                    ' OR genres.noubomn.prefLabel:"'.$this->sanitizeForQuery($request->subject).'")';
136 136
                 // TODO: Vi bør vel antakelig skille mellom X som emne og X som form/sjanger ?
137 137
                 //       Men da må frontend si fra hva den ønsker, noe den ikke gjør enda.
138 138
         }
139 139
         if ($request->has('language')) {
140
-            $query[] = 'language:"' . $this->sanitizeForQuery($request->language) . '"' ;
140
+            $query[] = 'language:"'.$this->sanitizeForQuery($request->language).'"';
141 141
         }
142 142
         if ($request->has('genre')) {
143
-            $query[] = 'genres.noubomn.prefLabel:"' . $this->sanitizeForQuery($request->genre) . '"';
143
+            $query[] = 'genres.noubomn.prefLabel:"'.$this->sanitizeForQuery($request->genre).'"';
144 144
         }
145 145
         if ($request->has('real')) {
146 146
             dd('`real` is (very) deprecated, please use `subject` instead.');
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
     public function getUsageCount($id, $type)
179 179
     {
180 180
         $this->getFullType($type);
181
-        $arg = $type . '.' . $id;
181
+        $arg = $type.'.'.$id;
182 182
         if (is_null(array_get($this->usage, $arg))) {
183 183
             $this->addToUsageCache($id, $type);
184 184
         }
@@ -207,11 +207,11 @@  discard block
 block discarded – undo
207 207
             ->get();
208 208
 
209 209
         foreach ($entity_ids as $sid) {
210
-            array_set($this->usage, $type . '.' . $sid, 0);
210
+            array_set($this->usage, $type.'.'.$sid, 0);
211 211
         }
212 212
 
213 213
         foreach ($res as $row) {
214
-            array_set($this->usage, $type . '.' . $row->entity_id, intval($row->doc_count));
214
+            array_set($this->usage, $type.'.'.$row->entity_id, intval($row->doc_count));
215 215
         }
216 216
     }
217 217
 
@@ -221,10 +221,10 @@  discard block
 block discarded – undo
221 221
         $query = \DB::table('entities')
222 222
                     ->select(['entity_id', 'entity_type', \DB::raw('count(document_id) as doc_count')])
223 223
                     ->groupBy('entity_id', 'entity_type');
224
-        $query->chunk(5000, function ($rows) use ($typemap) {
224
+        $query->chunk(5000, function($rows) use ($typemap) {
225 225
             foreach ($rows as $row) {
226 226
                 $type = $typemap[$row->entity_type];
227
-                array_set($this->usage, $type . '.' . $row->entity_id, intval($row->doc_count));
227
+                array_set($this->usage, $type.'.'.$row->entity_id, intval($row->doc_count));
228 228
             }
229 229
         });
230 230
     }
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
     {
242 242
         $payload = $this->basePayload();
243 243
         if (!is_null($indexVersion)) {
244
-            $payload['index'] = $this->esIndex . '_v' . $indexVersion;
244
+            $payload['index'] = $this->esIndex.'_v'.$indexVersion;
245 245
         }
246 246
         $payload['id'] = $doc->id;
247 247
 
@@ -251,8 +251,8 @@  discard block
 block discarded – undo
251 251
         try {
252 252
             $this->client->index($payload);
253 253
         } catch (BadRequest400Exception $e) {
254
-            \Log::error('ElasticSearch returned error: ' . $e->getMessage() . '. Our request: ' . var_export($payload, true));
255
-            throw new \ErrorException('ElasticSearch failed to index the document ' . $doc->id . '. Please see the log for payload and full error response. Error message: ' . $e->getMessage());
254
+            \Log::error('ElasticSearch returned error: '.$e->getMessage().'. Our request: '.var_export($payload, true));
255
+            throw new \ErrorException('ElasticSearch failed to index the document '.$doc->id.'. Please see the log for payload and full error response. Error message: '.$e->getMessage());
256 256
         }
257 257
     }
258 258
 
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
         if (is_null($version)) {
274 274
             $version = $this->getCurrentVersion() + 1;
275 275
         }
276
-        $indexParams = ['index' => $this->esIndex . '_v' . $version];
276
+        $indexParams = ['index' => $this->esIndex.'_v'.$version];
277 277
         $indexParams['body']['settings']['analysis']['char_filter']['isbn_filter'] = [
278 278
             'type'        => 'pattern_replace',
279 279
             'pattern'     => '-',
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
     {
316 316
         try {
317 317
             $this->client->indices()->delete([
318
-                'index' => $this->esIndex . '_v' . $version,
318
+                'index' => $this->esIndex.'_v'.$version,
319 319
             ]);
320 320
         } catch (Missing404Exception $e) {
321 321
             # Didn't exist in the beginning, that's ok.
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
     public function addAction(&$actions, $action, $version)
326 326
     {
327 327
         if ($version) {
328
-            $actions[] = [$action => ['index' => $this->esIndex . '_v' . $version, 'alias' => $this->esIndex]];
328
+            $actions[] = [$action => ['index' => $this->esIndex.'_v'.$version, 'alias' => $this->esIndex]];
329 329
         }
330 330
     }
331 331
 
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
 
343 343
     public function versionExists($version)
344 344
     {
345
-        return $this->client->indices()->exists(['index' => $this->esIndex . '_v' . $version]);
345
+        return $this->client->indices()->exists(['index' => $this->esIndex.'_v'.$version]);
346 346
     }
347 347
 
348 348
     public function getCurrentVersion()
Please login to merge, or discard this patch.