Skip to content

Commit

Permalink
Merge pull request #68 from heyday/main
Browse files Browse the repository at this point in the history
Added parameter to allow filtering using ORM filters
  • Loading branch information
wilr authored May 21, 2024
2 parents 8673f79 + d5dcd18 commit f5cbcbb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/Service/AlgoliaIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down Expand Up @@ -282,7 +292,7 @@ public function exportAttributesFromRelationship($item, $relationship, $attribut
try {
$data = [];

$related = $item->{$relationship}();
$related = $item->relObject($relationship);

if (!$related || !$related->exists()) {
return;
Expand Down
7 changes: 6 additions & 1 deletion src/Service/AlgoliaQuerier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit f5cbcbb

Please sign in to comment.