public function testGetCategories()
 {
     $categories = ['Foo_bar' => 'Bar', 'New_page' => ''];
     $parserOutput = new ParserOutput('', [], $categories);
     $searchDataExtractor = new ParserOutputSearchDataExtractor();
     $this->assertEquals(['Foo bar', 'New page'], $searchDataExtractor->getCategories($parserOutput));
 }
Exemple #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;
 }