Last active
December 1, 2017 23:03
-
-
Save pedroborges/3a9ddb1a0a94a5e73d16fcd616f3dbc5 to your computer and use it in GitHub Desktop.
Besides finding non-exact matches in your content, Fuzzy Search for @getkirby offers some neat features like the ability to search through a custom page method. https://github.com/pedroborges/kirby-fuzzy-search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// site/controllers/blog.php | |
return function($site, $pages, $page) { | |
$query = esc(get('q')); | |
$articles = $page->children()->visible()->flip(); | |
if ($query) { | |
$articles = $articles->fuzzySearch($query, 'title|text|authorName'); | |
} | |
$perpage = $page->perpage()->int(); | |
$articles = $articles->paginate($perpage >= 1 ? $perpage : 5); | |
$pagination = $articles->pagination(); | |
return compact('articles', 'pagination', 'query'); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// site/plugins/methods.php | |
page::$methods['authorName'] = function($page) { | |
$author = $page->author()->value(); | |
if ($user = site()->user($author)) { | |
return $user->firstname().' '.$user->lastname(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment