public function getStoresAlgolia($coordinate) { $latitude = $this->getLatitude($coordinate); $longitude = $this->getLongitude($coordinate); $client = new \AlgoliaSearch\Client(APPLICATION_ID, API_KEY); $index = $client->initIndex(INDEX_STORES); $query = $index->search("", array("aroundLatLng" => "{$latitude},{$longitude}", "aroundRadius" => 1000)); if ($this->validateNbHits($query)) { parent::response($response_code = 200, $this->arrayInformation($query)); } else { parent::response($response_code = 404, array("stores" => 0, "message" => "Stores near not found")); } }
public function syncProducts() { if ($this->isConfigurationValid() == false) { return false; } try { $client = new \AlgoliaSearch\Client($this->application_id, $this->api_key); $index = $client->initIndex($this->index_name); $products = $this->getProductsToIndex(); $settings = $this->getSettings(); $index->setSettings($settings); $products = array_chunk($products, 10); foreach ($products as $product_group) { $index->saveObjects($product_group); } } catch (Exception $exception) { d($exception); return false; } return true; }
public function __construct($indexName) { // APPLICATION_ID & API_KEY are defined in keys.php $client = new \AlgoliaSearch\Client(APPLICATION_ID, API_KEY); $this->index = $client->initIndex($indexName); }
<?php require_once '../algoliasearch.php'; $client = new \AlgoliaSearch\Client('55D6OYYP5R', '125e15cb6cabe55d4b3c8f8ac7acdfde'); var_dump($client->listIndexes()); var_dump($client->getLogs());
<?php // autoload.php @generated by Composer require_once __DIR__ . '/composer' . '/autoload_real.php'; return ComposerAutoloaderInit8bd13e21811ac4e03034a8a5a61beace::getLoader(); $client = new \AlgoliaSearch\Client('SMKT5MSYKT', '800636e75ea1db77a0f76817bf0743dc'); $index = $client->initIndex("contacts"); $batch = json_decode(file_get_contents("contacts.json"), true); $index->addObjects($batch); /** Search by firstname */ var_dump($index->search('jimmie')); /** Search a firstname with typo */ var_dump($index->search('jimie')); /** Search for a company */ var_dump($index->search('california paint')); /** Search by firstname & company */ var_dump($index->search('jimmie paint'));