Skip to content

Commit

Permalink
Add sortRaw methos
Browse files Browse the repository at this point in the history
  • Loading branch information
alecritson committed Dec 17, 2024
1 parent fea04ae commit 785118f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/Engines/AbstractEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ abstract class AbstractEngine

protected string $sort = '';

protected string $sortRaw = '';


public function extendQuery(\Closure $callable): self
{
$this->queryExtenders[] = $callable;
Expand Down Expand Up @@ -96,6 +99,13 @@ public function sort(string $sort): self
return $this;
}

public function sortRaw(string $sort): self
{
$this->sortRaw = $sort;

return $this;
}

public function query(string $query): AbstractEngine
{
$this->query = $query;
Expand Down
4 changes: 2 additions & 2 deletions src/Engines/TypesenseEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function get(): SearchResults
$response = $engine->getMultiSearch()->perform($request, [
'collection' => (new $this->modelType)->searchableAs(),
]);

$completeResults = $response['results'][0];

unset( $response['results'][0]);
Expand Down Expand Up @@ -191,7 +191,7 @@ protected function buildSearch(array $options): array
'facet_query' => $facetQuery,
'prefix' => false,
'max_facet_values' => 50,
'sort_by' => $this->sortByIsValid() ? $this->sort : '_text_match:desc',
'sort_by' => $this->sortRaw ?: ($this->sortByIsValid() ? $this->sort : '_text_match:desc'),
'facet_by' => implode(',', $searchQuery->facets),
];

Expand Down

0 comments on commit 785118f

Please sign in to comment.