2017 © Pedro PelĂĄez
 

craft-plugin craft-scout

Craft Scout provides a simple solution for adding full-text search to your entries. Scout will automatically keep your search indexes in sync with your entries.

image

jorgeanzola/craft-scout

Craft Scout provides a simple solution for adding full-text search to your entries. Scout will automatically keep your search indexes in sync with your entries.

  • Friday, July 27, 2018
  • by JorgeAnzola
  • Repository
  • 1 Watchers
  • 0 Stars
  • 15 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 16 Versions
  • 0 % Grown

The README.md

Icon, (*1)

Latest Version Quality Score StyleCI Total Downloads, (*2)

Scout plugin for Craft CMS 3

Craft Scout provides a simple solution for adding full-text search to your entries. Scout will automatically keep your search indexes in sync with your entries., (*3)

Support Open Source. Buy beer.

This plugin is licensed under a MIT license, which means that it's completely free open source software, and you can use it for whatever and however you wish. If you're using it and want to support the development, buy me a beer over at Beerpay!, (*4)

Beerpay, (*5)

Requirements

This plugin requires Craft CMS 3.0.0-RC1 or later., (*6)

Installation

To install the plugin, follow these instructions., (*7)

  1. Open your terminal and go to your Craft project:, (*8)

    cd /path/to/project
  2. Then tell Composer to load the plugin:, (*9)

    composer require rias/craft-scout
  3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Scout., (*10)

Setup

To define your indices, create a new scout.php file within your config folder. This file should return an array with 3 keys, an application_id, your admin_api_key (which are both found in your Algolia account) and a mappings key, which defines your site's mappings., (*11)

Within the mappings array, each index is represented by a configuration array., (*12)

 true,
    "application_id" => "algolia",
    "admin_api_key" => "algolia",
    "mappings" => [
        [
            'indexName' => 'blog',
            'elementType' => \craft\elements\Entry::class,
            'criteria' => [
                'section' => 'blog'
            ],
            'transformer' => function (craft\base\Element $element) {
                return $element->toArray();
            },
        ],
        ...
    ],
];
```

### The Sync option
This config variable determines if Scout should keep your entries in sync automatically. Setting this to `false` disables all of Scout's event listeners.

### Mapping configuration settings

#### `indexName`
The index name in Algolia, if you don't already have an index created, Scout will create one for you.

#### `elementType`
The element type that this index contains, most of the time this will be `craft\elements\Entry::class`

Craft's default element type classes are:

- `craft\elements\Asset`
- `craft\elements\Category`
- `craft\elements\Entry`
- `craft\elements\GlobalSet`
- `craft\elements\MatrixBlock`
- `craft\elements\Tag`
- `craft\elements\User`

```php
'elementType' => craft\elements\Entry::class,
```

#### `criteria`
An array of parameters that should be set on the [Element Query](https://github.com/craftcms/docs/blob/v3/en/element-queries.md) that limits which entries go inside the index. These criteria are also used when importing through the console command.

```php
'criteria' => [
    'section' => 'blog',
],
```

#### `transformer`
The [transformer](http://fractal.thephpleague.com/transformers/) that should be used to define the data that should be sent to Algolia for each element. If you don’t set this, the default transformer will be used, which includes all of the element’s direct attribute values, but no custom field values.

```php
// Can be set to a function
'transformer' => function(craft\elements\Entry $entry) {
    return [
        'title' => $entry->title,
        'id' => $entry->id,
        'url' => $entry->url,
    ];
},

// Or a string/array that defines a Transformer class configuration
'transformer' => 'MyTransformerClassName',

// Or a Transformer class instance
'transformer' => new MyTransformerClassName(),
```
Your custom transformer class would look something like this:
```php
 [
    'summary',
    'matrixElement'
]
```

*Important* - distinctId (available after indexing) must be set up as an attribute for faceting for deletion of objects to work when using splitElementIndex.

## Console commands
Scout provides two easy console commands for managing your indices.

### Importing
To import one or all indices you can run the following console command

```
./craft scout/index/import 

The indexName argument is not required, all your mappings will be imported when you omit it., (*13)

Flushing/Clearing

Clearing an index is as easy as running a command in your console., (*14)

./craft scout/index/flush <indexName?>

As with the import command, indexName is not required, when flushing Scout will ask you to confirm that you really want to clear all the data in your index., (*15)

