diff --git a/src/Service/AlgoliaIndexer.php b/src/Service/AlgoliaIndexer.php index 641a778..d14d3cb 100644 --- a/src/Service/AlgoliaIndexer.php +++ b/src/Service/AlgoliaIndexer.php @@ -163,7 +163,17 @@ public function exportAttributesFromObject($item) ]; if ($item->hasMethod('AbsoluteLink')) { - $toIndex['objectLink'] = str_replace(['?stage=Stage', '?stage=Live'], '', $item->AbsoluteLink()); + $link = $item->AbsoluteLink(); + + if (!empty($link)) { + $toIndex['objectLink'] = str_replace(['?stage=Stage', '?stage=Live'], '', $link); + } + } elseif ($item->hasMethod('Link')) { + $link = $item->Link(); + + if (!empty($link)) { + $toIndex['objectLink'] = str_replace(['?stage=Stage', '?stage=Live'], '', $link); + } } if ($item && $item->hasMethod('exportObjectToAlgolia')) { @@ -282,7 +292,7 @@ public function exportAttributesFromRelationship($item, $relationship, $attribut try { $data = []; - $related = $item->{$relationship}(); + $related = $item->relObject($relationship); if (!$related || !$related->exists()) { return; diff --git a/src/Service/AlgoliaQuerier.php b/src/Service/AlgoliaQuerier.php index 54bc3c4..a473ae0 100644 --- a/src/Service/AlgoliaQuerier.php +++ b/src/Service/AlgoliaQuerier.php @@ -23,10 +23,11 @@ class AlgoliaQuerier * @param string $selectedIndex * @param string $query * @param array $searchParameters + * @param array $ORMFilters filter ORM objects prior to returning the results as a PaginatedList * * @return PaginatedList */ - public function fetchResults($selectedIndex = null, $query = '', $searchParameters = []) + public function fetchResults($selectedIndex = null, $query = '', $searchParameters = [], $ORMFilters = []) { $service = Injector::inst()->get(AlgoliaService::class); $results = false; @@ -78,6 +79,10 @@ function array_key_first(array $arr) $this->lastResult = $results; + if (!empty($ORMFilters)) { + $records = $records->filter($ORMFilters); + } + $output = PaginatedList::create($records); if ($results) {