/** * Accesses backlinks. Iterate over a result set of documents with outbound links, and store. * (non-PHPdoc) * @see \Wikia\Search\IndexService\AbstractService::execute() */ public function execute() { $docIdSeparated = $this->getCurrentDocumentId() . ' |'; $config = new Config(); $config->setDirectLuceneQuery(true)->setQuery(sprintf('outbound_links_txt:"%s"', $docIdSeparated)); $factory = new Factory(); $backlinks = []; do { $offset = 0; $limit = 100; $config->setStart($offset)->setLimit($limit); $resultSet = $factory->getFromConfig($config)->search(); foreach ($resultSet as $result) { foreach ($result['outbound_links_txt'] as $link) { if (substr($link, 0, strlen($docIdSeparated)) == $docIdSeparated) { $backlinks[] = implode(' | ', array_slice(explode(' | ', $link), 1)); } } } $offset = $limit; $limit = $offset + 100; } while ($config->getResultsFound() > $limit); return ['backlinks_txt' => $backlinks]; }
/** * @group Slow * @slowExecutionTime 0.07594 ms * @covers Wikia\Search\Config::getResultsFound */ public function testGetResultsFound() { $config = new Config(); $this->assertEquals(0, $config->getResultsFound(), 'With no result set, config should say results found is zero'); $results = $this->getMockBuilder('Wikia\\Search\\ResultSet\\Base')->disableOriginalConstructor()->setMethods(['getResultsFound'])->getMock(); $results->expects($this->once())->method('getResultsFound')->will($this->returnValue(100)); $config->setResults($results); $this->assertEquals(100, $config->getResultsFound()); }