public function testGetTemplates() { $title = Title::makeTitle(NS_TEMPLATE, 'Cite_news'); $parserOutput = new ParserOutput(); $parserOutput->addTemplate($title, 10, 100); $searchDataExtractor = new ParserOutputSearchDataExtractor(); $this->assertEquals(['Template:Cite news'], $searchDataExtractor->getTemplates($parserOutput)); }
/** * 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; }