50 private $latestPage =
null;
68 $searchEngineConfig = $services->getSearchEngineConfig();
71 LoggerFactory::getInstance(
"search" )
72 ->debug(
"Skipping update: search updates disabled by config" );
76 $seFactory = $services->getSearchEngineFactory();
77 foreach ( $searchEngineConfig->getSearchTypes() as $type ) {
78 $search = $seFactory->create( $type );
79 if ( !$search->
supports(
'search-update' ) ) {
83 $normalTitle = $this->getNormalizedTitle( $search );
85 if ( $this->getLatestPage() ===
null ) {
86 $search->
delete( $this->
id, $normalTitle );
88 } elseif ( $this->content ===
null ) {
93 $text = $this->content !==
null ? $this->content->getTextForSearchIndex() :
'';
96 # Perform the actual update
111 $contLang = $services->getContentLanguage();
112 # Language-specific strip/conversion
113 $text = $contLang->normalizeForSearch( $text );
114 $se = $se ?: $services->newSearchEngine();
115 $lc = $se->legalSearchChars() .
'&#;';
118 $text = preg_replace(
"/<\\/?\\s*[A-Za-z][^>]*?>/",
119 ' ', $contLang->lc(
" " . $text .
" " ) );
120 $text = preg_replace(
"/(^|\\n)==\\s*([^\\n]+)\\s*==(\\s)/",
121 "\\1\\2 \\2 \\2\\3", $text ); # Emphasize headings
123 # Strip external URLs
124 $uc =
"A-Za-z0-9_\\/:.,~%\\-+&;#?!=()@\\x80-\\xFF";
125 $protos =
"http|https|ftp|mailto|news|gopher";
126 $pat =
"/(^|[^\\[])({$protos}):[{$uc}]+([^{$uc}]|$)/";
127 $text = preg_replace( $pat,
"\\1 \\3", $text );
129 $p1 =
"/([^\\[])\\[({$protos}):[{$uc}]+]/";
130 $p2 =
"/([^\\[])\\[({$protos}):[{$uc}]+\\s+([^\\]]+)]/";
131 $text = preg_replace( $p1,
"\\1 ", $text );
132 $text = preg_replace( $p2,
"\\1 \\3 ", $text );
134 $text = preg_replace(
"/([^{$lc}])([{$lc}]+)]]([a-z]+)/",
135 "\\1\\2 \\2\\3", $text ); # Handle [[game]]s
137 # Strip all remaining non-search characters
138 $text = preg_replace(
"/[^{$lc}]+/",
" ", $text );
156 $text = strrev( preg_replace(
"/ s'([{$lc}]+)/",
" s'\\1 \\1", strrev( $text ) ) );
157 $text = strrev( preg_replace(
"/ 's([{$lc}]+)/",
" s\\1", strrev( $text ) ) );
159 # Strip wiki '' and '''
160 $text = preg_replace(
"/''[']*/",
" ", $text );
174 private function getLatestPage() {
175 if ( !$this->latestPage ) {
177 ->getPageById( $this->
id, IDBAccessObject::READ_LATEST );
180 return $this->latestPage;
190 private function getNormalizedTitle(
SearchEngine $search ) {
192 $title = Title::newFromPageIdentity( $this->page )->getText();
195 $t = $contLang->normalizeForSearch( $title );
196 $t = preg_replace(
"/[^{$lc}]+/",
' ', $t );
197 $t = $contLang->lc( $t );
200 $t = preg_replace(
"/([{$lc}]+)'s( |$)/",
"\\1 \\1's ", $t );
201 $t = preg_replace(
"/([{$lc}]+)s'( |$)/",
"\\1s ", $t );
203 $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.
Content objects represent page content, e.g.
Interface for objects (potentially) representing an editable wiki page.