mac 下 sphinx + mysql + php 实现全文搜索(xampp)(1)

 
  1. 原理:
    1. 使用sphinx 中的indexer 生成索引数据
    2. service/web 端 利用searched 调用索引数据
  2. 步骤:
    1. 下载 sphinx:
      1. 下载地址:http://sphinxsearch.com/downloads/release/  这个可以根据自己电脑的系统来下载相应的安装包。
      2. ps:我是mac,所以 我下载了mac安装包,按照文档上的安装 发现不行,后来 我下载了第一个 即 Source tarball (tar.gz), 才安装成功的。
    2. 安装sphinx
      1. 参考地址:http://sphinxsearch.com/docs/current.html#compiling-from-source  一步步来就可以了。主要是 configure的配置,其他都一样。我是xampp 所以写成 ./configure --prefix=/usr/local/sphinx --with-mysql=/Applications/XAMPP/xamppfiles。然并卵,./configure --prefix=/usr/local/sphinx 其实就可以了。
      2. cd /usr/local/sphinx/ 查看 这个目录下,有了bin,etc,var 三个文件夹,就是安转成功了。
    3. 使用sphinx 中的indexer工具 来 对数据表 建立索引数据
      1. indexer 的位置: /usr/local/sphinx/bin 
      2. 方法:bin/indexer -c etc/sphinx.conf test1
      3. 问题1:sphinx.conf 是什么 。
        1. sphinx.conf 是 sphinx 的配置文件
        2. 位置 /usr/local/sphinx/etc,没有的话,自己新建一个或者复制一个
      4. 问题2:test1 是什么:需要建立索引文件的 索引名称,在配置文件中有些
      5. 所以需要先 配置好 sphinx.conf 文件,
        1. 参考地址:http://www.sphinxsearch.org/sphinx-tutorial
        2. 参考地址:http://www.apoyl.com/?p=290
        3. 各个配置项的说明,参考:http://sphinxsearch.com/docs/current.html#conf-reference
        4. 配置好各个参考。保存,执行3.1。居然报错,提示语:Library not loaded: libmysqlclient.18.dylib 网上 查了下,貌似是 文件不存在
        5. 参考地址:http://blog.sina.com.cn/s/blog_68f3bc280100supn.html
        6. 因为我用的是xampp,并不是原生态的mysql,所以文件不存在 也是合理的。
        7. 我去xampp中找到了 类似文件 /Applications/XAMPP/xamppfiles/lib/libmysqlclient.18.dylib。然后执行 sudo ln -s /Applications/XAMPP/xamppfiles/lib/libmysqlclient.18.dylib  /usr/lib/libmysqlclient.18.dylib
        8. 在 执行 3.1 的命令行。发现 ok了。
        9. 查看 cd /usr/local/sphinx/var/data/.(sphinx.conf文件里面有些索引的路径即 path) 发现 存在了 。
        10. 这些数据,既 针对test1的索引数据,生成成功了。
      6.   ps:--rotate参数可以在不停searchd的情况下索引,不然的话会有类似如下的提示:
          FATAL: failed to lock /usr/local/...... Resource temporarily unavailable, will not index. Try --rotate option.
          方法:bin/indexer -c etc/sphinx.conf test1 --rotate
    4. 测试索引是否可以使用
      1. /usr/local/sphinx/bin/searchd --config /usr/local/sphinx/etc/sphinx.conf --status
    5. 查看sphinx 的数据
      1. mysql -h0 -P9306
      2. 使用mac 自带的终端 输入  mysql -h0 -P9306,怎么没起到作用,我去(command not found)。
      3. 原来当你输入命令时,系统会在/usr/bin这个位置里寻找你输入的命令,如果你没有把命令引入到这个位置,无论你直接cd到工具具体的位置调用,也是白费功夫的。只要把这个工具的绝对位置引入到/usr/bin,所有的问题就迎刃而解了,只要我们把这条命令执行     
        sudo ln /Applications/XAMPP/xamppfiles/bin/mysql /usr/bin 
      4. 此时 我们再次输入 mysql -h0 -P9306,就可以进入sphinx的数据库了。
      5. 再附上 进入mysql数据库的命令行 :mysql -u root -p
    6. 我的配置:
      1. mac os x 10.10.5
      2. x86_64
      3. xampp
posted @ 2015-08-26 22:29  ybbshanshan  阅读(372)  评论(0编辑  收藏  举报