/**
  * @group Slow
  * @slowExecutionTime 0.09325 ms
  * @covers \Wikia\Search\IndexService\AbstractService::getCurrentDocumentId
  */
 public function testGetCurrentDocumentId()
 {
     $service = $this->service->getMockForAbstractClass();
     $mwservice = new MediaWikiService();
     $service->setPageId(123);
     $this->assertEquals(sprintf('%s_%s', $mwservice->getWikiId(), $mwservice->getCanonicalPageIdFromPageId(123)), $service->getCurrentDocumentId());
 }
Example #2
0
 /**
  * Provides the logic for the appropriate field name, dynamic or not.
  * @return string
  */
 public function __toString()
 {
     if (in_array($this->fieldName, self::$languageFields) && $this->service->searchSupportsLanguageCode($this->languageCode)) {
         $lang = preg_replace('/([^-]+)(-.*)?/', '_$1', $this->languageCode);
         $mv = in_array($this->fieldName, self::$multiValuedFields) ? '_mv' : '';
         return sprintf('%s%s%s', $this->fieldName, $mv, $lang);
     }
     return $this->fieldName;
 }
 /**
  * Constructor method.
  * Sets defaults -- no writing to memache, and a default search indexer instance
  */
 public function __construct()
 {
     parent::__construct();
     $this->service = new MediaWikiService();
     $this->service->setGlobal('AllowMemcacheWrites', false)->setGlobal('AppStripsHtml', true);
     if (function_exists('newrelic_disable_autorum')) {
         newrelic_disable_autorum();
     }
     if (function_exists('newrelic_background_job')) {
         newrelic_background_job(true);
     }
 }
Example #4
0
 /**
  * Does a little prep on a result object, applies highlighting if exists, and adds to result array.
  * @param  Result $result
  * @throws WikiaException
  * @return Base provides fluent interface
  */
 protected function addResult(Result $result)
 {
     $id = $result['id'];
     $highlighting = $this->searchResultObject->getHighlighting();
     if ($highlighting !== null && ($hlResult = $highlighting->getResult($id)) && ($field = $hlResult->getField(Utilities::field('html')))) {
         $result->setText($field[0]);
     }
     if ($result['created']) {
         $result->setVar('fmt_timestamp', $this->service->getMediaWikiFormattedTimestamp($result['created']));
         $result->setVar('created_30daysago', time() - strtotime($result['created']) > 2592000);
     }
     $result->setVar('cityArticlesNum', $result['wikiarticles'])->setVar('wikititle', $result[Utilities::field('wikititle')]);
     $this->results[$id] = $result;
     return $this;
 }
Example #5
0
 /**
  * get video views
  * @return string $videoViews
  */
 public function getVideoViews()
 {
     try {
         return $this->service->getFormattedVideoViewsForPageId($this['pageid']);
     } catch (\Exception $e) {
         return 0;
     }
 }
 /**
  * @group Slow
  * @slowExecutionTime 0.13412 ms
  * @covers Wikia\Search\MediaWikiService::getSimpleMessage
  */
 public function testGetSimpleMessage()
 {
     $mockWfMessage = $this->getGlobalFunctionMock('wfMessage');
     $mockMessage = $this->getMockBuilder('Message')->disableOriginalConstructor()->setMethods(array('text'))->getMock();
     $service = $this->service->setMethods(null)->getMock();
     $params = array('whatever');
     $mockWfMessage->expects($this->once())->method('wfMessage')->with('foo', $params)->will($this->returnValue($mockMessage));
     $mockMessage->expects($this->once())->method('text')->will($this->returnValue('bar whatever'));
     $this->assertEquals('bar whatever', $service->getSimpleMessage('foo', $params));
 }
 /**
  * @group Slow
  * @slowExecutionTime 0.07898 ms
  * @covers \Wikia\Search\IndexService\AbstractWikiService::getCurrentDocumentId
  */
 public function testGetCurrentDocumentId()
 {
     $service = new MediaWikiService();
     $this->assertEquals(sprintf('%s_%s', $service->getWikiId(), \Wikia\Search\IndexService\AbstractWikiService::PAGEID_PLACEHOLDER), $this->service->getMockForAbstractClass()->getCurrentDocumentId());
     $this->assertEquals(sprintf('%s_%s', $service->getWikiId(), 123), $this->service->getMockForAbstractClass()->setPageId(123)->getCurrentDocumentId());
 }