<commit_before># [extensible-search](https://packagist.org/packages/nglasl/silverstripe-extensible-search)

_The current release is **3.1.2**_

> A module for SilverStripe which will allow user customisation and developer extension of a search page instance, including analytics and suggestions.

## Requirement

* SilverStripe 3.1.X or **3.2.X**

## Getting Started

* Place the module under your root project directory.
* Configure the search engine and search form YAML.
* `/dev/build`
* Configure the extensible search page.

## Overview

### Configuring the Search Page

A new page type `ExtensibleSearchPage` should automatically be created for you in the site root.
This should be published before you are able to perform searches using a search engine selection. Here you can configure how your search page behaves.

<screenshot>

### Search Engine

#### Enabling Full-Text

The extensible search page will work with the MySQL/SQLite full-text search by default, however will require some YAML configuration around the data objects you wish to search against.

```yaml
FulltextSearchable:
  searchable_classes:
    - 'SiteTree'
SiteTree:
  create_table_options:
    MySQLDatabase:
      'ENGINE=MyISAM'
  extensions:
    - "FulltextSearchable('Title, MenuTitle, Content, MetaDescription')"
```

It should also be highlighted that unfortunately full-text does **not** support custom data objects and fields. However, these can be applied to `File` and not just `SiteTree`.

#### Search Engine Extensions

These will need to be created as an extension applied to `ExtensibleSearchPage`, and explicitly defined under the `search_engine_extensions` using YAML. The `ExtensibleSearchPage_Controller` will also require an extension so the search results can be retrieved for your search engine correctly. When the one class has been added to `search_engine_extensions` (pretty titles can be defined using array syntax), and the two extensions applied, your search engine will appear as a selection.

<replace this with a solr example>

https://github.com/nyeholt/silverstripe-solr

##### Customisation

###### Model Extension

If your search wrapper supports filtering based upon page hierarchy (`ParentID` as opposed to just `SiteID`), the `supports_hierarchy` flag can be set.

It is also possible to define the `getSelectableFields` function if you wish to customise what fields are returned to an end user, such as when selecting a field to sort by.

###### Controller Extension

To process the result set using your new search wrapper, the `getSearchResults` should be implemented on the controller extension, returning the array of data you wish to render into your search template.

### Search Form

To allow search functionality through template hooks, make sure the appropriate extension has been applied.

```yaml
Page_Controller:
  extensions:
    - 'ExtensibleSearchExtension'
```

The search form may now be retrieved from a template using `$SearchForm`

### Search Analytics

These may be disabled by configuring the `enable_analytics` flag.

<screenshot>

### Archiving

`/dev/tasks/ExtensibleSearchArchiveTask` creates an archived collection of analytics for each search page. Depending on your search traffic, the queued jobs module may be recommended to trigger this on a schedule.

`number_to_archive`

<screenshots>

### Search Suggestions

These require the appropriate permissions.
<commit_msg>DOCUMENTATION, cleaning up the formatting.<commit_after># [extensible-search](https://packagist.org/packages/nglasl/silverstripe-extensible-search)

_The current release is **3.1.2**_

> A module for SilverStripe which will allow user customisation and developer extension of a search page instance, including analytics and suggestions.

## Requirement

* SilverStripe 3.1.X or **3.2.X**

## Getting Started

* Place the module under your root project directory.
* Configure the search engine and search form YAML.
* `/dev/build`
* Configure the extensible search page.

## Overview

### Extensible Search Page

This is automatically created, and allows configuration for search based on a search engine (more below).

### Search Engine

The extensible search page is designed to use full-text search by default, however does provide support for search engine extensions (elastic search for example).

#### Full-Text

```yaml
FulltextSearchable:
  searchable_classes:
    - 'SiteTree'
SiteTree:
  create_table_options:
    MySQLDatabase: 'ENGINE=MyISAM'
  extensions:
    - "FulltextSearchable('Title, MenuTitle, Content, MetaDescription')"
```

When considering the search engine to use, full-text has a few important limitations. The above can also be applied to `File`, however it currently does not support custom data objects or fields.

#### Search Engine Extensions

The following is an example:

```yaml
ExtensibleSearchPage:
  search_engine_extensions:
    SolrSearch: 'Solr'
  extensions:
    - 'SolrSearch'
ExtensibleSearchPage_Controller:
  extensions:
    - 'SolrSearch_Controller'
```

When implementing your own search engine extension, make sure to define the following:

`supports_hierarchy` and `getSelectableFields` and `getSearchResults`

### Search Form

```yaml
Page_Controller:
  extensions:
    - 'ExtensibleSearchExtension'
```

The search form can be rendered in templates using:

```php
$SearchForm
```

### Search Analytics

These may be disabled by configuring the `enable_analytics` flag.

<screenshot>

### Archiving

`/dev/tasks/ExtensibleSearchArchiveTask` creates an archived collection of analytics for each search page. Depending on your search traffic, the queued jobs module may be recommended to trigger this on a schedule.

`number_to_archive`

<screenshots>

### Search Suggestions

These require the appropriate permissions.

{'fraction_non_alphanumeric': 0.07225583405358686, 'fraction_numerical': 0.0024200518582541053, 'mean_word_length': 4.940451745379876, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1131746', 'n_tokens_mistral': 1557, 'n_tokens_neox': 1492, 'n_words': 685}