Credits

  • Craft Algolia by aaronwaldon as a base to start from
  • @larsboldt for the Split Element Index option

Brought to you by Rias, (*16)

The Versions

27/07 2018

dev-master

9999999-dev

Craft Scout provides a simple solution for adding full-text search to your entries. Scout will automatically keep your search indexes in sync with your entries.

  Sources   Download

MIT

The Requires

 

cms scout craftcms craft-plugin craft

27/07 2018

0.4.5

0.4.5.0

Craft Scout provides a simple solution for adding full-text search to your entries. Scout will automatically keep your search indexes in sync with your entries.

  Sources   Download

MIT

The Requires

 

cms scout craftcms craft-plugin craft

27/07 2018

0.4.4

0.4.4.0

Craft Scout provides a simple solution for adding full-text search to your entries. Scout will automatically keep your search indexes in sync with your entries.

  Sources   Download

MIT

The Requires

 

cms scout craftcms craft-plugin craft

01/05 2018

0.4.1

0.4.1.0

Craft Scout provides a simple solution for adding full-text search to your entries. Scout will automatically keep your search indexes in sync with your entries.

  Sources   Download

MIT

The Requires

 

cms scout craftcms craft-plugin craft

17/04 2018

0.4.0

0.4.0.0

Craft Scout provides a simple solution for adding full-text search to your entries. Scout will automatically keep your search indexes in sync with your entries.

  Sources   Download

MIT

The Requires

 

cms scout craftcms craft-plugin craft

12/03 2018

0.3.0

0.3.0.0

Craft Scout provides a simple solution for adding full-text search to your entries. Scout will automatically keep your search indexes in sync with your entries.

  Sources   Download

MIT

The Requires

 

cms scout craftcms craft-plugin craft

28/02 2018

0.2.8

0.2.8.0

Craft Scout provides a simple solution for adding full-text search to your entries. Scout will automatically keep your search indexes in sync with your entries.

  Sources   Download

MIT

The Requires

 

cms scout craftcms craft-plugin craft

27/02 2018

0.2.7

0.2.7.0

Craft Scout provides a simple solution for adding full-text search to your entries. Scout will automatically keep your search indexes in sync with your entries.

  Sources   Download

MIT

The Requires

 

cms scout craftcms craft-plugin craft

15/01 2018

0.2.6

0.2.6.0

Craft Scout provides a simple solution for adding full-text search to your entries. Scout will automatically keep your search indexes in sync with your entries.

  Sources   Download

MIT

The Requires

 

cms scout craftcms craft-plugin craft

15/01 2018

0.2.5

0.2.5.0

Craft Scout provides a simple solution for adding full-text search to your entries. Scout will automatically keep your search indexes in sync with your entries.

  Sources   Download

MIT

The Requires

 

cms scout craftcms craft-plugin craft

14/01 2018

0.2.4

0.2.4.0

Craft Scout provides a simple solution for adding full-text search to your entries. Scout will automatically keep your search indexes in sync with your entries.

  Sources   Download

MIT

The Requires

 

cms scout craftcms craft-plugin craft

08/01 2018

0.2.3

0.2.3.0

Craft Scout provides a simple solution for adding full-text search to your entries. Scout will automatically keep your search indexes in sync with your entries.

  Sources   Download

MIT

The Requires

 

cms scout craftcms craft-plugin craft

08/01 2018

0.2.2

0.2.2.0

Craft Scout provides a simple solution for adding full-text search to your entries. Scout will automatically keep your search indexes in sync with your entries.

  Sources   Download

MIT

The Requires

 

cms scout craftcms craft-plugin craft

12/12 2017

0.2.1

0.2.1.0

Craft Scout provides a simple solution for adding full-text search to your entries. Scout will automatically keep your search indexes in sync with your entries.

  Sources   Download

MIT

The Requires

 

cms scout craftcms craft-plugin craft

12/12 2017

0.2.0

0.2.0.0

Craft Scout provides a simple solution for adding full-text search to your entries. Scout will automatically keep your search indexes in sync with your entries.

  Sources   Download

MIT

The Requires

 

cms scout craftcms craft-plugin craft

12/12 2017

0.1.1

0.1.1.0

Craft Scout provides a simple solution for adding full-text search to your entries. Scout will automatically keep your search indexes in sync with your entries.

  Sources   Download

MIT

The Requires

 

cms scout craftcms craft-plugin craft