PHP code example of vierbergenlars / forage-client
1. Go to this page and download the library: Download vierbergenlars/forage-client 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/ */
vierbergenlars / forage-client example snippets
use vierbergenlars\Forage\Transport\Http as HttpTransport;
use vierbergenlars\Forage\Client;
$transport = new HttpTransport;
$client = new Client($transport);
$query = $client->createQueryBuilder()
->setSearchQuery('Funny cat')
->setOffset(($_GET['page']-1)*10)
->setLimit(10)
->addSearchField('title')
->addFacet('media_type')
->addFilter('animal', 'cat')
->addFilter('categories', array('funny', 'lol'))
->addWeight('title', 3)
->getQuery();
$results = $query->execute();
echo 'Total hits: '.$results->getTotalHits();
foreach($result as $hit) {
/* @var $hit \vierbergenlars\Forage\SearchResult\Hit */
echo ' - '.$hit->getDocument()['title'].' (score: '.$hit->getScore().'; id='.$hit->getId().')';
}