]> BookStack Code Mirror - bookstack/blobdiff - app/Entities/Tools/SearchIndex.php
Fixes for CodeStyle vol.2
[bookstack] / app / Entities / Tools / SearchIndex.php
index dd68a92fa8ff5767e753c016847872e2f8a9a814..cc0b32d6a00f1437ce2845b3f1e107aae663f39f 100644 (file)
@@ -1,8 +1,11 @@
-<?php namespace BookStack\Entities\Tools;
+<?php
+
+namespace BookStack\Entities\Tools;
 
 use BookStack\Entities\EntityProvider;
 use BookStack\Entities\Models\Entity;
 use BookStack\Entities\Models\SearchTerm;
+use Illuminate\Support\Collection;
 
 class SearchIndex
 {
@@ -16,14 +19,12 @@ class SearchIndex
      */
     protected $entityProvider;
 
-
     public function __construct(SearchTerm $searchTerm, EntityProvider $entityProvider)
     {
         $this->searchTerm = $searchTerm;
         $this->entityProvider = $entityProvider;
     }
 
-
     /**
      * Index the given entity.
      */
@@ -31,7 +32,7 @@ class SearchIndex
     {
         $this->deleteEntityTerms($entity);
         $nameTerms = $this->generateTermArrayFromText($entity->name, 5 * $entity->searchFactor);
-        $bodyTerms = $this->generateTermArrayFromText($entity->getText() ?? '', 1 * $entity->searchFactor);
+        $bodyTerms = $this->generateTermArrayFromText($entity->getText(), 1 * $entity->searchFactor);
         $terms = array_merge($nameTerms, $bodyTerms);
         foreach ($terms as $index => $term) {
             $terms[$index]['entity_type'] = $entity->getMorphClass();
@@ -41,7 +42,8 @@ class SearchIndex
     }
 
     /**
-     * Index multiple Entities at once
+     * Index multiple Entities at once.
+     *
      * @param Entity[] $entities
      */
     protected function indexEntities(array $entities)
@@ -75,8 +77,8 @@ class SearchIndex
             $entityModel->newQuery()
                 ->withTrashed()
                 ->select($selectFields)
-                ->chunk(1000, function ($entities) {
-                    $this->indexEntities($entities);
+                ->chunk(1000, function (Collection $entities) {
+                    $this->indexEntities($entities->all());
                 });
         }
     }
@@ -109,8 +111,8 @@ class SearchIndex
         $terms = [];
         foreach ($tokenMap as $token => $count) {
             $terms[] = [
-                'term' => $token,
-                'score' => $count * $scoreAdjustment
+                'term'  => $token,
+                'score' => $count * $scoreAdjustment,
             ];
         }