zoukankan      html  css  js  c++  java
  • xunsearch之php索引维护(四)


    1.添加文档

    $xs = new XS('njw');
    $index = $xs->index;
    $data = array(
    'pid' => 234, // 此字段为主键,必须指定
    'subject' => '测试文档的标题',
    'message' => '测试文档的内容部分',
    'chrono' => time()
    );
    //创建文档对象
    $doc = new XSDocument;
    $doc->setFields($data);
    ​//添加到索引数据库中
    $index->add($doc);

    2.更新文档

    //创建文档对象
    $doc = new XSDocument;
    $doc->setFields($data);
    //更新到索引数据库中
    $index->update($doc);

    3.平滑批量重建更新索引

    header('Content-Type:text/html;charset=utf-8;');
    require_once '../../../local/xunsearch/sdk/php/lib/XS.php';
    include "./mysql_conn.php";
    try{
    $xs = new XS('njw');
    //平滑重建索引
    //宣布开始重建索引
    $xs->index->beginRebuild();
    $sql = "select g.id id,g.title title,g.norms norms,i.picture picture from b2b_goods g INNER JOIN b2b_goods_images i ON g.id=i.goods_id limit";
    $result = $db->query($sql);
    while( $row = $result -> fetch_assoc ()) {
    $doc = new XSDocument;
    $doc->setFields($row);
    //添加到索引数据库中
    $xs->index->add($doc);
    $xs->index->update($doc);
    }
    //告诉服务器重建索引完成
    $xs->index->endRebuild();
    }catch(XSException $e){
    echo $e;
    }

    4.使用缓冲区批量重建更新索引

    header('Content-Type:text/html;charset=utf-8;');
    require_once '../../../local/xunsearch/sdk/php/lib/XS.php';
    include "./mysql_conn.php";
    try{
        $xs = new XS('njw');
        //使用索引缓冲区
        $xs->index->openBuffer();
        $sql = "select g.id id,g.title title,g.norms norms,i.picture picture from b2b_goods g INNER JOIN b2b_goods_images i ON g.id=i.goods_id";
        $result = $db->query($sql);
        while( $row = $result -> fetch_assoc ()) {
            $doc = new XSDocument;
            $doc->setFields($row);
            //添加到索引数据库中
            $xs->index->add($doc);
            $xs->index->update($doc);
        }
        //告诉服务器重建索引完成
        $xs->index->closeBuffer();
    }catch(XSException $e){
        echo $e;
    }
  • 相关阅读:
    SqlServer Alwayson 搭建排错记录(一)
    SqlServer图形数据库初体验
    SqlServer报错:主体“dbo”不存在
    IIS重叠回收
    No module named 'revoscalepy'问题解决
    SqlServer查询文件组被占用情况
    SqlServer作业指定目标服务器
    [持续更新]UnsatisfiedLinkError常见问题及解决方案
    Android加载SO库UnsatisfiedLinkError错误的原因及解决方案
    _set_invalid_parameter_handler异常处理函数
  • 原文地址:https://www.cnblogs.com/lisqiong/p/5509187.html
Copyright © 2011-2022 走看看