3 * Contain a class for special pages
14 var $searchTerms = array();
15 var $namespaces = array( 0 );
16 var $showRedirects = false;
19 * Perform a full text search query and return a result set.
20 * If title searches are not supported or disabled, return null.
22 * @param string $term - Raw search term
23 * @return SearchResultSet
27 function searchText( $term ) {
32 * Perform a title-only search query and return a result set.
33 * If title searches are not supported or disabled, return null.
35 * @param string $term - Raw search term
36 * @return SearchResultSet
40 function searchTitle( $term ) {
45 * If an exact title match can be find, or a very slightly close match,
46 * return the title. If no match, returns NULL.
53 function getNearMatch( $term ) {
54 # Exact match? No need to look further.
55 $title = Title
::newFromText( $term );
59 if ( $title->getNamespace() == NS_SPECIAL ||
$title->exists() ) {
63 # Now try all lower case (i.e. first letter capitalized)
65 $title = Title
::newFromText( strtolower( $term ) );
66 if ( $title->exists() ) {
70 # Now try capitalized string
72 $title = Title
::newFromText( ucwords( strtolower( $term ) ) );
73 if ( $title->exists() ) {
77 # Now try all upper case
79 $title = Title
::newFromText( strtoupper( $term ) );
80 if ( $title->exists() ) {
84 $title = Title
::newFromText( $term );
86 # Entering an IP address goes to the contributions page
87 if ( ( $title->getNamespace() == NS_USER
&& User
::isIP($title->getText() ) )
88 || User
::isIP( trim( $term ) ) ) {
89 return Title
::makeTitle( NS_SPECIAL
, "Contributions/" . $title->getDbkey() );
93 # Entering a user goes to the user page whether it's there or not
94 if ( $title->getNamespace() == NS_USER
) {
98 # Quoted term? Try without the quotes...
99 if( preg_match( '/^"([^"]+)"$/', $term, $matches ) ) {
100 return SearchEngine
::getNearMatch( $matches[1] );
106 function legalSearchChars() {
107 return "A-Za-z_'0-9\\x80-\\xFF\\-";
111 * Set the maximum number of results to return
112 * and how many to skip before returning the first.
118 function setLimitOffset( $limit, $offset = 0 ) {
119 $this->limit
= IntVal( $limit );
120 $this->offset
= IntVal( $offset );
124 * Set which namespaces the search should include.
125 * Give an array of namespace index numbers.
127 * @param array $namespaces
130 function setNamespaces( $namespaces ) {
131 $this->namespaces
= $namespaces;
135 * Make a list of searchable namespaces and their canonical names.
139 function searchableNamespaces() {
142 foreach( $wgContLang->getNamespaces() as $ns => $name ) {
143 if( $ns >= NS_MAIN
) {
151 * Return a 'cleaned up' search string
156 function filter( $text ) {
157 $lc = $this->legalSearchChars();
158 return trim( preg_replace( "/[^{$lc}]/", " ", $text ) );
161 * Load up the appropriate search engine class for the currently
162 * active database backend, and return a configured instance.
164 * @return SearchEngine
168 global $wgDBtype, $wgDBmysql4, $wgSearchType;
169 if( $wgSearchType ) {
170 $class = $wgSearchType;
171 } elseif( $wgDBtype == 'mysql' ) {
173 $class = 'SearchMySQL4';
174 require_once( 'SearchMySQL4.php' );
176 $class = 'SearchMysql3';
177 require_once( 'SearchMySQL3.php' );
179 } else if ( $wgDBtype == 'PostgreSQL' ) {
180 $class = 'SearchTsearch2';
181 require_once( 'SearchTsearch2.php' );
183 $class = 'SearchEngineDummy';
185 $search = new $class( wfGetDB( DB_SLAVE
) );
186 $search->setLimitOffset(0,0);
191 * Create or update the search index record for the given page.
192 * Title and text should be pre-processed.
195 * @param string $title
196 * @param string $text
199 function update( $id, $title, $text ) {
204 * Update a search index record's title only.
205 * Title should be pre-processed.
208 * @param string $title
211 function updateTitle( $id, $title ) {
216 class SearchResultSet
{
218 * Fetch an array of regular expression fragments for matching
219 * the search terms as parsed by this engine in a text extract.
225 function termMatches() {
234 * Return true if results are included in this result set.
238 function hasResults() {
243 * Some search modes return a total hit count for the query
244 * in the entire article database. This may include pages
245 * in namespaces that would not be matched on the given
248 * Return null if no total hits number is supported.
253 function getTotalHits() {
258 * Some search modes return a suggested alternate term if there are
259 * no exact hits. Returns true if there is one on this set.
264 function hasSuggestion() {
269 * Some search modes return a suggested alternate term if there are
270 * no exact hits. Check hasSuggestion() first.
275 function getSuggestion() {
280 * Fetches next search result, or false.
281 * @return SearchResult
291 function SearchResult( $row ) {
292 $this->mTitle
= Title
::makeTitle( $row->page_namespace
, $row->page_title
);
299 function getTitle() {
300 return $this->mTitle
;
304 * @return double or null if not supported
306 function getScore() {
314 class SearchEngineDummy
{
315 function search( $term ) {