• sphinx和mysql like对比


    一共有3093326条企业数据,其中sphinx代码如下:

    <?php
    function microtime_float()
    {
        list($usec, $sec) = explode(" ", microtime());
        return ((float)$usec + (float)$sec);
    }
    $time_start = microtime_float();
    $s = new SphinxClient;
    $s->setServer("localhost", 9312);
    $s->setMatchMode(SPH_MATCH_ANY);
    $s->setMaxQueryTime(300);
    
    $result = $s->query("暖气片",'test1');
    var_dump($result);
    $time_end = microtime_float();
    $time = $time_end - $time_start;
    echo "Sphinx search in $time seconds
    ";
    ?>

    php+mysql代码如下:

    <?php
    $start = microtime_float();
    mysql_connect("localhost", "root", "root") or
        die("Could not connect: " . mysql_error());
    mysql_select_db("test");
    
    $result = mysql_query("SELECT id, cache_companyname as title, content FROM pb_trades where cache_companyname like '%暖气片%' or content like '%暖气片%' limit 10");
    echo mysql_num_rows($result);
    $end = microtime_float();
    $time = $end - $start;
    echo "Mysql like search in $time seconds
    ";
    mysql_free_result($result);
    ?>

    都是搜索带有“暖气片”的关键词,Sphin花费0.17000985145569 seconds,Mysql花费了19.646124124527 seconds.

  • 相关阅读:
    python3.5过滤网址和图片的函数自己亲测可用
    关于接口数据编写的思路整理
    Mysql db
    在Maven中设置Nexus私有服务为中央工厂
    maven 镜像使用
    maven 自建库
    Windows批处理(cmd/bat)常用命令小结
    springmvc and maven
    spring 源码解析
    spring aop 原理
  • 原文地址:https://www.cnblogs.com/zl0372/p/sphinx_12.html
Copyright © 2020-2023  润新知