/**
  * Override to filter out videos with the same title.
  * @param Result $result
  * @return $this
  */
 protected function addResult(Result $result)
 {
     if (sizeof($this->titleSet) >= $this->searchConfig->getLimit() || isset($this->titleSet[$result->getTitle()])) {
         return $this;
     } else {
         if (wfFindFile(\Title::newFromText($result->getTitle(), NS_FILE)) === false) {
             // file is deleted on this wiki
             return $this;
         } else {
             $this->titleSet[$result->getTitle()] = true;
             return parent::addResult($result);
         }
     }
 }
Exemple #2
0
 /**
  * @group Slow
  * @slowExecutionTime 0.10045 ms
  * @covers Wikia\Search\Result::getTitle
  * @covers Wikia\Search\Result::setTitle
  */
 public function testTitleFieldMethods()
 {
     global $wgLanguageCode;
     $wgLanguageCode = 'fr';
     $fieldsCopy = $this->defaultFields;
     unset($fieldsCopy['title']);
     unset($fieldsCopy[Utilities::field('title')]);
     $result = new Result($fieldsCopy);
     $this->assertEquals('', $result->getTitle(), 'A result with no title or language title field should return an empty string during getTitle().');
     $title = 'Foo';
     $result['title'] = $title;
     $this->assertEquals($title, $result->getTitle(), 'A result with no language title field should return a normal title field during getTitle() if it exists.');
     $languageTitle = 'LangFoo';
     $result[Utilities::field('title')] = $languageTitle;
     $this->assertEquals($languageTitle, $result->getTitle(), 'A result should return the language title field during getTitle() if it exists.');
     $languageTitleWithJunk = '.../**$#(FooEnglish...</span>&hellip;';
     $this->assertEquals($result, $result->setTitle($languageTitleWithJunk), 'Wikia\\Search\\Result::setTitle should provide a fluent interface');
     $method = new ReflectionMethod('Wikia\\Search\\Result', 'fixSnippeting');
     $method->setAccessible(true);
     $this->assertEquals($method->invoke($result, $languageTitleWithJunk), $result->getTitle(), 'A title set with Wikia\\Search\\Result::setTitle() should be filtered with Wikia\\Search\\Utilities::fixSnippeting before storage.');
     unset($result[Utilities::field('title')]);
     unset($result['title']);
     $result[Utilities::field('title', 'en')] = $languageTitle;
     global $wgLanguageCode;
     $oldCode = $wgLanguageCode;
     $wgLanguageCode = 'fr';
     $result = new Result(array('title_en' => $languageTitle));
     $this->assertEquals($languageTitle, $result->getTitle(), 'A result should return the english language title field during getTitle() if it exists, but the non-english field doesn\'t (video support).');
     $wgLanguageCode = $oldCode;
 }