53 private $latestPage =
null;
71 $searchEngineConfig = $services->getSearchEngineConfig();
74 LoggerFactory::getInstance(
"search" )
75 ->debug(
"Skipping update: search updates disabled by config" );
79 $seFactory = $services->getSearchEngineFactory();
80 foreach ( $searchEngineConfig->getSearchTypes() as $type ) {
81 $search = $seFactory->create( $type );
82 if ( !$search->
supports(
'search-update' ) ) {
86 $normalTitle = $this->getNormalizedTitle( $search );
88 if ( $this->getLatestPage() ===
null ) {
89 $search->
delete( $this->
id, $normalTitle );
91 } elseif ( $this->content ===
null ) {
96 $text = $this->content !==
null ? $this->content->getTextForSearchIndex() :
'';
99 # Perform the actual update
114 $contLang = $services->getContentLanguage();
115 # Language-specific strip/conversion
116 $text = $contLang->normalizeForSearch( $text );
117 $se = $se ?: $services->newSearchEngine();
118 $lc = $se->legalSearchChars() .
'&#;';
121 $text = preg_replace(
"/<\\/?\\s*[A-Za-z][^>]*?>/",
122 ' ', $contLang->lc(
" " . $text .
" " ) );
123 $text = preg_replace(
"/(^|\\n)==\\s*([^\\n]+)\\s*==(\\s)/",
124 "\\1\\2 \\2 \\2\\3", $text ); # Emphasize headings
126 # Strip external URLs
127 $uc =
"A-Za-z0-9_\\/:.,~%\\-+&;#?!=()@\\x80-\\xFF";
128 $protos =
"http|https|ftp|mailto|news|gopher";
129 $pat =
"/(^|[^\\[])({$protos}):[{$uc}]+([^{$uc}]|$)/";
130 $text = preg_replace( $pat,
"\\1 \\3", $text );
132 $p1 =
"/([^\\[])\\[({$protos}):[{$uc}]+]/";
133 $p2 =
"/([^\\[])\\[({$protos}):[{$uc}]+\\s+([^\\]]+)]/";
134 $text = preg_replace( $p1,
"\\1 ", $text );
135 $text = preg_replace( $p2,
"\\1 \\3 ", $text );
137 # Internal image links
138 $pat2 =
"/\\[\\[image:([{$uc}]+)\\.(gif|png|jpg|jpeg)([^{$uc}])/i";
139 $text = preg_replace( $pat2,
" \\1 \\3", $text );
141 $text = preg_replace(
"/([^{$lc}])([{$lc}]+)]]([a-z]+)/",
142 "\\1\\2 \\2\\3", $text ); # Handle [[game]]s
144 # Strip all remaining non-search characters
145 $text = preg_replace(
"/[^{$lc}]+/",
" ", $text );
163 $text = strrev( preg_replace(
"/ s'([{$lc}]+)/",
" s'\\1 \\1", strrev( $text ) ) );
164 $text = strrev( preg_replace(
"/ 's([{$lc}]+)/",
" s\\1", strrev( $text ) ) );
166 # Strip wiki '' and '''
167 $text = preg_replace(
"/''[']*/",
" ", $text );
181 private function getLatestPage() {
182 if ( !isset( $this->latestPage ) ) {
184 ->getPageById( $this->
id, IDBAccessObject::READ_LATEST );
187 return $this->latestPage;
197 private function getNormalizedTitle(
SearchEngine $search ) {
199 $ns = $this->page->getNamespace();
200 $title = str_replace(
'_',
' ', $this->page->getDBkey() );
203 $t = $contLang->normalizeForSearch( $title );
204 $t = preg_replace(
"/[^{$lc}]+/",
' ', $t );
205 $t = $contLang->lc( $t );
208 $t = preg_replace(
"/([{$lc}]+)'s( |$)/",
"\\1 \\1's ", $t );
209 $t = preg_replace(
"/([{$lc}]+)s'( |$)/",
"\\1s ", $t );
211 $t = preg_replace(
"/\\s+/",
' ', $t );
214 $t = preg_replace(
"/ (png|gif|jpg|jpeg|ogg)$/",
"", $t );
222class_alias( SearchUpdate::class,
'SearchUpdate' );
A class containing constants representing the names of configuration variables.
const DisableSearchUpdate
Name constant for the DisableSearchUpdate setting, for use with Config::get()
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.
Base interface for representing page content.
Interface for objects (potentially) representing an editable wiki page.