Help talk:Searching

Jump to: navigation, search
This message box is using an invalid "type=warning" parameter and needs fixing.

Phrase matching[edit]

Why doesn't the search support phrases? At the very least the search should return pages containing ALL the words first. The search functionality is inadequate.

At some point I plan to replace the Mediawiki built-in search with something that supports phrase matching. - 16:40, 10 April 2007

@ At the very least the search should return pages containing ALL the words first. - I definitely agree! Are there any workarounds?
does Lucene Search help? - Thanks for hints, -- Achimbode 10:02, 1 April 2009 (UTC)

change Stopwords?[edit]

is it possible, to change the stopwords on a local wiki? Where can I find the stopwordlist? -- 16:26, 26 April 2007 (UTC)

I found them in the file mysqld-opt.exe, but that does not seem to be directly editable.--Patrick 09:39, 29 April 2007 (UTC)

Wildcard Search[edit]

What is the recommended approach of adding wildcard search. E.g. I would like to get the following to work Rab* would return Rabbi, Rabbit, Rabbits etc.... Many thanks --Markw21 12:32, 8 May 2007 (UTC)

Yes, like that, rab*. The asterisk seems to work only at the end of a word.--Patrick 12:51, 8 May 2007 (UTC)
Thanks Patrick, but it does not seem to work for me, I specifically have a document called Outages, but when I search for Outage or Outage* it does not find the document. (Mediawiki 1.9.2, PHP 5.2.1, MySQL 5.0.37) --Markw21 12:54, 8 May 2007 (UTC)
I see now that you need to install the extension lucene search.--Patrick 15:40, 8 May 2007 (UTC)
Is there anyway I can get wildcard searching working without having to install lucene, c#, mono, mcs. There seems to be various different methods, and I would like to pick an 'easy', commonly adopted method, that will not be broken by future releases of mediawiki.
Yes! Create a new file in include/ named SearchMySQL4SubString.php with following content:
 * Search engine hook for MySQL 4+
 * @package MediaWiki
 * @subpackage Search

require_once( 'SearchEngine.php' );
require_once( 'SearchMySQL.php' );

 * @package MediaWiki
 * @subpackage Search
class SearchMySQL4SubString extends SearchMySQL {
      var $strictMatching = true;

