Applied StyleCI changes
This commit is contained in:
parent
63d8d72d7e
commit
2633b94deb
|
@ -175,7 +175,7 @@ class SearchIndex
|
||||||
$names = [];
|
$names = [];
|
||||||
$values = [];
|
$values = [];
|
||||||
|
|
||||||
foreach($tags as $tag) {
|
foreach ($tags as $tag) {
|
||||||
$names[] = $tag->name;
|
$names[] = $tag->name;
|
||||||
$values[] = $tag->value;
|
$values[] = $tag->value;
|
||||||
}
|
}
|
||||||
|
@ -233,17 +233,16 @@ class SearchIndex
|
||||||
$entityType = $entity->getMorphClass();
|
$entityType = $entity->getMorphClass();
|
||||||
foreach ($mergedScoreMap as $term => $score) {
|
foreach ($mergedScoreMap as $term => $score) {
|
||||||
$dataArray[] = [
|
$dataArray[] = [
|
||||||
'term' => $term,
|
'term' => $term,
|
||||||
'score' => $score,
|
'score' => $score,
|
||||||
'entity_type' => $entityType,
|
'entity_type' => $entityType,
|
||||||
'entity_id' => $entityId,
|
'entity_id' => $entityId,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $dataArray;
|
return $dataArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For the given term data arrays, Merge their contents by term
|
* For the given term data arrays, Merge their contents by term
|
||||||
* while combining any scores.
|
* while combining any scores.
|
||||||
|
|
|
@ -124,7 +124,6 @@ class SearchOptions
|
||||||
return $terms;
|
return $terms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse a standard search term string into individual search terms and
|
* Parse a standard search term string into individual search terms and
|
||||||
* extract any exact terms searches to be made.
|
* extract any exact terms searches to be made.
|
||||||
|
@ -136,7 +135,7 @@ class SearchOptions
|
||||||
$terms = explode(' ', $termString);
|
$terms = explode(' ', $termString);
|
||||||
$indexDelimiters = SearchIndex::$delimiters;
|
$indexDelimiters = SearchIndex::$delimiters;
|
||||||
$parsed = [
|
$parsed = [
|
||||||
'terms' => [],
|
'terms' => [],
|
||||||
'exacts' => [],
|
'exacts' => [],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,10 @@ use Illuminate\Support\HtmlString;
|
||||||
|
|
||||||
class SearchResultsFormatter
|
class SearchResultsFormatter
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For the given array of entities, Prepare the models to be shown in search result
|
* For the given array of entities, Prepare the models to be shown in search result
|
||||||
* output. This sets a series of additional attributes.
|
* output. This sets a series of additional attributes.
|
||||||
|
*
|
||||||
* @param Entity[] $results
|
* @param Entity[] $results
|
||||||
*/
|
*/
|
||||||
public function format(array $results, SearchOptions $options): void
|
public function format(array $results, SearchOptions $options): void
|
||||||
|
@ -32,7 +32,7 @@ class SearchResultsFormatter
|
||||||
$terms = array_merge($options->exacts, $options->searches);
|
$terms = array_merge($options->exacts, $options->searches);
|
||||||
|
|
||||||
$originalContentByNewAttribute = [
|
$originalContentByNewAttribute = [
|
||||||
'preview_name' => $entity->name,
|
'preview_name' => $entity->name,
|
||||||
'preview_content' => $textContent,
|
'preview_content' => $textContent,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -49,7 +49,8 @@ class SearchResultsFormatter
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Highlight tags which match the given terms.
|
* Highlight tags which match the given terms.
|
||||||
* @param Tag[] $tags
|
*
|
||||||
|
* @param Tag[] $tags
|
||||||
* @param string[] $terms
|
* @param string[] $terms
|
||||||
*/
|
*/
|
||||||
protected function highlightTagsContainingTerms(array $tags, array $terms): void
|
protected function highlightTagsContainingTerms(array $tags, array $terms): void
|
||||||
|
@ -104,6 +105,7 @@ class SearchResultsFormatter
|
||||||
* adjacent or where they overlap.
|
* adjacent or where they overlap.
|
||||||
*
|
*
|
||||||
* @param array<int, int> $matchPositions
|
* @param array<int, int> $matchPositions
|
||||||
|
*
|
||||||
* @return array<int, int>
|
* @return array<int, int>
|
||||||
*/
|
*/
|
||||||
protected function sortAndMergeMatchPositions(array $matchPositions): array
|
protected function sortAndMergeMatchPositions(array $matchPositions): array
|
||||||
|
@ -118,7 +120,7 @@ class SearchResultsFormatter
|
||||||
$mergedRefs[$start] = $end;
|
$mergedRefs[$start] = $end;
|
||||||
$lastStart = $start;
|
$lastStart = $start;
|
||||||
$lastEnd = $end;
|
$lastEnd = $end;
|
||||||
} else if ($end > $lastEnd) {
|
} elseif ($end > $lastEnd) {
|
||||||
$mergedRefs[$lastStart] = $end;
|
$mergedRefs[$lastStart] = $end;
|
||||||
$lastEnd = $end;
|
$lastEnd = $end;
|
||||||
}
|
}
|
||||||
|
@ -194,7 +196,7 @@ class SearchResultsFormatter
|
||||||
$firstStart = $firstStart ?: 0;
|
$firstStart = $firstStart ?: 0;
|
||||||
if ($remainder > 10 && $firstStart !== 0) {
|
if ($remainder > 10 && $firstStart !== 0) {
|
||||||
$padStart = max(0, $firstStart - $remainder);
|
$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
|
// Add ellipsis if we're not at the end
|
||||||
|
@ -204,5 +206,4 @@ class SearchResultsFormatter
|
||||||
|
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -141,13 +141,13 @@ class SearchRunner
|
||||||
$relations = ['tags'];
|
$relations = ['tags'];
|
||||||
|
|
||||||
if ($entityModelInstance instanceof BookChild) {
|
if ($entityModelInstance instanceof BookChild) {
|
||||||
$relations['book'] = function(BelongsTo $query) {
|
$relations['book'] = function (BelongsTo $query) {
|
||||||
$query->visible();
|
$query->visible();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($entityModelInstance instanceof Page) {
|
if ($entityModelInstance instanceof Page) {
|
||||||
$relations['chapter'] = function(BelongsTo $query) {
|
$relations['chapter'] = function (BelongsTo $query) {
|
||||||
$query->visible();
|
$query->visible();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -310,7 +310,7 @@ class SearchRunner
|
||||||
if (empty($termCounts)) {
|
if (empty($termCounts)) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$multipliers = [];
|
$multipliers = [];
|
||||||
$max = max(array_values($termCounts));
|
$max = max(array_values($termCounts));
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,8 @@ class SearchController extends Controller
|
||||||
protected $searchRunner;
|
protected $searchRunner;
|
||||||
protected $entityContextManager;
|
protected $entityContextManager;
|
||||||
|
|
||||||
public function __construct(SearchRunner $searchRunner) {
|
public function __construct(SearchRunner $searchRunner)
|
||||||
|
{
|
||||||
$this->searchRunner = $searchRunner;
|
$this->searchRunner = $searchRunner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ use BookStack\Entities\Models\Book;
|
||||||
use BookStack\Entities\Models\Bookshelf;
|
use BookStack\Entities\Models\Bookshelf;
|
||||||
use BookStack\Entities\Models\Chapter;
|
use BookStack\Entities\Models\Chapter;
|
||||||
use BookStack\Entities\Models\Page;
|
use BookStack\Entities\Models\Page;
|
||||||
use BookStack\Entities\Models\SearchTerm;
|
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class EntitySearchTest extends TestCase
|
class EntitySearchTest extends TestCase
|
||||||
|
@ -410,5 +409,4 @@ class EntitySearchTest extends TestCase
|
||||||
$search->assertSee('My <cool> <strong>TestPageContent</strong>', false);
|
$search->assertSee('My <cool> <strong>TestPageContent</strong>', false);
|
||||||
$search->assertSee('My supercool <great> <strong>TestPageContent</strong> page', false);
|
$search->assertSee('My supercool <great> <strong>TestPageContent</strong> page', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue