Skip to content

Commit

Permalink
Merge branch 'release/2.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Aug 26, 2022
2 parents 00039e2 + 4f6730a commit 5e70f27
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# v2.3.0
## 08/26/2022

1. [](#new)
* Added new `onSimpleSearchCollection()` event to allow for custom integration into SimpleSearch.
* Require Grav 1.7+

# v2.2.2
## 05/25/2021

Expand Down
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,40 @@ You can tell Simplesearch to return a positive value when searching for characte
To do so, enable _Ignore accented characters_ in Admin, or manually set `ignore_accented_characters` to true in the plugin configuration.
The `en_US` locale must be installed on the server.

# Extending

As of version `2.3.0` SimpleSearch has a Grav even that allow for integrating into custom logic and adding your own 'pages' into the searchable collection. Because SimpleSearch utilizes Grav pages for its searching mechanism, your event needs to build fake 'pages' from your data, then you can add to the collection being passed to the event. Some example psudeo code should help you out:

```php
public function onSimpleSearchCollection(Event $event)
{
$collection = $event['collection'];
$locator = $this->grav['locator'];
$pages = $this->grav['pages'];

//find all my custom files
$finder = new Finder();
$data_location = $locator->findResource("user://data/custom-data");

foreach($finder->in($data_location)->name('*.json') as $file) {
$content = $file->getContents();
$data = json_decode($content, true);

$header['routes']['default'] = $data['url'],
$page = new Page();
$page->title($data['title']);
$page->content($data['content']);
$page->path($file->getPathname());
$page->header($header);

// Page needs to be added to Pages inorder to work in Collection
$pages->addPage($page);
// Add the fake page to the collection used to search
$collection->addPage($page);
}
}
```

# Updating

As development for SimpleSearch continues, new versions may become available that add additional features and functionality, improve compatibility with newer Grav releases, and generally provide a better user experience. Updating SimpleSearch is easy, and can be done through Grav's GPM system, as well as manually.
Expand Down
4 changes: 2 additions & 2 deletions blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: SimpleSearch
type: plugin
slug: simplesearch
version: 2.2.2
version: 2.3.0
description: "Don't be fooled, the **SimpleSearch** plugin provides a **fast** and highly **configurable** way to search your content."
icon: search
author:
Expand All @@ -15,7 +15,7 @@ bugs: https://github.com/getgrav/grav-plugin-simplesearch/issues
license: MIT

dependencies:
- { name: grav, version: '>=1.6.0' }
- { name: grav, version: '>=1.7.0' }

form:
validation: strict
Expand Down
3 changes: 3 additions & 0 deletions simplesearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ public function onPagesInitialized()
//Add modular pages again
$this->collection->merge($modularPageCollection);

//Allow for integration to SimpleSearch collection
$this->grav->fireEvent('onSimpleSearchCollection', new Event(['collection' => $this->collection]));

//Check if user has permission to view page
if ($this->grav['config']->get('plugins.login.enabled')) {
$this->collection = $this->checkForPermissions($this->collection);
Expand Down

0 comments on commit 5e70f27

Please sign in to comment.