PHP code example of spatie / elasticsearch-search-string-parser

1. Go to this page and download the library: Download spatie/elasticsearch-search-string-parser 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/ */

    

spatie / elasticsearch-search-string-parser example snippets


use Elasticsearch\ClientBuilder;
use Spatie\ElasticsearchStringParser\SearchQuery;

$subjects = SearchQuery::forClient(ClientBuilder::create())
    ->baseDirective(new SubjectBaseDirective())
    ->patternDirectives(
        new CompanyDirective(),
        new UserDirective(),
    )  
    ->search('deadly neurotoxin company:aperture @glados');

$searchString = 'cheap neurotoxin company:aperture deadly @glados';

SearchQuery::forClient(ClientBuilder::create())
    ->baseDirective(new SubjectBaseDirective())
    ->patternDirectives(
        new CompanyDirective(),
        new UserDirective(),
    )->search($searchString);

$elasticsearch-search-string-parser = new Spatie\ElasticsearchStringParser();
echo $elasticsearch-search-string-parser->echoPhrase('Hello, Spatie!');