$names = [];
$values = [];
- foreach($tags as $tag) {
+ foreach ($tags as $tag) {
$names[] = $tag->name;
$values[] = $tag->value;
}
$entityType = $entity->getMorphClass();
foreach ($mergedScoreMap as $term => $score) {
$dataArray[] = [
- 'term' => $term,
- 'score' => $score,
+ 'term' => $term,
+ 'score' => $score,
'entity_type' => $entityType,
- 'entity_id' => $entityId,
+ 'entity_id' => $entityId,
];
}
return $dataArray;
}
-
/**
* For the given term data arrays, Merge their contents by term
* while combining any scores.
class SearchResultsFormatter
{
-
/**
* For the given array of entities, Prepare the models to be shown in search result
* output. This sets a series of additional attributes.
+ *
* @param Entity[] $results
*/
public function format(array $results, SearchOptions $options): void
$terms = array_merge($options->exacts, $options->searches);
$originalContentByNewAttribute = [
- 'preview_name' => $entity->name,
+ 'preview_name' => $entity->name,
'preview_content' => $textContent,
];
/**
* Highlight tags which match the given terms.
- * @param Tag[] $tags
+ *
+ * @param Tag[] $tags
* @param string[] $terms
*/
protected function highlightTagsContainingTerms(array $tags, array $terms): void
* adjacent or where they overlap.
*
* @param array<int, int> $matchPositions
+ *
* @return array<int, int>
*/
protected function sortAndMergeMatchPositions(array $matchPositions): array
$mergedRefs[$start] = $end;
$lastStart = $start;
$lastEnd = $end;
- } else if ($end > $lastEnd) {
+ } elseif ($end > $lastEnd) {
$mergedRefs[$lastStart] = $end;
$lastEnd = $end;
}
$firstStart = $firstStart ?: 0;
if ($remainder > 10 && $firstStart !== 0) {
$padStart = max(0, $firstStart - $remainder);
- $content = ($padStart === 0 ? '' : '...') . e(substr($originalText, $padStart, $firstStart - $padStart)) . substr($content, 4);
+ $content = ($padStart === 0 ? '' : '...') . e(substr($originalText, $padStart, $firstStart - $padStart)) . substr($content, 4);
}
// Add ellipsis if we're not at the end
return $content;
}
-
-}
\ No newline at end of file
+}
$relations = ['tags'];
if ($entityModelInstance instanceof BookChild) {
- $relations['book'] = function(BelongsTo $query) {
+ $relations['book'] = function (BelongsTo $query) {
$query->visible();
};
}
if ($entityModelInstance instanceof Page) {
- $relations['chapter'] = function(BelongsTo $query) {
+ $relations['chapter'] = function (BelongsTo $query) {
$query->visible();
};
}
if (empty($termCounts)) {
return [];
}
-
+
$multipliers = [];
$max = max(array_values($termCounts));
use BookStack\Entities\Models\Bookshelf;
use BookStack\Entities\Models\Chapter;
use BookStack\Entities\Models\Page;
-use BookStack\Entities\Models\SearchTerm;
use Tests\TestCase;
class EntitySearchTest extends TestCase
$search->assertSee('My <cool> <strong>TestPageContent</strong>', false);
$search->assertSee('My supercool <great> <strong>TestPageContent</strong> page', false);
}
-
}