I've set up a static copy of the search index table to run on Larousse,
the web server, separately from the main database server, and modified
the wiki to run searches through it.
This is rather experimental, and I don't know if it'll remain smooth. If
it doesn't play nice, it'll get disabled again. For now this is a static
copy of the search index, so it won't automatically update with new
pages, changed pages etc. But, it's better than nothing and should be
more up to date than Google for the time being.
(I'd prefer to be running these sorts of things on a third machine,
capable of being a full live backup database server, but we don't yet
have one. Larousse does have plenty of free memory at the moment, so
stealing some to run a limited-purpose mysqld shouldn't hurt it too much
in the short term.)
Technical notes: the duplicate searchindex table has been modified to
include the cur_is_redirect and cur_namespace columns out of cur, since
these are used to narrow down the search. The modified search engine
grabs a series of matching page ID numbers out of the alternate
database, then grabs the current title and and contents from the real
cur table using the index numbers for just the matches that it needs to
display, which should be quite fast. I've also dropped the default
number of results per page from 20 to 10.
I haven't checked in these experimental changes to CVS; a diff to
SearchEngine.php is attached. Also slight change to
DatabaseFunctions.php to support more options to wfGetDB() but it
doesn't diff cleanly against the current version and I'm too tired to
sort it out right now.
-- brion vibber (brion @
pobox.com)
Index: SearchEngine.php
===================================================================
RCS file: /cvsroot/wikipedia/phase3/includes/SearchEngine.php,v
retrieving revision 1.12
diff -u -r1.12 SearchEngine.php
--- SearchEngine.php 13 Jul 2003 23:19:56 -0000 1.12
+++ SearchEngine.php 6 Aug 2003 11:28:29 -0000
@@ -170,27 +170,64 @@
$searchnamespaces = $this->queryNamespaces();
$redircond = $this->searchRedirects();
- $sql = "SELECT cur_id,cur_namespace,cur_title," .
- "cur_text FROM cur,searchindex " .
- "WHERE cur_id=si_page AND {$this->mTitlecond} " .
+ global $wgDBsearchServer, $wgDBsearchUser, $wgDBsearchPassword, $wgDBsearchName;
+ if( $wgDBsearchServer ) {
+ wfGetDB( $wgDBsearchUser, $wgDBsearchPassword, $wgDBsearchServer, $wgDBsearchName );
+ #$meep = mysql_connect( $wgDBsearchServer, $wgDBsearchUser, $wgDBsearchPassword );
+ #mysql_select_db( $wgDBsearchName, $meep );
+ }
+ $sql = "SELECT si_page " .
+ "FROM searchindex " .
+ "WHERE {$this->mTitlecond} " .
"{$searchnamespaces} {$redircond}" .
"LIMIT {$offset}, {$limit}";
- $res1 = wfQuery( $sql, $fname );
+ $res1 = wfQuery( $sql, $fname ); #FIXME
$num = wfNumRows($res1);
-
+
if ( $wgDisableTextSearch ) {
$res2 = 0;
+ $num2 = 0;
} else {
- $sql = "SELECT cur_id,cur_namespace,cur_title," .
- "cur_text FROM cur,searchindex " .
- "WHERE cur_id=si_page AND {$this->mTextcond} " .
+ $sql = "SELECT si_page " .
+ "FROM searchindex " .
+ "WHERE {$this->mTextcond} " .
"{$searchnamespaces} {$redircond} " .
"LIMIT {$offset}, {$limit}";
$res2 = wfQuery( $sql, $fname );
- $num = $num + wfNumRows($res2);
+ #$num = $num + wfNumRows($res2);
+ $num2 = wfNumRows( $res2 );
+ }
+ if( $wgDBsearchServer ) {
+ global $wgDBconnection;
+ $wgDBconnection = NULL;
+ wfGetDB();
}
- if ( $num == $limit ) {
+ if($num) {
+ $ids = array();
+ while( $s = wfFetchObject( $res1 ) ) {
+ array_push( $ids, $s->si_page );
+ }
+ $sql = "SELECT cur_id,cur_namespace,cur_title," .
+ "cur_text FROM cur " .
+ "WHERE cur_id IN (" . implode( ",", $ids ) . ")";
+ $res1 = wfQuery( $sql, $fname );
+ $num = wfNumRows( $res1 );
+ }
+ if($num2) {
+ $ids = array();
+ while( $s = wfFetchObject( $res2 ) ) {
+ array_push( $ids, $s->si_page );
+ }
+ $sql = "SELECT cur_id,cur_namespace,cur_title," .
+ "cur_text FROM cur " .
+ "WHERE cur_id IN (" . implode( ",", $ids ) . ")";
+ $res2 = wfQuery( $sql, $fname );
+ $num2 = wfNumRows( $res2 );
+ }
+ $num += $num2;
+
+ if ( $num == $limit ) {
$top = wfShowingResults( $offset, $limit);
} else {
$top = wfShowingResultsNum( $offset, $limit, $num );
@@ -415,7 +452,9 @@
$wgOut->redirect( wfLocalUrl( $wgTitle->getPrefixedURL() ) );
return;
}
+ $wgTitle = Title::newFromText( $search );
+ /*
# Try a near match
#
$this->parseQuery();
@@ -424,7 +463,8 @@
if ( "" != $this->mTitlecond ) {
$res = wfQuery( $sql, $fname );
- }
+ }
+ */
if ( isset( $res ) && 0 != wfNumRows( $res ) ) {
$s = wfFetchObject( $res );