コード例 #1
0
 /**
  * Formulates ID queries for each page ID
  * @return array
  */
 protected function getIdQueries()
 {
     $idQueries = [];
     $wid = $this->getMwService()->getWikiId();
     foreach (array_keys($this->getMappedIds()) as $canonicalId) {
         $idQueries[] = Wikia\Search\Utilities::valueForField('id', sprintf('%s_%s', $wid, $canonicalId));
     }
     return $idQueries;
 }
コード例 #2
0
 /**
  * @covers InfoboxesService::getIdQueries
  */
 public function testGetIdQueries()
 {
     $mwService = $this->getMock('Wikia\\Search\\MediaWikiService', ['getWikiId']);
     $service = $this->getMock('InfoboxesService', ['getMappedIds', 'getMwService']);
     $mappedIds = [456 => [789, 234]];
     $service->expects($this->once())->method('getMwService')->will($this->returnValue($mwService));
     $mwService->expects($this->once())->method('getWikiId')->will($this->returnValue(123));
     $service->expects($this->once())->method('getMappedIds')->will($this->returnValue($mappedIds));
     $get = new ReflectionMethod('InfoboxesService', 'getIdQueries');
     $get->setAccessible(true);
     $this->assertEquals([Wikia\Search\Utilities::valueForField('id', '123_456')], $get->invoke($service));
 }
コード例 #3
0
 /**
  * Returns the result object, or null if it doesn't exist
  * @return Wikia\Search\Result|null;
  */
 public function getResult()
 {
     $docId = $this->getDocumentId();
     if (isset(self::$documentCache[$docId])) {
         $result = self::$documentCache[$docId];
     } else {
         $config = $this->getConfig();
         $config->setQuery(Wikia\Search\Utilities::valueForField('id', $docId));
         $queryService = $this->getFactory()->getFromConfig($config);
         $resultSet = $queryService->search();
         $result = isset($resultSet[$docId]) ? $resultSet[$docId] : null;
         if ($result !== null) {
             self::$documentCache[$docId] = $result;
         }
     }
     return $result;
 }
コード例 #4
0
 /**
  * @group Slow
  * @slowExecutionTime 0.01169 ms
  */
 public function testGetDocumentWithResult()
 {
     $service = $this->getMock('SolrDocumentService', ['getConfig', 'getFactory', 'getDocumentId']);
     $factory = $this->getMock('Wikia\\Search\\QueryService\\Factory', ['getFromConfig']);
     $config = $this->getMock('Wikia\\Search\\Config', ['setQuery']);
     $queryService = $this->getMock('Wikia\\Search\\QueryService\\Lucene\\Lucene', ['search']);
     $resultSet = $this->getMockBuilder('Wikia\\Search\\ResultSet\\Base')->disableOriginalConstructor()->setMethods(['offsetGet', 'offsetExists'])->getMock();
     $result = $this->getMock('Wikia\\Search\\Result');
     $service->expects($this->once())->method('getConfig')->will($this->returnValue($config));
     $service->expects($this->once())->method('getDocumentId')->will($this->returnValue('123_456'));
     $config->expects($this->once())->method('setQuery')->with(Wikia\Search\Utilities::valueForField('id', '123_456'));
     $service->expects($this->once())->method('getFactory')->will($this->returnValue($factory));
     $factory->expects($this->once())->method('getFromConfig')->with($config)->will($this->returnValue($queryService));
     $queryService->expects($this->once())->method('search')->will($this->returnValue($resultSet));
     $resultSet->expects($this->once())->method('offsetExists')->with('123_456')->will($this->returnValue(true));
     $resultSet->expects($this->once())->method('offsetGet')->with('123_456')->will($this->returnValue($result));
     $this->assertEquals($result, $service->getResult());
     $this->assertArrayHasKey('123_456', SolrDocumentService::$documentCache);
 }
コード例 #5
0
?>
" <?php 
echo $trackingData;
?>
 ><?php 
echo $title;
?>
</a>
		</h1>

		<p class="hub subtle"><?php 
echo strtoupper($result->getHub());
?>
</p>
		<p class="description"><?php 
echo $result->getText(Wikia\Search\Utilities::field('description'), $isOnWikiMatch ? 16 : 60);
?>
</p>

		<ul class="wiki-statistics subtle">
			<li><?php 
echo $pagesMsg;
?>
</li>
			<li><?php 
echo $imgMsg;
?>
</li>
			<li><?php 
echo $videoMsg;
?>
コード例 #6
0
 /**
  * Gets a plain text of an article using Solr.
  *
  * @return string The plain text as stored in solr. Will be empty if we don't have a result.
  */
 public function getTextFromSolr()
 {
     $service = new SolrDocumentService();
     // note that this will use wgArticleId without an article
     if ($this->article) {
         $service->setArticleId($this->article->getId());
     }
     $htmlField = Wikia\Search\Utilities::field('html');
     $document = $service->getResult();
     $text = '';
     if ($document !== null) {
         if (!empty($document[static::SOLR_SNIPPETS_FIELD])) {
             $text = $document[static::SOLR_SNIPPETS_FIELD];
         } elseif (isset($document[$htmlField])) {
             $text = $document[$htmlField];
         }
     }
     return $text;
 }
コード例 #7
0
?>
" <?php 
echo $trackingData;
?>
 ><?php 
echo $title;
?>
</a>
			</h1>

			<p class="hub subtle"><?php 
echo strtoupper($result->getHub());
?>
</p>
			<p class="description"><?php 
echo $result->getText(Wikia\Search\Utilities::field('description'), 16);
?>
</p>

			<ul class="wiki-statistics subtle">
				<li><?php 
echo $pagesMsg;
?>
</li>
				<li><?php 
echo $imgMsg;
?>
</li>
				<li><?php 
echo $videoMsg;
?>