Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft #67

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
24 changes: 24 additions & 0 deletions src/Service/AlgoliaQuerier.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ function array_key_first(array $arr)
$record = $className::get()->byId($id);

if ($record && $record->canView()) {
// Snippet results are cofigured in Algolia to be returned.
// Since the following result is actually fetched from the DB
// I need to concatenate the aogolias snippeted result to the $hit to be returned

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spelling mistake "algolia"

if(isset($hit["_snippetResult"]) && isset($hit["_snippetResult"]['Content'])) {
$record->snippetResult = $hit["_snippetResult"]['Content']["value"];
}
if(isset($hit["_snippetResult"]) && isset($hit["_snippetResult"]['objectContent'])) {
$record->snippetResult = $hit["_snippetResult"]['objectContent']["value"];
}

if(isset($hit["objectLink"])) {
$record->AlgoliaLink = $hit["objectLink"];
}

$records->push($record);
}
} catch (Throwable $e) {
Expand All @@ -76,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') {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phillygogo Definitely should not be done in here :) Sorting can be set in Algolia directly.

unset($records[$key]);
}
$records[$key] = $wanted;
}

$this->lastResult = $results;

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