/** * {@inheritDoc} */ public function synchronize(array $documents) { if ($this->clearOnSync) { $this->index->clearIndex(); } $this->index->addObjects($documents); }
/** * @param \Sculpin\Core\Event\SourceSetEvent $event */ public function afterRun(SourceSetEvent $event) { $documents = array(); /** @var AbstractSource $item */ foreach ($event->allSources() as $item) { if ($item->data()->get('indexed')) { if ($item->isGenerated()) { continue; } $documents[] = $this->parseSource($item); } } $this->index->clearIndex(); $this->index->addObjects($documents); }
/** * Get the results for the given query. * * @param string|array|\Spatie\SearchIndex\Query\Algolia\SearchQuery $query * * @return mixed */ public function getResults($query) { $parameters = []; if (is_object($query) && $query instanceof SearchQuery) { $query = $query->toArray(); } if (is_array($query)) { $collection = new Collection($query); $query = $collection->pull('query', ''); $parameters = $collection->toArray(); } return $this->index->search($query, $parameters); }
/** * Configure settings on the Algolia index. * * @return void */ public function setSettings() { $this->index->setSettings(['attributesToIndex' => ['unordered(h1)', 'unordered(h2)', 'unordered(h3)', 'unordered(h4)', 'unordered(content)'], 'attributesToHighlight' => ['h1', 'h2', 'h3', 'h4', 'content'], 'attributesToRetrieve' => ['h1', 'h2', 'h3', 'h4', '_tags', 'link'], 'customRanking' => ['asc(importance)'], 'ranking' => ['words', 'typo', 'attribute', 'proximity', 'exact', 'custom'], 'minWordSizefor1Typo' => 3, 'minWordSizefor2Typos' => 7, 'allowTyposOnNumericTokens' => false, 'minProximity' => 2, 'ignorePlurals' => true, 'advancedSyntax' => true, 'removeWordsIfNoResults' => 'allOptional']); }
public function it_can_get_search_results_using_an_array_without_a_query_key(\AlgoliaSearch\Index $index) { $query = ['param1' => 'yes', 'param2' => 'no']; $index->search('', ['param1' => 'yes', 'param2' => 'no'])->shouldBeCalled(); $this->getResults($query); }
/** * Reindex atomically the given index with the given records. * * @param Index $index * @param array $algoliaRecords * * @return mixed */ private function reindexAtomically(Index $index, array $algoliaRecords) { $temporaryIndexName = 'tmp_' . $index->indexName; $temporaryIndex = $this->initIndex($temporaryIndexName); $temporaryIndex->addObjects($algoliaRecords); $settings = $index->getSettings(); // Temporary index overrides all the settings on the main one. // So we need to set the original settings on the temporary one before atomically moving the index. $temporaryIndex->setSettings($settings); return $this->moveIndex($temporaryIndexName, $index->indexName); }