From 370e83bb0dfd0c70de268c93bf07ad5ee0897192 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Fri, 15 Aug 2008 01:29:47 +0200 Subject: Update auf 1.13.0 --- t/Search.inc | 165 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 t/Search.inc (limited to 't/Search.inc') diff --git a/t/Search.inc b/t/Search.inc new file mode 100644 index 00000000..fa8a8b97 --- /dev/null +++ b/t/Search.inc @@ -0,0 +1,165 @@ +isOpen() ) { + if ( !( stristr( $db->getSoftwareLink(), 'MySQL') && version_compare( $db->getServerVersion(), '4.1', '<' ) ) ) { + # Database that supports CREATE TABLE ... LIKE + foreach ($tables as $tbl) { + $newTableName = $db->tableName( $tbl ); + #$tableName = $oldPrefix . $tbl; + $tableName = $tbl; + $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName)"); + } + } else { + # Hack for MySQL versions < 4.1, which don't support + # "CREATE TABLE ... LIKE". Note that + # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0" + # would not create the indexes we need.... + foreach ($tables as $tbl) { + $res = $db->query("SHOW CREATE TABLE $tbl"); + $row = $db->fetchRow($res); + $create = $row[1]; + $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `' + . $wgDBprefix . '\\1`', $create); + if ($create === $create_tmp) { + # Couldn't do replacement + wfDie( "could not create temporary table $tbl" ); + } + $db->query($create_tmp); + } + + } + return $db; + } else { + // Something amiss + return null; + } +} + +class SearchEngineTest { + var $db, $search; + + function __construct( SearchEngine $search ){ + $this->search = $search; + $this->db = $this->search->db; + } + + function insertSearchData() { + $this->db->safeQuery( <<db->tableName( 'page' ) ); + $this->db->safeQuery( <<db->tableName( 'revision' ) ); + $this->db->safeQuery( <<db->tableName( 'text' ) ); + $this->db->safeQuery( <<db->tableName( 'searchindex' ) ); + } + + function fetchIds( $results ) { + $matches = array(); + while( $row = $results->next() ) { + $matches[] = $row->getTitle()->getPrefixedText(); + } + $results->free(); + # Search is not guaranteed to return results in a certain order; + # sort them numerically so we will compare simply that we received + # the expected matches. + sort( $matches ); + return $matches; + } + + function run(){ + if( is_null( $this->db ) ){ + fail( "Can't find a database to test with." ); + return; + } + + $this->insertSearchData(); + plan( 4 ); + + $exp = array( 'Smithee' ); + $got = $this->fetchIds( $this->search->searchText( 'smithee' ) ); + is( $got, $exp, "Plain search" ); + + $exp = array( 'Alan Smithee', 'Smithee' ); + $got = $this->fetchIds( $this->search->searchTitle( 'smithee' ) ); + is( $got, $exp, "Title search" ); + + $this->search->setNamespaces( array( 0, 1, 4 ) ); + + $exp = array( 'Smithee', 'Talk:Main Page', ); + $got = $this->fetchIds( $this->search->searchText( 'smithee' ) ); + is( $got, $exp, "Power search" ); + + $exp = array( 'Alan Smithee', 'Smithee', 'Talk:Smithee', ); + $got = $this->fetchIds( $this->search->searchTitle( 'smithee' ) ); + is( $got, $exp, "Title power search" ); + } +} \ No newline at end of file -- cgit v1.2.3-54-g00ecf