Git Product home page Git Product logo

elasticscout's Introduction

Latest Stable Version Latest Unstable Version Total Downloads License composer.lock

ElasticScout

A Laravel Scout Driver for Elasticsearch 5.x

Overview

ElasticScout is a Laravel Scout Elasticsearch 5.x compatible engine. It makes critical changes to the old Elasticseach Scout Engine, as well as adds new functionality.

The ElasticScout engine includes an Elasticsearch Query Builder which can be used to create elaborate custom queries and aggregations, allowing full use of Elasticsearch within the Laravel/Scout Paradigm.

License

ElasticScout is released under the MIT Open Source License, https://opensource.org/licenses/MIT

Copyright

ElasticScout © Broker Exchange Network

Installation

  • Run composer require command composer require brokerexchange/elasticscout
  • Configure Elasticsearch Host (default: localhost:9200)
   ELASTICSEARCH_HOST='elastic1.host.com:9200,elastic2.host.com:9200'
  • Add trait to desired model
   use ElasticScout\Searchable;

Usage

   //create search/query object
   $search = $article->search()
       ->boolean()
       ->should(DSL::match('title',$request->input('query')))
       ->should(DSL::match('body',$request->input('query')))
       ->filter(DSL::term('published', 1))
       ->aggregate(Agg::terms('categories', 'category.name'));
       
   //fire the search
   $articles = $search->paginate();
       
   //retrieve aggregation results
   $categories = $search->aggregation('categories');

Mappings

You may set a custom mapping by simply defining a "mapping" method on your model.

   public function mappings()
   {
       return [
           $this->searchableType() => [
               'properties' => [
                   'name' => [
                       'type' => 'text',
                       'fields' => [
                           'keyword' => [
                               'type' => 'keyword',
                           ],
                           'autocomplete' => [
                               'type' => 'text',
                               'analyzer' => 'autocomplete',
                               'search_analyzer' => 'autocomplete_search',
                           ],
                       ],
                   ],
               ]
           ]
       ]
   }

Settings

You may create custom settings and analyzers by creating a "settings" method on the model.

   public function settings()
   {
     return [
         'index' => [
             'analysis' => [
                 'analyzer' => [
                     'autocomplete' => [
                         'tokenizer' => 'autocomplete',
                         'filter' => [
                             'lowercase',
                         ],
                     ],
                     'autocomplete_search' => [
                         'tokenizer' => 'lowercase',
                     ],
                 ],
                 'tokenizer' => [
                     'autocomplete' => [
                         'type' => 'edge_ngram',
                         'min_gram' => 1,
                         'max_gram' => 15,
                         'token_chars' => [
                             'letter'
                         ]
                     ]
                 ]
             ],
         ],
     ];
   }

elasticscout's People

Contributors

brino avatar seanwahlstrom avatar artistan avatar llz avatar

Watchers

James Cloos avatar Josh Anthony avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.