public function testGetOutgoingLinks()
 {
     $parserOutput = new ParserOutput();
     $parserOutput->addLink(Title::makeTitle(NS_MAIN, 'Foo_bar'), 1);
     $parserOutput->addLink(Title::makeTitle(NS_HELP, 'Contents'), 2);
     $searchDataExtractor = new ParserOutputSearchDataExtractor();
     // this indexes links with db key
     $this->assertEquals(['Foo_bar', 'Help:Contents'], $searchDataExtractor->getOutgoingLinks($parserOutput));
 }
Example #2
0
 /**
  * Return fields to be indexed by search engine
  * as representation of this document.
  * Overriding class should call parent function or take care of calling
  * the SearchDataForIndex hook.
  * @param WikiPage     $page Page to index
  * @param ParserOutput $output
  * @param SearchEngine $engine Search engine for which we are indexing
  * @return array Map of name=>value for fields
  * @since 1.28
  */
 public function getDataForSearchIndex(WikiPage $page, ParserOutput $output, SearchEngine $engine)
 {
     $fieldData = [];
     $content = $page->getContent();
     if ($content) {
         $searchDataExtractor = new ParserOutputSearchDataExtractor();
         $fieldData['category'] = $searchDataExtractor->getCategories($output);
         $fieldData['external_link'] = $searchDataExtractor->getExternalLinks($output);
         $fieldData['outgoing_link'] = $searchDataExtractor->getOutgoingLinks($output);
         $fieldData['template'] = $searchDataExtractor->getTemplates($output);
         $text = $content->getTextForSearchIndex();
         $fieldData['text'] = $text;
         $fieldData['source_text'] = $text;
         $fieldData['text_bytes'] = $content->getSize();
     }
     Hooks::run('SearchDataForIndex', [&$fieldData, $this, $page, $output, $engine]);
     return $fieldData;
 }