/**
  * {@inheritDoc}
  */
 public function synchronize(array $documents)
 {
     if ($this->clearOnSync) {
         $this->index->clearIndex();
     }
     $this->index->addObjects($documents);
 }
Exemplo n.º 2
0
 /**
  * @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);
 }
Exemplo n.º 3
0
 /**
  * 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);
 }
Exemplo n.º 4
0
 /**
  * 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']);
 }
Exemplo n.º 5
0
 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);
 }
Exemplo n.º 6
0
 /**
  * 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);
 }