13 /* private */ var $mId = 0, $mNamespace, $mTitle, $mText;
14 /* private */ var $mTitleWords;
16 function SearchUpdate( $id, $title, $text = false ) {
17 $nt = Title
::newFromText( $title );
22 $this->mNamespace
= $nt->getNamespace();
23 $this->mTitle
= $nt->getText(); # Discard namespace
25 $this->mTitleWords
= $this->mTextWords
= array();
27 wfDebug( "SearchUpdate object created with invalid title '$title'\n" );
32 global $wgContLang, $wgDisableSearchUpdate;
34 if( $wgDisableSearchUpdate ||
!$this->mId
) {
37 $fname = 'SearchUpdate::doUpdate';
38 wfProfileIn( $fname );
40 $search = SearchEngine
::create();
41 $lc = $search->legalSearchChars() . '&#;';
43 if( $this->mText
=== false ) {
44 $search->updateTitle($this->mId
,
45 Title
::indexTitle( $this->mNamespace
, $this->mTitle
));
46 wfProfileOut( $fname );
50 # Language-specific strip/conversion
51 $text = $wgContLang->stripForSearch( $this->mText
);
53 wfProfileIn( $fname.'-regexps' );
54 $text = preg_replace( "/<\\/?\\s*[A-Za-z][A-Za-z0-9]*\\s*([^>]*?)>/",
55 ' ', strtolower( " " . $text /*$this->mText*/ . " " ) ); # Strip HTML markup
56 $text = preg_replace( "/(^|\\n)==\\s*([^\\n]+)\\s*==(\\s)/sD",
57 "\\1\\2 \\2 \\2\\3", $text ); # Emphasize headings
60 $uc = "A-Za-z0-9_\\/:.,~%\\-+&;#?!=()@\\xA0-\\xFF";
61 $protos = "http|https|ftp|mailto|news|gopher";
62 $pat = "/(^|[^\\[])({$protos}):[{$uc}]+([^{$uc}]|$)/";
63 $text = preg_replace( $pat, "\\1 \\3", $text );
65 $p1 = "/([^\\[])\\[({$protos}):[{$uc}]+]/";
66 $p2 = "/([^\\[])\\[({$protos}):[{$uc}]+\\s+([^\\]]+)]/";
67 $text = preg_replace( $p1, "\\1 ", $text );
68 $text = preg_replace( $p2, "\\1 \\3 ", $text );
70 # Internal image links
71 $pat2 = "/\\[\\[image:([{$uc}]+)\\.(gif|png|jpg|jpeg)([^{$uc}])/i";
72 $text = preg_replace( $pat2, " \\1 \\3", $text );
74 $text = preg_replace( "/([^{$lc}])([{$lc}]+)]]([a-z]+)/",
75 "\\1\\2 \\2\\3", $text ); # Handle [[game]]s
77 # Strip all remaining non-search characters
78 $text = preg_replace( "/[^{$lc}]+/", " ", $text );
82 # $text = preg_replace( "/([{$lc}]+)'s /", "\\1 \\1's ", $text );
83 # $text = preg_replace( "/([{$lc}]+)s' /", "\\1s ", $text );
85 # These tail-anchored regexps are insanely slow. The worst case comes
86 # when Japanese or Chinese text (ie, no word spacing) is written on
87 # a wiki configured for Western UTF-8 mode. The Unicode characters are
88 # expanded to hex codes and the "words" are very long paragraph-length
89 # monstrosities. On a large page the above regexps may take over 20
90 # seconds *each* on a 1GHz-level processor.
92 # Following are reversed versions which are consistently fast
93 # (about 3 milliseconds on 1GHz-level processor).
95 $text = strrev( preg_replace( "/ s'([{$lc}]+)/", " s'\\1 \\1", strrev( $text ) ) );
96 $text = strrev( preg_replace( "/ 's([{$lc}]+)/", " s\\1", strrev( $text ) ) );
98 # Strip wiki '' and '''
99 $text = preg_replace( "/''[']*/", " ", $text );
100 wfProfileOut( "$fname-regexps" );
101 $search->update($this->mId
, Title
::indexTitle( $this->mNamespace
, $this->mTitle
),
103 wfProfileOut( $fname );
111 class SearchUpdateMyISAM
extends SearchUpdate
{
112 # Inherits everything