python html5 bootstrap 视频教程

德云社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 7200|回复: 0

在 Ubuntu 14.04 下 apt-get 安装全文搜索引擎 Sphinx

[复制链接]

172

主题

258

帖子

1114

积分

版主

Rank: 7Rank: 7Rank: 7

金钱
663
金币
7
威望
0
贡献
0
发表于 2018-5-19 14:40:00 | 显示全部楼层 |阅读模式
AI人工智能 语音助理 人工翻译 教程
在 Ubuntu 14.04 下 apt-get 安装全文搜索引擎 Sphinx

1.jpg

工作环境:
1系统Ubuntu 14.04
2HTTP 代理nginx 1.4.6
3PHP 版本5.5.9
4MySQL 版本5.5.40
5phpMyAdmin 版本4.0.10deb1

安装步骤:
       01、安装全文搜索引擎 Sphinx 前,必须先安装 MySQL server 并设置数据库 root 用户(此处不讲 MySQL server 的具体安装过程,请关注相关主题)

       02、使用 apt-get 方法直接安装 Sphinx:
  1. apt-get install sphinxsearch
复制代码
      

智能批处理式 "数字 Python IDE" 集成开发环境 (集成高效 Cython PyInstaller 批处理小程序)

http://dt.digitser.cn/zh-CN/ide/idepy/index.html


多线程 批处理式 全文搜索 工具

http://dt.digitser.cn/zh-CN/applet/fulltext_search/index.html

多线程 批处理式 全文搜索-文本 工具

http://dt.digitser.cn/zh-CN/applet/fulltext_searchtext/index.html


多线程 批处理式 全文替换 工具

http://dt.digitser.cn/zh-CN/applet/fulltext_replace/index.html

多线程 批处理式 全文替换-多 工具

http://dt.digitser.cn/zh-CN/applet/fulltext_replacemany/index.html

多线程 批处理式 全文替换-文本 工具

http://dt.digitser.cn/zh-CN/applet/fulltext_replacetext/index.html


多线程 批处理式 全文移动-文本 工具

http://dt.digitser.cn/zh-CN/applet/fulltext_move/index.html


       03、创建全文搜索引擎 Sphinx 的配置文件:
  1. cp /etc/sphinxsearch/sphinx.conf.sample /etc/sphinxsearch/sphinx.conf
  2. vi /etc/sphinxsearch/sphinx.conf
复制代码
              配置全文搜索引擎 Sphinx 的配置文件:
  1. sql_user = test
  2. sql_pass =
  3. # compat_sphinxql_magics = 1
复制代码
              将以上代码改为
  1. sql_user = root
  2. sql_pass = 您的数据库 root 用户密码
  3. compat_sphinxql_magics = 0
复制代码
       04、开启 sphinxsearch 功能:
  1. vi /etc/default/sphinxsearch
复制代码
              将其中的
  1. START=no
复制代码
              改为
  1. START=yes
复制代码
       05、创建 test 数据库:
  1. root:~# mysql -u root -p

  2. Enter password: 键入您的数据库 root 用户密码

  3. Welcome to the MySQL monitor.  Commands end with ; or \g.
  4. Your MySQL connection id is 20177
  5. Server version: 5.5.40-0ubuntu0.14.04.1 (Ubuntu)

  6. Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

  7. Oracle is a registered trademark of Oracle Corporation and/or its
  8. affiliates. Other names may be trademarks of their respective
  9. owners.

  10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

  11. mysql>create database test;

  12. Query OK, 1 row affected (0.00 sec)

  13. mysql> use test;

  14. Reading table information for completion of table and column names
  15. You can turn off this feature to get a quicker startup with -A

  16. Database changed

  17. mysql> exit

  18. Bye

  19. root:~#
复制代码
       06、将 test 数据库范例文件
  1. /etc/sphinxsearch/example.sql
复制代码
              下载到本地计算机

       07、在浏览器中键入
  1. http://您的服务器 IP 地址/phpmyadmin/
复制代码
              访问 phpMyAdmin 控制台-->键入您的数据库 root 用户名及密码-->选择 test 数据库-->导入-->浏览-->找到本地计算机 example.sql 文件-->打开-->执行-->显示
  1. “导入成功,执行了 6 个查询。(example.sql)”
