Skip to content

Commit

Permalink
Merge pull request #2 from education-nz/bug/add-support-for-snippet-r…
Browse files Browse the repository at this point in the history
…esults

Adding a custom sorting function, and adding Content to be indexed
  • Loading branch information
phillygogo authored May 10, 2024
2 parents 255c2c6 + ad38dcd commit 93e1cef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Service/AlgoliaIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public function exportAttributesFromObject($item)
{
$toIndex = [
'objectID' => $item->AlgoliaUUID,
'objectContent' => $item->Content,
'objectSilverstripeID' => $item->ID,
'objectIndexedTimestamp' => date('c'),
'objectTitle' => (string) $item->Title,
Expand Down
10 changes: 10 additions & 0 deletions src/Service/AlgoliaQuerier.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ function array_key_first(array $arr)
}
}

//Custom sorting results so Guide pages are always first.
//This will unset all results that aren't guide pages
//Then instantly re add to array which places them at the bottom.
foreach($records as $key => $wanted) {
if($wanted->ClassName != 'IntranetGuidePage') {
unset($records[$key]);
}
$records[$key] = $wanted;
}

$this->lastResult = $results;

$output = PaginatedList::create($records);
Expand Down

0 comments on commit 93e1cef

Please sign in to comment.