49 private $latestPage =
null;
66 $services = MediaWikiServices::getInstance();
67 $config = $services->getSearchEngineConfig();
69 if ( $config->getConfig()->get( MainConfigNames::DisableSearchUpdate ) || !$this->id ) {
70 LoggerFactory::getInstance(
"search" )
71 ->debug(
"Skipping update: search updates disabled by config" );
75 $seFactory = $services->getSearchEngineFactory();
76 foreach ( $config->getSearchTypes() as $type ) {
77 $search = $seFactory->create( $type );
78 if ( !$search->
supports(
'search-update' ) ) {
82 $normalTitle = $this->getNormalizedTitle( $search );
84 if ( $this->getLatestPage() ===
null ) {
85 $search->
delete( $this->
id, $normalTitle );
87 } elseif ( $this->content ===
null ) {
92 $text = $this->content !==
null ? $this->content->getTextForSearchIndex() :
'';
95 # Perform the actual update
109 $services = MediaWikiServices::getInstance();
110 $contLang = $services->getContentLanguage();
111 # Language-specific strip/conversion
112 $text = $contLang->normalizeForSearch( $text );
113 $se = $se ?: $services->newSearchEngine();
114 $lc = $se->legalSearchChars() .
'&#;';
117 $text = preg_replace(
"/<\\/?\\s*[A-Za-z][^>]*?>/",
118 ' ', $contLang->lc(
" " . $text .
" " ) );
119 $text = preg_replace(
"/(^|\\n)==\\s*([^\\n]+)\\s*==(\\s)/",
120 "\\1\\2 \\2 \\2\\3", $text ); # Emphasize headings
122 # Strip external URLs
123 $uc =
"A-Za-z0-9_\\/:.,~%\\-+&;#?!=()@\\x80-\\xFF";
124 $protos =
"http|https|ftp|mailto|news|gopher";
125 $pat =
"/(^|[^\\[])({$protos}):[{$uc}]+([^{$uc}]|$)/";
126 $text = preg_replace( $pat,
"\\1 \\3", $text );
128 $p1 =
"/([^\\[])\\[({$protos}):[{$uc}]+]/";
129 $p2 =
"/([^\\[])\\[({$protos}):[{$uc}]+\\s+([^\\]]+)]/";
130 $text = preg_replace( $p1,
"\\1 ", $text );
131 $text = preg_replace( $p2,
"\\1 \\3 ", $text );
133 # Internal image links
134 $pat2 =
"/\\[\\[image:([{$uc}]+)\\.(gif|png|jpg|jpeg)([^{$uc}])/i";
135 $text = preg_replace( $pat2,
" \\1 \\3", $text );
137 $text = preg_replace(
"/([^{$lc}])([{$lc}]+)]]([a-z]+)/",
138 "\\1\\2 \\2\\3", $text ); # Handle [[game]]s
140 # Strip all remaining non-search characters
141 $text = preg_replace(
"/[^{$lc}]+/",
" ", $text );
159 $text = strrev( preg_replace(
"/ s'([{$lc}]+)/",
" s'\\1 \\1", strrev( $text ) ) );
160 $text = strrev( preg_replace(
"/ 's([{$lc}]+)/",
" s\\1", strrev( $text ) ) );
162 # Strip wiki '' and '''
163 $text = preg_replace(
"/''[']*/",
" ", $text );
177 private function getLatestPage() {
178 if ( !isset( $this->latestPage ) ) {
179 $this->latestPage = MediaWikiServices::getInstance()->getPageStore()
180 ->getPageById( $this->
id, PageStore::READ_LATEST );
183 return $this->latestPage;
193 private function getNormalizedTitle(
SearchEngine $search ) {
194 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
195 $ns = $this->page->getNamespace();
196 $title = str_replace(
'_',
' ', $this->page->getDBkey() );
199 $t = $contLang->normalizeForSearch( $title );
200 $t = preg_replace(
"/[^{$lc}]+/",
' ', $t );
201 $t = $contLang->lc( $t );
204 $t = preg_replace(
"/([{$lc}]+)'s( |$)/",
"\\1 \\1's ", $t );
205 $t = preg_replace(
"/([{$lc}]+)s'( |$)/",
"\\1s ", $t );
207 $t = preg_replace(
"/\\s+/",
' ', $t );
210 $t = preg_replace(
"/ (png|gif|jpg|jpeg|ogg)$/",
"", $t );
A class containing constants representing the names of configuration variables.
Contain a class for special pages.
delete( $id, $title)
Delete an indexed page Title should be pre-processed.
update( $id, $title, $text)
Create or update the search index record for the given page.
normalizeText( $string)
When overridden in derived class, performs database-specific conversions on text to be used for searc...
updateTitle( $id, $title)
Update a search index record's title only.
legalSearchChars( $type=self::CHARS_ALL)
Get chars legal for search.
Database independent search index updater.
updateText( $text, SearchEngine $se=null)
Clean text for indexing.
doUpdate()
Perform actual update for the entry.
__construct( $id, $page, ?Content $c=null)
Base interface for representing page content.
Interface that deferrable updates should implement.
Interface for objects (potentially) representing an editable wiki page.