Hands On tutorial ElasticSearch from PHP
ElasticSearch provides a very powerfull search engine and a simple php client, but the documentation on practical use in php is limited. In his talk on the Laravel Meetup Groningen Peter Steenbergen filled the gap: He explained the internals of the search and filtering page of shop application in PHP using Laravel and vue.js. His code is remarkably simple but what is does is surprisingly cool!
You are advised to read the documentation and follow instruction in the following order:
- Introduction to ElasticSearch
- Installation and configuration
- (optional) Introduction to the application to find your way in this skeleton
- Instructions part 1 for the hands-on
- Instructions part 2
- Instructions part 3
- Instructions part 4
- Instructions part 5
- simple PHP application requires no prior knowledge of application or front end frameworks
- uses elasticsearch php client but includes hints on Elastica library
- creates ElasticSearch index and mapping using language-specific (dutch) analyzers,
- normalizes entities and insert them in the index,
- search using multi_match
- filter using terms, range and geographical distance
- global, bucket end stats aggregations
- follows patterns: builder, service provider, entity, seeder, valueobject and dependency injection
- PHP >=7.0,
- ElasticSearch (link to installation instructions included)
- basic knowledge of PHP, git and composer
Tested with PHP 7.0 and ElasticSearch 6.4.0
- Just a single page, therefore no routing
- All services are only provided once, therefore no service container
- Not fully SOLID: view 'Rendering' inlined in AbstractController, should have a seperate class
- Security: not all input is fully validated
- The Solutions for Elastica are not fully complete, not tested
This is a pre-release version under development.
COPYRIGHT, LICENCE AND DISCLAIMER
The code in this bundle was based on CoolShop from Peter Steenbergen Modifications and additions are Copyricht (c) MetaClass, Groningen, 2018.
This bundle is under the MIT license. See the complete license in the bundle
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.