51 private $latestPage =
null;
69 $searchEngineConfig = $services->getSearchEngineConfig();
72 LoggerFactory::getInstance(
"search" )
73 ->debug(
"Skipping update: search updates disabled by config" );
77 $seFactory = $services->getSearchEngineFactory();
78 foreach ( $searchEngineConfig->getSearchTypes() as $type ) {
79 $search = $seFactory->create( $type );
80 if ( !$search->
supports(
'search-update' ) ) {
84 $normalTitle = $this->getNormalizedTitle( $search );
86 if ( $this->getLatestPage() ===
null ) {
87 $search->
delete( $this->
id, $normalTitle );
89 } elseif ( $this->content ===
null ) {
94 $text = $this->content !==
null ? $this->content->getTextForSearchIndex() :
'';
97 # Perform the actual update
112 $contLang = $services->getContentLanguage();
113 # Language-specific strip/conversion
114 $text = $contLang->normalizeForSearch( $text );
115 $se = $se ?: $services->newSearchEngine();
116 $lc = $se->legalSearchChars() .
'&#;';
119 $text = preg_replace(
"/<\\/?\\s*[A-Za-z][^>]*?>/",
120 ' ', $contLang->lc(
" " . $text .
" " ) );
121 $text = preg_replace(
"/(^|\\n)==\\s*([^\\n]+)\\s*==(\\s)/",
122 "\\1\\2 \\2 \\2\\3", $text ); # Emphasize headings
124 # Strip external URLs
125 $uc =
"A-Za-z0-9_\\/:.,~%\\-+&;#?!=()@\\x80-\\xFF";
126 $protos =
"http|https|ftp|mailto|news|gopher";
127 $pat =
"/(^|[^\\[])({$protos}):[{$uc}]+([^{$uc}]|$)/";
128 $text = preg_replace( $pat,
"\\1 \\3", $text );
130 $p1 =
"/([^\\[])\\[({$protos}):[{$uc}]+]/";
131 $p2 =
"/([^\\[])\\[({$protos}):[{$uc}]+\\s+([^\\]]+)]/";
132 $text = preg_replace( $p1,
"\\1 ", $text );
133 $text = preg_replace( $p2,
"\\1 \\3 ", $text );
135 $text = preg_replace(
"/([^{$lc}])([{$lc}]+)]]([a-z]+)/",
136 "\\1\\2 \\2\\3", $text ); # Handle [[game]]s
138 # Strip all remaining non-search characters
139 $text = preg_replace(
"/[^{$lc}]+/",
" ", $text );
157 $text = strrev( preg_replace(
"/ s'([{$lc}]+)/",
" s'\\1 \\1", strrev( $text ) ) );
158 $text = strrev( preg_replace(
"/ 's([{$lc}]+)/",
" s\\1", strrev( $text ) ) );
160 # Strip wiki '' and '''
161 $text = preg_replace(
"/''[']*/",
" ", $text );
175 private function getLatestPage() {
176 if ( !$this->latestPage ) {
178 ->getPageById( $this->
id, IDBAccessObject::READ_LATEST );
181 return $this->latestPage;
191 private function getNormalizedTitle(
SearchEngine $search ) {
193 $title = Title::newFromPageIdentity( $this->page )->getText();
196 $t = $contLang->normalizeForSearch( $title );
197 $t = preg_replace(
"/[^{$lc}]+/",
' ', $t );
198 $t = $contLang->lc( $t );
201 $t = preg_replace(
"/([{$lc}]+)'s( |$)/",
"\\1 \\1's ", $t );
202 $t = preg_replace(
"/([{$lc}]+)s'( |$)/",
"\\1s ", $t );
204 $t = preg_replace(
"/\\s+/",
' ', $t );
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.