https://github.com/arillo/silverstripe-simple-search
https://github.com/arillo/silverstripe-simple-search
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/arillo/silverstripe-simple-search
- Owner: arillo
- Created: 2020-05-15T14:05:39.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-03-01T12:09:55.000Z (over 4 years ago)
- Last Synced: 2025-02-18T12:07:17.334Z (over 1 year ago)
- Language: HTML
- Size: 33.2 KB
- Stars: 0
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# arillo/silverstripe-simple-search
Adds simple site search to your project.
### Requirements
SilverStripe CMS ^4.0
### Simple page example
```php
Title,
$this->obj('Content')
->setProcessShortcodes(true)
->RAW()
];
$string = implode($contents, ' ');
return $string ? SearchIndexEntry::sanitize_string($string) : null;
}
}
```
### (Re-)Build the search index
```
php vendor/silverstripe/framework/cli-script.php dev/tasks/Arillo-SimpleSearch-BuildIndexTask
```
### Integrate with Fluent
Add `search.yml` to your config:
```
Arillo\SimpleSearch\SearchIndexEntry:
extensions:
- TractorCow\Fluent\Extension\FluentExtension
translate:
- Title
- SearchableText
```
### Integrate with arillo/elements
Add the extension, so update / publish elements will trigger an reindex of the holder page.
```yaml
Arillo\Elements\ElementBase:
extensions:
- Arillo\SimpleSearch\ElementDataExtension
```
Implement `ISearchIndexable` e.g. like this:
```php
isPageWithSections()) {
$oldThemes = SSViewer::get_themes();
SSViewer::set_themes(
Config::inst()->get(SSViewer::class, 'themes')
);
try {
$string = SearchIndexEntry::sanitize_string(
$this->customise([
'RelationName' => self::SECTIONS
])->renderWith('Elements')
);
} finally {
SSViewer::set_themes($oldThemes);
}
return $string;
}
$contents = [
$this->Title,
$this->obj('Content')
->setProcessShortcodes(true)
->RAW()
];
$string = implode($contents, ' ');
return $string ? SearchIndexEntry::sanitize_string($string) : null;
}
public function isPageWithSections()
{
return isset(
ElementsExtension::page_element_relation_names($this)[
self::SECTIONS
]
);
}
}
```
### Content stripping
When using `SearchIndexEntry::sanitize_string` html tags will be removed from the text.
It is possible to mark certain parts of the html to also be removed. This can be handy if you want to strip out navigation elements or breadcrumbs. To accomplish this all content between `` and `` will be ereased:
```html
Contents between this comments will be stripped
```