PHP code example of pion / laravel-lelastico

1. Go to this page and download the library: Download pion/laravel-lelastico library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pion / laravel-lelastico example snippets


\Lelastico\LelasticoServiceProvider::class,

    protected function propertyMappings(): array
    {
      return [
          'id' => MappingTypes::KEYWORD,
          'name' => MappingTypes::TEXT_WITH_KEYWORD,
          'is_verified' => MappingTypes::BOOLEAN,
          'email' => MappingTypes::textWithAnalyzer('fulltext'),
          'created_at' => MappingTypes::DATE,
          'updated_at' => MappingTypes::DATE,
          'deleted_at' => MappingTypes::DATE,
      ];
    }   
    

    protected function settings(): array
    {
      // Add support for partial text search
      return [
          'index' => [
              'analysis' => [
                  'filter' => [
                      'fulltext_filter' => [
                          // Always from start of beginning of each token
                          'type' => 'edge_ngram',
                          'min_gram' => 3,
                          'max_gram' => 20,
                      ],
                  ],
                  'analyzer' => [
                      'fulltext' => [
                          'type' => 'custom',
                          'tokenizer' => 'standard',
                          'filter' => ['lowercase', 'fulltext_filter'],
                      ],
                  ],
              ],
          ],
      ];
    }
    

    return [
        'indices' => [
            \App\ElasticSearch\Indices\UsersIndex::class,
        ],
    ];
    

/**
 * Allowed fields for sorting.
 *
 * Key is the name of the field in the query.
 * Value is the name of the field in the index.
 *
 * @return array
 */
public function allowedSortFields(): array
{
    return [
        'goals' => 'goals_count',
        'minutes' => 'played_minutes',
    ];
}