Skip to content
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

Merged
merged 4 commits into from
Dec 9, 2020
Merged

Feature: Aspect Search Result Limit #82

merged 4 commits into from
Dec 9, 2020

Conversation

WalrusSoup
Copy link
Contributor

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:

$searchResults = (new Search())
    ->registerAspect(BlogPostAspect::class)
    ->limitAspectResults(50)
    ->search('How To');
  • Tests Added
  • Readme Updated
  • Manually verified database executes query as expected (->setAspectLimit(2) yields limit 2 added to queries)

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
@freekmurze freekmurze mentioned this pull request Oct 4, 2020
Copy link

@marcorivm marcorivm left a 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

public function setType(string $type): self

@@ -23,4 +26,9 @@ public function getType(): string

return Str::plural($type);
}

public function limit($limit) : void

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:

public function setType(string $type): self

public function limitAspectResults(int $limit) : self
{
collect($this->getSearchAspects())->each(function(SearchAspect $aspect) use ($limit) {
$aspect->limit($limit);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$aspect->limit($limit);
$aspect->setLimit($limit);

@freekmurze freekmurze merged commit 3256bf8 into spatie:master Dec 9, 2020
@freekmurze
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants