-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
Feature: Aspect Search Result Limit #82
Conversation
This feature adds an aspect limiter to apply to each aspect before queries are executed.
Adding readme for aspect limiter
I think it's easier to understand we're limiting the results not the number of aspects itself.
Fixing readme
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Saw this PR while searching for this functionality today, thanks for putting in the work @WalrusSoup
I think there is a function name change you could apply so it's on the same formatting as the other files like
laravel-searchable/src/SearchResult.php
Line 28 in 93a5d19
public function setType(string $type): self |
@@ -23,4 +26,9 @@ public function getType(): string | |||
|
|||
return Str::plural($type); | |||
} | |||
|
|||
public function limit($limit) : void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function limit($limit) : void | |
public function setLimit($limit) : void |
I think it would be a good idea to use setLimit to keep consistency, see:
laravel-searchable/src/SearchResult.php
Line 28 in 93a5d19
public function setType(string $type): self |
public function limitAspectResults(int $limit) : self | ||
{ | ||
collect($this->getSearchAspects())->each(function(SearchAspect $aspect) use ($limit) { | ||
$aspect->limit($limit); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$aspect->limit($limit); | |
$aspect->setLimit($limit); |
Thanks! |
This PR makes it possible to add a limit to the number of results returned by each searchAspect by applying a limit on the query before execution. I'm introducing this to solve #56
Usage:
(->setAspectLimit(2)
yieldslimit 2
added to queries)