1. Add a document
$xs=NewXS (' NJW ');$index=$xs-index;$data=Array(' pid ' = 234,//This field is the primary key and you must specify' Subject ' = ' The title of the test document ', ' message ' = ' content part of the test document ', ' chrono ' = Time());//Create a Document object$doc=Newxsdocument;$doc->setfields ($data);?//Add to index database$index->add ($doc);
2. Update the document
// Create a Document object $doc New xsdocument; $doc->setfields ($data); // Update to the index database $index->update ($doc);
3. Smooth Batch Rebuild update index
Header(' Content-type:text/html;charset=utf-8; '));require_once‘.. /.. /.. /local/xunsearch/sdk/php/lib/xs.php ';include"./mysql_conn.php";Try{$xs=NewXS (' NJW ');//Smooth Rebuild Index//Announce start rebuilding index$xs->index->beginrebuild ();$sql= "Select G.id id,g.title title,g.norms norms,i.picture picture from B2b_goods G INNER joins b2b_goods_images I on G.ID=I.G oods_id Limit ";$result=$db->query ($sql); while($row=$result-Fetch_assoc ()) {$doc=Newxsdocument;$doc->setfields ($row);//Add to index database$xs->index->add ($doc);$xs->index->update ($doc);}//tell the server to rebuild the index complete$xs->index->endrebuild ();}Catch(xsexception$e){Echo $e;}
4. Using buffer batch rebuild to update index
Header(' Content-type:text/html;charset=utf-8; '));require_once‘.. /.. /.. /local/xunsearch/sdk/php/lib/xs.php ';include"./mysql_conn.php";Try{ $xs=NewXS (' NJW '); //using index buffers $xs->index->Openbuffer (); $sql= "Select G.id id,g.title title,g.norms norms,i.picture picture from B2b_goods G INNER joins b2b_goods_images I on G.ID=I.G oods_id "; $result=$db->query ($sql); while($row=$result-Fetch_assoc ()) { $doc=Newxsdocument; $doc->setfields ($row); //Add to index database $xs->index->add ($doc); $xs->index->update ($doc); } //tell the server to rebuild the index complete $xs->index->Closebuffer ();}Catch(xsexception$e){ Echo $e;}
Xunsearch PHP index maintenance (iv)