PHP code example of cloudmediasolutions / laravel-scout-opensearch

1. Go to this page and download the library: Download cloudmediasolutions/laravel-scout-opensearch 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/ */

    

cloudmediasolutions / laravel-scout-opensearch example snippets



    'client' => [
        'hosts' => explode(',', env('OPENSEARCH_HOSTS')),
        'basicAuthentication' => [
            env('OPENSEARCH_USERNAME'),
            env('OPENSEARCH_PASSWORD'),
        ],
    ],



    Song::search("crass")
        ->orderBy("_score", "desc")
        ->orderBy("id")
        ->cursorPaginate(10);



    Song::search()
        ->orderByRaw(
            new FieldSort('stars', 'desc', ['mode' => 'avg'])
        )
        ->orderBy('id')
        ->cursorPaginate(10);



    Article::search()
        ->orderByRaw(
            (new FieldSort('comments.created_at', 'desc', ['mode' => 'max']))
                ->setNestedFilter(new NestedSort('comments'))
        )
        ->orderBy('id')
        ->cursorPaginate(10);



    Store::search()
        ->orderByRaw(new FieldSort(
            '_geo_distance',
            'desc',
            [
                'point' => [10, 10],
                'unit' => 'km',
                'distance_type' => 'arc',
                'mode' => 'min',
                'ignore_unmapped' => true
            ]
        ))
        ->orderBy('id')
        ->cursorPaginate(10);