8f6b86b2c8a1eb541ac7112788e06d5721d5a704
3 require_once( 'MediaWiki_Setup.php' );
8 class SearchEngineTest
extends MediaWiki_Setup
{
12 function insertSearchData() {
13 $this->insertPage("Main_Page", "This is a main page", 0);
14 $this->insertPage('Main_Page', 'This is a talk page to the main page, see [[smithee]]', 1);
15 $this->insertPage('Smithee', 'A smithee is one who smiths. See also [[Alan Smithee]]', 0);
16 $this->insertPage('Smithee', 'This article sucks.', 1);
17 $this->insertPage('Unrelated_page', 'Nothing in this page is about the S word.', 0);
18 $this->insertPage('Another_page', 'This page also is unrelated.', 0);
19 $this->insertPage('Help', 'Help me!', 4);
20 $this->insertPage('Thppt', 'Blah blah', 0);
21 $this->insertPage('Alan_Smithee', 'yum', 0);
22 $this->insertPage('Pages', 'are food', 0);
23 $this->insertPage('DblPageOne', 'ABCDEF', 0);
24 $this->insertPage('DblPageTwo', 'ABCDE', 0);
25 $this->insertPage('DblPageTwoLow', 'abcde', 0);
28 function normalize( $text ) {
29 return strtolower(preg_replace("/[^[:alnum:] ]/", " ", $text));
32 function insertPage( $pageName, $text, $ns ) {
34 $this->db
->safeQuery( 'INSERT INTO ! (page_id,page_namespace,page_title,page_latest) VALUES (?,?,?,?)',
35 $this->db
->tableName( 'page' ), $this->count
, $ns, $pageName, $this->count
);
36 $this->db
->safeQuery( 'INSERT INTO ! (rev_id,rev_page) VALUES (?, ?)',
37 $this->db
->tableName( 'revision' ), $this->count
, $this->count
);
38 $this->db
->safeQuery( 'INSERT INTO ! (old_id,old_text) VALUES (?, ?)',
39 $this->db
->tableName( 'text' ), $this->count
, $text );
40 $this->db
->safeQuery( 'INSERT INTO ! (si_page,si_title,si_text) VALUES (?, ?, ?)',
41 $this->db
->tableName( 'searchindex' ), $this->count
,
42 $this->normalize( $pageName ), $this->normalize( $text ) );
45 function fetchIds( $results ) {
47 while( $row = $results->next() ) {
48 $matches[] = $row->getTitle()->getPrefixedText();
51 # Search is not guaranteed to return results in a certain order;
52 # sort them numerically so we will compare simply that we received
53 # the expected matches.
58 function testTextSearch() {
59 if( is_null( $this->db
) ) {
60 $this->markTestIncomplete( "Can't find a database to test with." );
64 $this->fetchIds( $this->search
->searchText( 'smithee' ) ),
65 "Plain search failed" );
68 function testTextPowerSearch() {
69 if( is_null( $this->db
) ) {
70 $this->markTestIncomplete( "Can't find a database to test with." );
72 $this->search
->setNamespaces( array( 0, 1, 4 ) );
78 $this->fetchIds( $this->search
->searchText( 'smithee' ) ),
79 "Power search failed" );
82 function testTitleSearch() {
83 if( is_null( $this->db
) ) {
84 $this->markTestIncomplete( "Can't find a database to test with." );
91 $this->fetchIds( $this->search
->searchTitle( 'smithee' ) ),
92 "Title search failed" );
95 function testTextTitlePowerSearch() {
96 if( is_null( $this->db
) ) {
97 $this->markTestIncomplete( "Can't find a database to test with." );
99 $this->search
->setNamespaces( array( 0, 1, 4 ) );
106 $this->fetchIds( $this->search
->searchTitle( 'smithee' ) ),
107 "Title power search failed" );