Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
Rias committed Dec 11, 2017
0 parents commit 7ca46da
Show file tree
Hide file tree
Showing 20 changed files with 3,846 additions and 0 deletions.
1 change: 1 addition & 0 deletions .craftplugin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"pluginName":"Scout","pluginDescription":"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.","pluginVersion":"0.1.0","pluginAuthorName":"Rias","pluginVendorName":"rias","pluginAuthorUrl":"https://rias.be","pluginAuthorGithub":"Rias500","codeComments":"","pluginComponents":["consolecommands","services","settings","tasks"],"consolecommandName":"","controllerName":"","cpsectionName":"","elementName":"","fieldName":"","modelName":"","purchasableName":"","recordName":"","serviceName":"","taskName":"","utilityName":"","widgetName":"","apiVersion":"api_version_3_0"}
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# CRAFT ENVIRONMENT
.env.php
.env.sh
.env

# COMPOSER
/vendor

# BUILD FILES
/bower_components/*
/node_modules/*
/build/*
/yarn-error.log

# MISC FILES
.cache
.DS_Store
.idea
.project
.settings
*.esproj
*.sublime-workspace
*.sublime-project
*.tmproj
*.tmproject
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
config.codekit3
prepros-6.config
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Scout Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 0.1.0 - 2017-12-11
### Added
- Initial release
9 changes: 9 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright (c) 2017 Rias

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
126 changes: 126 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Scout plugin for Craft CMS 3.x

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.

## Requirements

This plugin requires Craft CMS 3.0.0-RC1 or later.

## Installation

To install the plugin, follow these instructions.

1. Open your terminal and go to your Craft project:

cd /path/to/project

2. Then tell Composer to load the plugin:

composer require rias/scout

3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Scout.

## 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](https://www.algolia.com/api-keys) account) and a `mappings` key, which defines your site's mappings.

Within the mappings array, each index is represented by an array, and values are the configuration.

```php
<?php

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

### 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,
```

#### `filter`
The criteria on which to filter the `elementType`, in the example we only want entries from the section `blog`

```php
'filter' => function (craft\base\Element $element) {
return $element->section->handle == '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
<?php

use craft\elements\Entry;
use League\Fractal\TransformerAbstract;

class MyTransformerClassName extends TransformerAbstract
{
public function transform(Entry $entry)
{
return [
// ...
];
}
}
```


## Scout Roadmap

Some things to do, and ideas for potential features:

* Use the queue to process Algolia updates
* Add console commands to flush/import indexes

Brought to you by [Rias](https://rias.be)
52 changes: 52 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "rias/scout",
"description": "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.",
"type": "craft-plugin",
"version": "0.1.0",
"keywords": [
"craft",
"cms",
"craftcms",
"craft-plugin",
"scout"
],
"support": {
"docs": "https://github.com/Rias500/scout/blob/master/README.md",
"issues": "https://github.com/Rias500/scout/issues"
},
"license": "MIT",
"authors": [
{
"name": "Rias",
"homepage": "https://rias.be"
}
],
"require": {
"craftcms/cms": "^3.0.0-RC1",
"algolia/algoliasearch-client-php": "^1.23",
"league/fractal": "^0.17.0"
},
"repositories": [
{
"type": "composer",
"url": "https://asset-packagist.org"
}
],
"autoload": {
"psr-4": {
"rias\\scout\\": "src/"
}
},
"extra": {
"name": "Scout",
"handle": "scout",
"schemaVersion": "0.1.0",
"hasCpSettings": true,
"hasCpSection": false,
"changelogUrl": "https://raw.githubusercontent.com/Rias500/scout/master/CHANGELOG.md",
"components": {
"scoutService": "rias\\scout\\services\\ScoutService"
},
"class": "rias\\scout\\Scout"
}
}
Loading

0 comments on commit 7ca46da

Please sign in to comment.