From 6f2a8205de4f82d9694e29b5ea4f677c4453ac5a Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Mon, 22 Apr 2024 10:41:38 +1200 Subject: [PATCH 1/4] adding support for snippeted results --- src/Service/AlgoliaQuerier.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Service/AlgoliaQuerier.php b/src/Service/AlgoliaQuerier.php index 54bc3c4..145a4a8 100644 --- a/src/Service/AlgoliaQuerier.php +++ b/src/Service/AlgoliaQuerier.php @@ -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 + 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) { From ad38dcdde72cb6ddd9b19fc2f86b1afdffd50073 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Fri, 10 May 2024 14:58:30 +1200 Subject: [PATCH 2/4] Adding a custom sorting function, and adding Content to be indexed --- src/Service/AlgoliaIndexer.php | 1 + src/Service/AlgoliaQuerier.php | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/Service/AlgoliaIndexer.php b/src/Service/AlgoliaIndexer.php index 641a778..b57cc84 100644 --- a/src/Service/AlgoliaIndexer.php +++ b/src/Service/AlgoliaIndexer.php @@ -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, diff --git a/src/Service/AlgoliaQuerier.php b/src/Service/AlgoliaQuerier.php index 145a4a8..b691763 100644 --- a/src/Service/AlgoliaQuerier.php +++ b/src/Service/AlgoliaQuerier.php @@ -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); From 068060ed11cff13a1f15cc50bbd1bb989fd7547f Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Tue, 14 May 2024 13:41:09 +1200 Subject: [PATCH 3/4] removing code and have reworked it into the intranet repo --- src/Service/AlgoliaQuerier.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/Service/AlgoliaQuerier.php b/src/Service/AlgoliaQuerier.php index b691763..145a4a8 100644 --- a/src/Service/AlgoliaQuerier.php +++ b/src/Service/AlgoliaQuerier.php @@ -90,16 +90,6 @@ 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); From 2b53a45b1682afad5400d8a1863fca1a40d3076c Mon Sep 17 00:00:00 2001 From: Phillip Rooney Date: Fri, 17 May 2024 08:46:55 +1200 Subject: [PATCH 4/4] removing bug which is overwriting my content --- src/Service/AlgoliaQuerier.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Service/AlgoliaQuerier.php b/src/Service/AlgoliaQuerier.php index 145a4a8..59c7e89 100644 --- a/src/Service/AlgoliaQuerier.php +++ b/src/Service/AlgoliaQuerier.php @@ -71,9 +71,6 @@ function array_key_first(array $arr) // 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 - 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"]; }