Skip to content

Commit

Permalink
Add siteMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
bvdputte committed Feb 4, 2023
1 parent bd2f352 commit 3564c76
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"description": "A search plugin for Kirby 3 that searches for full word combinations rather than just individual words.",
"license": "MIT",
"type": "kirby-plugin",
"version": "2.0.0",
"authors": [
{
"name": "Bart Vandeputte",
"email": "[email protected]"
"email": "[email protected]"
}
],
"keywords": [
Expand Down
7 changes: 6 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
Kirby::plugin('bvdputte/kirby-bettersearch', [
'pagesMethods' => [
'bettersearch' => function ($query, $params = array()) {
return search($this, $query, $params);
return bettersearch(kirby(), $this, $query, $params);
}
],
'siteMethods' => [
'bettersearch' => function ($query, $params = array()) {
return bettersearch(kirby(), site()->index(), $query, $params);
}
]
]);
8 changes: 7 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ A search plugin for Kirby 3 that searches for full word combinations rather than

## Usage

Instead of the default `$pages` [search method](https://getkirby.com/docs/reference/objects/pages/search), use `$pages->bettersearch($string, $options)` instead.
Instead of the default `$pages` [search method](https://getkirby.com/docs/reference/objects/pages/search), use `$pages->bettersearch($querystring, $options)` or `$site->bettersearch($querystring, $options)` instead.

Since we're looking for _full query matches_, following options have been removed:

- stopwords
- minlength
- words

## Disclaimer

Expand Down
2 changes: 1 addition & 1 deletion src/bettersearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Fork of the native search() component
* Only searches for full matches
*/
function search(Kirby\Cms\App $kirby, Kirby\Cms\Collection $collection, string $query = null, $params = []) {
function bettersearch(Kirby\Cms\App $kirby, Kirby\Cms\Collection $collection, string $query = null, $params = []) {
// empty search query
if (empty(trim($query ?? '')) === true) {
return $collection->limit(0);
Expand Down

0 comments on commit 3564c76

Please sign in to comment.