复制代码
              说明 example.sql 文件导入 test 数据库成功

       08、建立全文搜索引擎 Sphinx 的索引:
  1. indexer --all
复制代码
1.jpg
        09、启动全文搜索引擎 Sphinx 服务:
  1. root:~# service sphinxsearch start

  2. Starting sphinxsearch: Sphinx 2.0.4-id64-release (r3135)
  3. Copyright (c) 2001-2012, Andrew Aksyonoff
  4. Copyright (c) 2008-2012, Sphinx Technologies Inc (http://sphinxsearch.com)

  5. using config file '/etc/sphinxsearch/sphinx.conf'...
  6. listening on all interfaces, port=9312
  7. listening on all interfaces, port=9306
  8. precaching index 'test1'
  9. precaching index 'test1stemmed'                             
  10. WARNING: multiple addresses found for 'localhost', using the first one (ip=127.0.0.1)
  11. precaching index 'rt'
  12. precached 3 indexes in 0.001 sec
  13. sphinxsearch.

  14. root:~#
复制代码
       10、测试搜索 EN 单词 test
  1. root:~# /usr/bin/search test

  2. Sphinx 2.0.4-id64-release (r3135)
  3. Copyright (c) 2001-2012, Andrew Aksyonoff
  4. Copyright (c) 2008-2012, Sphinx Technologies Inc (http://sphinxsearch.com)

  5. using config file '/etc/sphinxsearch/sphinx.conf'...
  6. index 'test1': query 'test ': returned 3 matches of 3 total in 0.000 sec

  7. displaying matches:
  8. 1. document=1, weight=2421, group_id=1, date_added=Mon Dec 22 15:30:18 2014
  9.     id=1
  10.     group_id=1
  11.     group_id2=5
  12.     date_added=2014-12-22 15:30:18
  13.     title=test one
  14.     content=this is my test document number one. also checking search within phrases.
  15. 2. document=2, weight=2421, group_id=1, date_added=Mon Dec 22 15:30:18 2014
  16.     id=2
  17.     group_id=1
  18.     group_id2=6
  19.     date_added=2014-12-22 15:30:18
  20.     title=test two
  21.     content=this is my test document number two
  22. 3. document=4, weight=1442, group_id=2, date_added=Mon Dec 22 15:30:18 2014
  23.     id=4
  24.     group_id=2
  25.     group_id2=8
  26.     date_added=2014-12-22 15:30:18
  27.     title=doc number four
  28.     content=this is to test groups

  29. words:
  30. 1. 'test': 3 documents, 5 hits

  31. index 'test1stemmed': query 'test ': returned 3 matches of 3 total in 0.000 sec

  32. displaying matches:
  33. 1. document=1, weight=2421, group_id=1, date_added=Mon Dec 22 15:30:18 2014
  34.     id=1
  35.     group_id=1
  36.     group_id2=5
  37.     date_added=2014-12-22 15:30:18
  38.     title=test one
  39.     content=this is my test document number one. also checking search within phrases.
  40. 2. document=2, weight=2421, group_id=1, date_added=Mon Dec 22 15:30:18 2014
  41.     id=2
  42.     group_id=1
  43.     group_id2=6
  44.     date_added=2014-12-22 15:30:18
  45.     title=test two
  46.     content=this is my test document number two
  47. 3. document=4, weight=1442, group_id=2, date_added=Mon Dec 22 15:30:18 2014
  48.     id=4
  49.     group_id=2
  50.     group_id2=8
  51.     date_added=2014-12-22 15:30:18
  52.     title=doc number four
  53.     content=this is to test groups

  54. words:
  55. 1. 'test': 3 documents, 5 hits

  56. index 'rt': search error: failed to open /var/lib/sphinxsearch/data/rt.sph: No such file or directory.

  57. root:~#
复制代码
       11、好啦,一切 OK


扫一扫关注 德云社区 微信公众号

版权声明:
本文为独家原创稿件,版权归 德云社区,未经许可不得转载。
AI人工智能 语音助理 人工翻译 教程
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|Sitemap|小黑屋|德云社区 |网站地图  

GMT+8, 2024-4-20 06:30 , Processed in 0.029882 second(s), 30 queries .

工业和信息化部: 粤ICP备14079481号-2

技术支持 乐数软件     版权所有 © 2014-2021 德云社区    

快速回复 返回顶部 返回列表