public function testCleanAndCommit() { $testTitle = "Ipsum Lorem Vehicula"; $nodeSource = Kernel::getService('em')->getRepository('GeneratedNodeSources\\NSPage')->findOneBy(array('title' => $testTitle)); if (null !== $nodeSource) { try { $solrDoc = new SolariumNodeSource($nodeSource, Kernel::getService('solr')); $solrDoc->cleanAndCommit(); $this->assertFalse($solrDoc->getDocumentFromIndex()); } catch (SolrServerNotAvailableException $e) { } catch (HttpException $e) { return; } } }
/** * Update or create solr documents for each Node sources. * * @param FilterNodesSourcesEvent $event */ public function onSolariumNodeUpdate(FilterNodeEvent $event) { if (null !== $this->solr) { foreach ($event->getNode()->getNodeSources() as $nodeSource) { $solrSource = new SolariumNodeSource($nodeSource, $this->solr); $solrSource->getDocumentFromIndex(); $solrSource->updateAndCommit(); } } }
/** * Delete Solr index and loop over every NodesSources to index them again. * * @param \Solarium\Client $this->solr * @param OutputInterface $output */ private function reindexNodeSources(\Solarium\Client $solr, OutputInterface $output) { $update = $this->solr->createUpdate(); // Empty first $update->addDeleteQuery('*:*'); $this->solr->update($update); $update->addCommit(); /* * Use buffered insertion */ $buffer = $this->solr->getPlugin('bufferedadd'); $buffer->setBufferSize(100); // Then index $nSources = $this->entityManager->getRepository('RZ\\Roadiz\\Core\\Entities\\NodesSources')->findAll(); $progress = new ProgressBar($output, count($nSources)); $progress->setFormat('verbose'); $progress->start(); foreach ($nSources as $ns) { $solariumNS = new SolariumNodeSource($ns, $this->solr); $solariumNS->setDocument($update->createDocument()); $solariumNS->index(); $buffer->addDocument($solariumNS->getDocument()); $progress->advance(); } $buffer->flush(); // optimize the index $update->addOptimize(true, false, 5); $progress->finish(); }