-<?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
{
*/
protected $entityProvider;
-
public function __construct(SearchTerm $searchTerm, EntityProvider $entityProvider)
{
$this->searchTerm = $searchTerm;
$this->entityProvider = $entityProvider;
}
-
/**
* Index the given entity.
*/
{
$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();
}
/**
- * Index multiple Entities at once
+ * Index multiple Entities at once.
+ *
* @param Entity[] $entities
*/
protected function indexEntities(array $entities)
$entityModel->newQuery()
->withTrashed()
->select($selectFields)
- ->chunk(1000, function ($entities) {
- $this->indexEntities($entities);
+ ->chunk(1000, function (Collection $entities) {
+ $this->indexEntities($entities->all());
});
}
}
$terms = [];
foreach ($tokenMap as $token => $count) {
$terms[] = [
- 'term' => $token,
- 'score' => $count * $scoreAdjustment
+ 'term' => $token,
+ 'score' => $count * $scoreAdjustment,
];
}