36 private $latestPage =
null;
54 $searchEngineConfig = $services->getSearchEngineConfig();
57 LoggerFactory::getInstance(
"search" )
58 ->debug(
"Skipping update: search updates disabled by config" );
62 $seFactory = $services->getSearchEngineFactory();
63 foreach ( $searchEngineConfig->getSearchTypes() as $type ) {
64 $search = $seFactory->create( $type );
65 if ( !$search->
supports(
'search-update' ) ) {
69 $normalTitle = $this->getNormalizedTitle( $search );
71 if ( $this->getLatestPage() ===
null ) {
72 $search->
delete( $this->
id, $normalTitle );
75 if ( $this->content ===
null ) {
80 $text = $this->content->getTextForSearchIndex();
83 # Perform the actual update
98 $contLang = $services->getContentLanguage();
99 # Language-specific strip/conversion
100 $text = $contLang->normalizeForSearch( $text );
101 $se = $se ?: $services->newSearchEngine();
102 $lc = $se->legalSearchChars() .
'&#;';
105 $text = preg_replace(
"/<\\/?\\s*[A-Za-z][^>]*?>/",
106 ' ', $contLang->lc(
" " . $text .
" " ) );
107 $text = preg_replace(
"/(^|\\n)==\\s*([^\\n]+)\\s*==(\\s)/",
108 "\\1\\2 \\2 \\2\\3", $text ); # Emphasize headings
110 # Strip external URLs
111 $uc =
"A-Za-z0-9_\\/:.,~%\\-+&;#?!=()@\\x80-\\xFF";
112 $protos =
"http|https|ftp|mailto|news|gopher";
113 $pat =
"/(^|[^\\[])({$protos}):[{$uc}]+([^{$uc}]|$)/";
114 $text = preg_replace( $pat,
"\\1 \\3", $text );
116 $p1 =
"/([^\\[])\\[({$protos}):[{$uc}]+]/";
117 $p2 =
"/([^\\[])\\[({$protos}):[{$uc}]+\\s+([^\\]]+)]/";
118 $text = preg_replace( $p1,
"\\1 ", $text );
119 $text = preg_replace( $p2,
"\\1 \\3 ", $text );
121 $text = preg_replace(
"/([^{$lc}])([{$lc}]+)]]([a-z]+)/",
122 "\\1\\2 \\2\\3", $text ); # Handle [[game]]s
124 # Strip all remaining non-search characters
125 $text = preg_replace(
"/[^{$lc}]+/",
" ", $text );
143 $text = strrev( preg_replace(
"/ s'([{$lc}]+)/",
" s'\\1 \\1", strrev( $text ) ) );
144 $text = strrev( preg_replace(
"/ 's([{$lc}]+)/",
" s\\1", strrev( $text ) ) );
146 # Strip wiki '' and '''
147 $text = preg_replace(
"/''[']*/",
" ", $text );
161 private function getLatestPage() {
162 if ( !$this->latestPage ) {
164 ->getPageById( $this->
id, IDBAccessObject::READ_LATEST );
167 return $this->latestPage;
177 private function getNormalizedTitle(
SearchEngine $search ) {
179 $title = Title::newFromPageIdentity( $this->page )->getText();
182 $t = $contLang->normalizeForSearch( $title );
183 $t = preg_replace(
"/[^{$lc}]+/",
' ', $t );
184 $t = $contLang->lc( $t );
186 if ( $this->page->getNamespace() ===
NS_FILE ) {
187 $t = preg_replace(
"/([{$lc}]+)\\.(\\w{1,4})$/",
"\\1 \\1.\\2", $t );
191 $t = preg_replace(
"/([{$lc}]+)'s( |$)/",
"\\1 \\1's ", $t );
192 $t = preg_replace(
"/([{$lc}]+)s'( |$)/",
"\\1s ", $t );
194 $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.