Xunsearch PHP index maintenance (iv)

Source: Internet
Author: User
Tags joins


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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.