      /** @todo document */
      function SearchMySQL4SubString( &$db ) {
            $this->db =& $db;

      function legalSearchChars() {
            return "A-Za-z_'0-9\\x80-\\xFF\\-*?+";

      /** @todo document */
      function parseQuery( $filteredText, $fulltext ) {
            global $wgContLang;
            $lc = SearchEngine::legalSearchChars();
            $searchon = '';
            $this->searchTerms = array();

            wfDebug( "parseQuery filteredText is: '$filteredText'\n" );
            wfDebug( "parseQuery fulltext is: '$fulltext'\n" );

            # FIXME: This doesn't handle parenthetical expressions.
            if( preg_match_all( '/([-+<>~]?)(([' . $lc .
                    $filteredText, $m, PREG_SET_ORDER ) ) {
                  foreach( $m as $terms ) {
                        if( $searchon !== '' ) $searchon .= ' ';
                        $searchon .= $terms[1] .
$wgContLang->stripForSearch( $terms[2] );
                        if( !empty( $terms[3] ) ) {
                              $regexp = preg_quote( $terms[3], '/' );
                              if( $terms[4] ) $regexp .= "[0-9A-Za-z_]+";
                        } else {
                              $regexp = preg_quote( str_replace( '"', '',
$terms[2] ), '/' );
                        $this->searchTerms[] = $regexp;
                  wfDebug( "Would search with '$searchon'\n" );
                  wfDebug( "Match with /\b" . implode( '\b|\b',
$this->searchTerms ) . "\b/\n" );
            } else {
                  wfDebug( "Can't understand search query
'{$this->filteredText}'\n" );

            $searchon = $this->db->strencode( $searchon );
            $field = $this->getIndexField( $fulltext );
            return " MATCH($field) AGAINST('$searchon' IN BOOLEAN MODE) ";
Then add following lines in your LocalSettings.php
require_once( 'SearchMySQL4SubString.php' );
$wgSearchType = 'SearchMySQL4SubString';
And yes, it works with MySQL5 :)

-- 09:52, 10 May 2007 (UTC)

Many thanks that works great, if there anyway to get it to always add the *, so the user wouldn't have to? --Markw21 11:43, 10 May 2007 (UTC)

Oh yes, you can change the function searchText in the SearchMySQL.php like that
        function searchText( $term ) {
                $resultSet = $this->db->resultObject( $this->db->query( $this->getQuery( $this->filter( $term ).'*', true ) ) );
                return new MySQLSearchResultSet( $resultSet, $this->searchTerms );
So the * is in the sourcecode and doesn't need to be inserted manually.
-- 12:27, 10 May 2007 (UTC)

Automagically add wildcard to mediawiki search 1.18[edit]

I changed the following line in SearchMySQL.php:

return $this->searchInternal( $term, true );


return $this->searchInternal( $term.'*', true );

I hope this info may be helpful to someone. 23:47, 28 March 2013 (UTC)

It might be better to do this addendum of asterisk inside the searchInternal function itself, right after the line "if ( trim( $term ) === ) return null;":
$term = $term . '*';

Automagically add wildcard to mediawiki search 1.22[edit]

In Mediawiki 1.22 you have to change the Lines 184 - 186 from:
if ( trim( $term ) === '' ) {
return null;
if ( trim( $term ) === '' ) {
return null;
} else {
$term = $term . '*';
This works great for me on 1.24.2
        protected function searchInternal( $term, $fulltext ) {
                // This seems out of place, why is this called with empty term?
                if ( trim( $term ) === '' ) {
                        return null;
                        $term2 = $term . '*';
                        $term2 = str_replace(' ', '* *', $term2);
                        $term .= ' '.$term2;

Searchresults - jump to result by link[edit]

Is it possible to jump directly to a result found in a text? For example: I search for "computer", my result is a page where "computer" appears 200 times. The result I need is in line 1534. Can mediawiki create a link direct to this line in the text? -- 10:12, 10 May 2007 (UTC)

This would be nice for page history differences that involve particular sections; having direct links to the section(s) would be nice instead of having to scroll down on particularly long pages (like talk pages) in order to see the actual text. -Eep² 03:19, 25 July 2007 (UTC)

Blank page after upgrade to 1.10[edit]

after upgrading to v1.10, this code gives me php errors and a blank page.

The error I get is:

 [17-May-2007 13:07:34] PHP Fatal error:  Cannot make static method SearchEngine::legalSearchChars() non static in class   
 SearchMySQL4SubString in C:\www\doc\includes\SearchMySQL4SubString.php on line 15

anyone know how to fix this? --Dingfelder 01:10, 17 May 2007 (UTC)

is there really a SearchMySQL4SubString.php in your include dir? this php is no standard and maybe you have to ceate it on your own -- 06:40, 21 May 2007 (UTC)
please read the instructions above for adding the wild card search... they specify to create this file and show it's contents. The reason I am posting is this code is now causing the problem after the upgrade --Dingfelder 05:15, 22 May 2007 (UTC)

I do not really know, why it works, but it works on my wiki (1.10) after changing the line (in the extension)

function legalSearchChars() {


public static function legalSearchChars() {
Thx, that made it work on 1.12 -- 13:06, 24 February 2011 (UTC)

Update for 1.1X[edit]

It's also working with 1.11 :) Thank you work that great work!!!

Line 23: "function legalSearchChars() {" -> "public static function legalSearchChars() {"

-- 13:42, 27 September 2007 (UTC)

Search for short word or abbreviations[edit]

Is it possible to make search also search world like "lvm". I got one article with word lvm in it but it gives me 0 results. However when I search for "logical" I get desired page. I'm 100% sure that everyone will search lvm not "logical volume manager". thank you

you could/should use redirects for that -- 13:07, 24 February 2011 (UTC)

3 character search?[edit]

I have just discovered that the search function does not give any results on words that have less than 4 characters. Is there a way to change that?

Hans Telgen 07:27, 6 July 2007 (UTC)

The answer is in the FAQ here. 14:32, 25 July 2007 (UTC)
To me, that FAQ entry raises more questions than it answers. It seems to suggest that possibility that only "older versions of MediaWiki" are affected. Actually I can add further evidence for this possibility; I am an end user on a site running MediaWiki 1.21.1 and I do not face the 4 character minimum. I assume these help pages are only supposed to document the latest version of MediaWiki, so we should not add anything to Help:Searching about this matter. Open4D (talk) 13:10, 15 November 2013 (UTC)

Search statistics[edit]

Is there a way to see what users are searching for? Some kind of statistics. thank you

eek! would be awesome. --Subfader 09:11, 9 April 2008 (UTC)

Searching for Words with ä, ö and ü in it[edit]

We do administrate a German wiki using the MediaWiki-Software. When we post articles with the letters Ä, Ö or Ü in the title the search ever show an Error: "Ungültiger Titel". How can I fix this? --Ulli1105 10:33, 12 February 2008 (UTC)

[RESOLVED] Go for other namespaces[edit]

I'd like the Go feature working for other namespaces, e.g. I enter "House" the Go button will take me to Category:House (if exists).
It could be combined with the ns you define as default in your user prefs. --Subfader 19:51, 28 February 2008 (UTC)

Solved for me by: Extension talk:GoToCategory --Subfader 09:10, 9 April 2008 (UTC)

Quote problems[edit]

While I search for something like "O'Leary" it'll end up with 404 page :( Has anyone a fix for the quote ( ' ), so that it won't break my Mediawiki?

search ranking?[edit]

What is the ranking algorithm used in default mediawiki search, to display the search result? --Ans 10:40, 25 February 2009 (UTC)

By default mediawiki uses mysql fulltext search, which uses ranking only for multiple words searches, afaik. --Rainman 16:51, 25 February 2009 (UTC)
But the ranking is odd. When search multiple words the results seem to be very useless. Example: this is useful includes a result three issues: , followed by to it. This is not a g. Nowhere are the 3 words in that order found as phrase. Shouldn't the first results be the same as if you searched in quotes? "this is useful" --Subfader 12:44, 22 March 2009 (UTC)
Please note that uses an earlier (and outdated) version of Extension:lucene-search because of pending hardware issue. If you have suggestion/comments about search ranking please refer to the latest lucene-search version as used on en, fr, de, es, pt, .. etc wiki ([1]). --Rainman 15:35, 22 March 2009 (UTC)
On a more general note, there are (at least) two type of queries: keywords and phrases. Your example is a phrase query, and it is appropriate to have the phrase be the first hit. However, for keyword queries (e.g. douglas adams book) one doesn't want to get an irrelevant article where those three words happen to be next to each other as a first hit. Of course, it is impossible to distinguish these two in all cases, so the search engine need to come up with smart ways of combining best results for both. --Rainman 15:39, 22 March 2009 (UTC)

search problems[edit]

Is there a way to search for a few letters in a word and wiki gives thw whole word? e.g. I type to the searchbox "wiki" and the wohle word in a article is "Mediawiki". If i search for "Media*" then i'll get "Mediawiki" but i like to search for "*wiki" or only "wiki". Hope you understand what i mean. (23.02.2010) — Preceding unsigned comment added by (talkcontribs)


I searched "Dogs" on my wiki and got no results, even though I have a file named "R3 Dogs.png". This is definitely a problem, as searches should lead to what they are.-- 00:52, 29 September 2010 (UTC)

Go / Search[edit]

The wording of this article needs to change to describe current (beta Vector) functionality for Searching - there are no Go / Search buttons anymore so this doesn't describe current mediawiki version functionality. Superman57 23:00, 25 January 2011 (UTC)

Disregard that page change I made please, I edited the wrong site. :/

Only searching for exact results - Why?[edit]

When I use the search function I never get any results at all, except when I search for the exact name of the article. However I would like the search to display every article related to the search word. E.g. when I search "game" I would like to be shown all articles that have the words "game", "games" and similar in the title. The only thing I get it suggestions to create an article called "game" in this case. Can anybody please explain in "beginners" terms how I can change that? Thank you :) --MeikKebza 17:41, 09 June 2011

I'm experiencing the same problem, only the exact wording result, puzzling... any solution? --Sunjizu (talk) 17:23, 25 July 2014 (UTC)
Sunjizu, can you provide a specific word you are searching for and the existing pages that are present but not being found? It might be related to:
  • the 3 letter short indexing limitation or
  • short word list.
  • spaces or underscores in the string
Sunjizu, If you click on the Search glass icon without any search term entered, you will be presented with a screen to enter your search term like "game". The results you get back will include pages named game and other pages with the name game in them.

Title search on namespaces besides Main[edit]

Currently if i search my wiki it shows all of the name spaces checked off on the page text search but it only returns page title matches from the Main namespace. Is there some way that i can can select which namespaces, or all namespaces, for searching for page title matches? Caile13

Using quotations to match phrases?[edit]

Is it possible to search for phrases like the following, "simple phrase". It doesn't seem to work at all.

I know this was asked above, but no one provided an answer (and this was from 2009!). It'd be awesome if there was a way to do this.

-- Dana (24sep2012)

The search is not case-sensitive, so "MediaWiki", "mediawiki" and "MEDIAWIKI" all give the same result.[edit]

What? Since when? I was pretty sure Extension:TitleKey was required for that. Please confirm. If this is now core functionality, please indicate in which version this was implemented; I have searched the last 8 or so versions' release notes and I find nothing. Thanks!

--Mathieu ottawa (talk) 13:26, 10 December 2012 (UTC)

Yes, that's probably a mistake. --Nemo 13:27, 30 December 2013 (UTC)
Or maybe now (version 1.25wmf18 (2c93d82) 2015-02-19T02:47:27) it is case insensitive? For example a search for $wgvectorusesimplesearch brings up a page with the term in mixed case. I have my own Mediawiki version 1.23 and am continually confused over some results sometimes. For example, a search for "done" gets no hits, even though there are pages with "done" on it. If anyone can provide clarity on this it would be much appreciated. Kmacdowe (talk) 19:41, 20 February 2015 (UTC)

Include search results in wiki page[edit]

Is it possible to include search result in a normal wiki page (instead of Special:Search), alternatively customize the search result page?

What I would like to include a search box (e.g. using the InputBox extension) and show the results in the same page (i.e. reload the page and replace part of the page with the search results)

Searching the File Namespace[edit]

I noticed that files with numbers in there names can not be searched. Example:

  • Page name : A1
  • File name : A1.xls

When you search in "everything" with A1 there is only one hit on the page with that name, there is no hit on the file.

When there is no number in the file name like:

  • Page name : A
  • File name : A.xls

Now when searching for A in "everything" produces hits for both.

When you generate a page and file name with a space in between both like:

  • Page name : A 1
  • File name : A 1.xls

When searching in "everything" with A produces hits in both but when searched with 1, only the page gets a hit.

This means that the File: namespace can't be searched with numbers. Is this correct? Maybe there is a very plausible explanation for this but I am not able to find it until now. Is there a solution for this? Tested on a clean (default) MW 1.20.2, PHP 5.3.8 & MySQL 5.5.19 install on Apache. Any comments are welcome. Regards --Jongfeli (talk) 10:30, 4 March 2013 (UTC)

Sources of info[edit]

Is anyone aware of any 'technical' documentation about the search functionality? This would enable us to enhance the 'non-technical' article we are currently talking about (Help:Searching). I have submitted an edit to the article, but I have to admit it is just based on trial & error with one particular wiki. I had a look myself for 'technical' documentation, but didn't find any. What I did find was this page at Meta Wiki which might be useful for some people - although remember please don't just copy the text from there to here, because it is not public domain (see Project:PD help#License) - and also it assumes "lucene search".

I suppose there may be just too much variety 'out in the wild' of how administrators have configured their MediaWiki wikis for us ever to make this Help:Searching article really useful for a decent proportion of users. But a lot of wiki users are quite technically-minded (or at least have a friend/colleague who is), so I wonder whether 'technical' documentation might be the best prospect when it comes to MediaWiki search functionality. Open4D (talk) 12:58, 18 November 2013 (UTC)

I too would like to see a detailed page on how the search functions. Limit the discussion to a standard LAMP install if necessary. I see all kind of odd results on my work wiki and I cannot explain them sometimes. Kmacdowe (talk) 19:46, 20 February 2015 (UTC)

Questions not currently covered[edit]

This section can be for questions not currently covered by the article (whose answers would potentially be useful in the article).

  • What happens when the user's search term contains a hyphenated word? (In my case, searching for wordone-wordtwo returns more results than searching for wordone wordtwo. If that's the normal behaviour, this page should explain it.) Open4D (talk) 13:48, 18 November 2013 (UTC)

Last changes[edit]

Please check last change of introduction. No objection? I want to mark this page for translation. --Kaganer (talk) 15:13, 25 November 2013 (UTC)

Search in Title[edit]

Is it possible to search in Titles, without installing an extention? Is it possible to set the word i am searching for to bold in the results? Thx for your answers!

Titles are searched in 1.23 and later I believe. Kmacdowe (talk) 20:33, 20 February 2015 (UTC)

Auto redirect to the first result?[edit]

What would be the query to show the page that would be the first in the list of search results without displaying the search page?Gleki.arxokuna (talk) 14:08, 17 October 2014 (UTC)

Should the article indicate version?[edit]

Over time the search functions for Mediawiki (MW) have changed but there is no indication of what version MW is being described. If the assumption is the latest version, that should be stated, correct? Kmacdowe (talk) 20:31, 20 February 2015 (UTC)