1. Go to this page and download the library: Download nuwber/oponka 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/ */
nuwber / oponka example snippets
use Nuwber\Oponka\Facades\Oponka;
$client = Oponka::client();
// Now you can use the $client directly with the OpenSearch PHP client methods
use Nuwber\Oponka\Facades\Oponka;
use OpenSearchDSL\Search;
use OpenSearchDSL\Query\Compound\BoolQuery;
use OpenSearchDSL\Query\TermLevel\TermQuery;
use OpenSearchDSL\Query\FullText\MatchQuery;
// Get the DSL Search object
$search = Oponka::search(); // Or potentially a method to get a new Search object
// Build a query
$query = new BoolQuery();
$query->add(new MatchQuery('title', 'laravel'));
$query->add(new TermQuery('status', 'published'), BoolQuery::FILTER);
$search->addQuery($query);
$search->setSource(['title', 'status', 'publish_date']);
$search->setSize(10);
$search->setFrom(0); // for pagination
// Prepare the parameters for OpenSearch
$params = [
'index' => 'my_index',
'body' => $search->toArray(),
];
// Execute the search
$results = Oponka::search($params);
// Process results (assuming a Result object or similar is returned)
// foreach ($results->getHits() as $hit) {
// // Access hit data: $hit['_source'], $hit['_score'], etc.
// }
// $total = $results->getTotal();