Table of Contents
安装
配置
mysql 数据源
sphinx 配置文件
创建索引
错误集
libmysqlclient.so.18
Invalid cross-device link
查看检索是否启动
WARNING attribute not found
ERROR index No fields in schema
WARNING sql_query_info removed from Sphinx
word overrun buffer
Home Database Mysql Tutorial Sphinx 使用记录

Sphinx 使用记录

Jun 07, 2016 pm 04:39 PM
sphinx download use Install Source code at present Record need

安装 安装前需要先去官网下载源码. 目前最新版本是 2.2.5-release, 点击下载即可。 当然,如果你想直接在命令行下载,直接下载我这个版本也行,就是不知道会不会版本太久。 tiankonguse:~ $ cd /usr/local/srctiankonguse:src $ su root -tiankonguse:src #

安装

安装前需要先去官网下载源码.
目前最新版本是 2.2.5-release, 点击下载即可。

当然,如果你想直接在命令行下载,直接下载我这个版本也行,就是不知道会不会版本太久。

tiankonguse:~ $ cd /usr/local/src
tiankonguse:src $ su root -
tiankonguse:src # wget http://sphinxsearch.com/files/sphinx-2.2.5-release.tar.gz
Copy after login

然后解压缩,命令就不用说了吧

tiankonguse:src # tar zxvf filename.tar.gz
Copy after login

后来听说 sphinx 有两种安装方式

  1. 单独安装,查询时采用API调用。
  2. 使用插件方式把sphinx编译成一个mysql插件并使用特定的sql语句进行检索。

这里我选择第一种方式,毕竟把 sphinx 和 mysql 耦合在一起的话, 将来将成为一个很大的坑。

sphinx 查询出来的是 id, 然后会进行二次查询得到想要的数据。

下面的命令都是在 root 权限下操作的。

tiankonguse:sphinx-2.2.5-release # ./configure –prefix=/usr/local/sphinx
tiankonguse:sphinx-2.2.5-release # make && make install
Copy after login

可以使用 --prefix 指向sphinx的安装路径 可以使用 --with-mysql 指向mysql的安装路径。

安装完毕后查看一下 /usr/local/sphinx 下是否有 三个目录 bin etc var,如有,则安装无误!

tiankonguse:sphinx-2.2.5-release # cd /usr/local/sphinx/
tiankonguse:sphinx # ls
bin/  etc/  share/  var/
Copy after login

配置

mysql 数据源

由于我使用的是 mysql, 所以需要为 sphinx 创建对应的db。

# server:127.0.0.1
# database : d_sphinx_testdb
# table: t_sphinx_article
CREATE SCHEMA IF NOT EXISTS `d_sphinx_testdb` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
USE `d_sphinx_testdb` ;
CREATE TABLE `d_sphinx_testdb`.`t_sphinx_article` (
  `c_id` INT NOT NULL AUTO_INCREMENT,
  `c_title` VARCHAR(45) NOT NULL DEFAULT '',
  `c_content` VARCHAR(45) NOT NULL DEFAULT '',
  `c_comment_num` VARCHAR(45) NOT NULL DEFAULT 0,
  PRIMARY KEY (`c_id`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
Copy after login

sphinx 配置文件

首先需要找到需要配置的文件以及需要配置的内容。

我们需要配置的是 /usr/local/sphinx/sphinx.conf 文件里面的数据库的信息。

tiankonguse:sphinx # cd etc
tiankonguse:etc # 
tiankonguse:etc # ls
example.sql  sphinx-min.conf.dist  sphinx.conf.dist
tiankonguse:etc #  cp sphinx.conf.dist sphinx.conf
tiankonguse:etc # ls
example.sql  sphinx-min.conf.dist  sphinx.conf  sphinx.conf.dist
skyyuan:etc $ vi sphinx.conf
Copy after login

可以看到下面的内容设置数据源 source

#############################################################################
## data source definition
#############################################################################
source d_sphinx_testdb 
{
    # data source type. mandatory, no default value
    # known types are mysql, pgsql, mssql, xmlpipe, xmlpipe2, odbc
    type            = mysql  # 数据库类型
    # some straightforward parameters for SQL source types
    #数据库主机地址
    sql_host        = 127.0.0.1 
    #数据库用户名
    sql_user        = root      
    #数据库密码
    sql_pass        = pwd       
    #数据库名称
    sql_db          = d_sphinx_testdb  
    # 数据库采用的端口
    sql_port        = 3306  
    # pre-query, executed before the main fetch query
    # multi-value, optional, default is empty list of queries
    #执行sql前要设置的字符集 
    sql_query_pre   = SET NAMES UTF8 
    # main document fetch query mandatory, integer document ID field MUST be the first selected column
    # 全文检索要显示的内容,在这里尽可能不使用where或group by,将where与groupby的内容交给sphinx,由sphinx进行条件过滤与groupby效率会更高
    # select 出来的字段必须至少包括一个唯一主键(ARTICLESID)以及要全文检索的字段,你计划原本在where中要用到的字段也要select出来,这里不需要使用orderby
    sql_query = SELECT c_id,c_title,c_content,c_comment_num FROM t_sphinx_article
    #####以下是用来过滤或条件查询的属性############
    #sql_attr_ 开头的表示一些属性字段,你原计划要用在where,orderby,groupby中的字段要在这里定义
    # unsigned integer attribute declaration
    sql_attr_uint = c_comment_num  # 无符号整数属性
    sql_attr_uint = c_id  # 无符号整数属性
    # boolean attribute declaration
    # sql_attr_bool     = is_deleted
    # bigint attribute declaration
    # sql_attr_bigint       = my_bigint_id
    # UNIX timestamp attribute declaration
    # sql_attr_timestamp    = posted_ts
    # floating point attribute declaration
    # sql_attr_float        = lat_radians
    # string attribute declaration
    sql_attr_string       = c_title
    sql_attr_string       = c_content
    # JSON attribute declaration
    # sql_attr_json     = properties
    # combined field plus attribute declaration (from a single column)
    # stores column as an attribute, but also indexes it as a full-text field
    #
    # sql_field_string  = author
}
Copy after login

然后设置数据源的索引

index d_sphinx_testdb_index
{
    #数据源名
    source = d_sphinx_testdb
    # 索引记录存放目录
    path = /usr/local/sphinx/var/data/d_sphinx_testdb_index
    # 文档信息存储方式
    docinfo = extern
    #缓存数据内存锁定
    mlock = 0
    # 形态学
    morphology = none
    # 索引的词最小长度
    min_word_len = 1
    #数据编码
    charset_type = utf-8
    #最小前缀
    min_prefix_len = 0
    #最小中缀
    min_infix_len = 1 
}
indexer  
{  
    # 内存限制
    mem_limit  = 32M  
}
searchd  
{  
    # 监听端口
    listen          = 9312  
    # 服务进程日志
    log         = /usr/local/sphinx/log/searchd.log  
    # 客户端查询日志
    query_log       = /usr/local/sphinx/log/query.log  
    # 请求超时
    read_timeout            = 5  
    # 同时可执行的最大searchd 进程数
    max_children            = 30  
    #进程ID文件
    pid_file        = /usr/local/sphinx/log/searchd.pid 
    # 查询结果的最大返回数    
    max_matches     = 1000  
    # 是否支持无缝切换,做增量索引时通常需要
    seamless_rotate         = 1  
}  
Copy after login

创建索引

进入 bin 目录,执行

./indexer 索引名
Copy after login

错误集

libmysqlclient.so.18

但是我报下面的错误

./indexer: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
Copy after login

原因:这主要是因为你安装库后,没有配置相应的环境变量.可以通过连接修正这个问题

sudo ln /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18 
Copy after login

但是还是报错,原来添加一个动态库后需要重新加载动态库。

tiankonguse:bin #  ldconfig
Copy after login

但是我又报错了

ln: creating hard link `/usr/lib/libmysqlclient.so.18 ' => `/usr/local/mysql/lib/libmysqlclient.so.18': Invalid cross-device link
Copy after login

于是我只好创建软连接了。

sudo  ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18 
Copy after login

查看检索是否启动

tiankonguse:bin #  ps -ef | grep search
tiankonguse   9601     1  0 Oct28 ?        00:00:00 xs-searchd: master                                             
tiankonguse   9602  9601  0 Oct28 ?        00:00:00 xs-searchd: worker[1]                                          
tiankonguse   9603  9601  0 Oct28 ?        00:00:00 xs-searchd: worker[2]                                          
tiankonguse   9604  9601  0 Oct28 ?        00:00:00 xs-searchd: worker[3]                                          
root     32637 18048  0 21:12 pts/0    00:00:00 grep search
Copy after login

WARNING attribute not found

执行索引的时候,看到这个错误,搜索了一下,原来主键不能加入到属性中去。

WARNING: attribute 'c_id' not found - IGNORING
Copy after login

参考文档 数据源配置:mysql数据源 和 WARNING: zero/NULL document_id, skipping .

ERROR index No fields in schema

ERROR: index 't_cover_sphinx_index': No fields in schema - will not index
Copy after login

还是在这里找到了原因。

使用sql_attr设置的字段,只能作为属性,使用SphinxClient::SetFilter()进行过滤;
未被设置的字段,自动作为全文检索的字段,使用SphinxClient::Query("搜索字符串")进行全文搜索

而我把所有字段都设置为 sql_attr 了,于是把需要全文索引的字段去掉。终于跑出一些接过来。

但是还有一些问题。

WARNING sql_query_info removed from Sphinx

WARNING: key 'sql_query_info' was permanently removed from Sphinx configuration. Refer to documentation for details.
Copy after login

好吧,我说怎么没有在配置文件中看到 sql_query_info 的说明呢,原来已经删除了,那就注释掉吧。

word overrun buffer

还是搜主键搜到的原因是我的主键不是一个整数,而 sphinx 要求必须是一个整数。

WARNING: source : skipped 300 document(s) with zero/NULL ids
WARNING: word overrun buffer, clipped!!!
WARNING: 601 duplicate document id pairs found
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What should I do if I download other people's wallpapers after logging into another account on wallpaperengine? What should I do if I download other people's wallpapers after logging into another account on wallpaperengine? Mar 19, 2024 pm 02:00 PM

When you log in to someone else's steam account on your computer, and that other person's account happens to have wallpaper software, steam will automatically download the wallpapers subscribed to the other person's account after switching back to your own account. Users can solve this problem by turning off steam cloud synchronization. What to do if wallpaperengine downloads other people's wallpapers after logging into another account 1. Log in to your own steam account, find cloud synchronization in settings, and turn off steam cloud synchronization. 2. Log in to someone else's Steam account you logged in before, open the Wallpaper Creative Workshop, find the subscription content, and then cancel all subscriptions. (In case you cannot find the wallpaper in the future, you can collect it first and then cancel the subscription) 3. Switch back to your own steam

Introduction to how to download and install the superpeople game Introduction to how to download and install the superpeople game Mar 30, 2024 pm 04:01 PM

The superpeople game can be downloaded through the steam client. The size of this game is about 28G. It usually takes one and a half hours to download and install. Here is a specific download and installation tutorial for you! New method to apply for global closed testing 1) Search for "SUPERPEOPLE" in the Steam store (steam client download) 2) Click "Request access to SUPERPEOPLE closed testing" at the bottom of the "SUPERPEOPLE" store page 3) After clicking the request access button, The "SUPERPEOPLECBT" game can be confirmed in the Steam library 4) Click the install button in "SUPERPEOPLECBT" and download

Where to download files from Quark Network Disk_How to download Quark Network Disk to local area and share Where to download files from Quark Network Disk_How to download Quark Network Disk to local area and share Mar 21, 2024 pm 03:57 PM

As a convenient and practical network disk tool, Quark can help users easily obtain their favorite resources. What if you want to download a file locally? Let the editor tell you now, let’s learn it together! How to download Quark Network Disk to local sharing method 1. First open the Quark software, enter the homepage, and click the [Cloud Icon] on the lower right; 2. Then on the Quark Network Disk page, we click the [Document] function; 3. Then go to the document page, select the file you want to download, and click the [three-dot icon]; 4. After the final click, we click [Download] in the pop-up dialog box;

How to use NetEase Mailbox Master How to use NetEase Mailbox Master Mar 27, 2024 pm 05:32 PM

NetEase Mailbox, as an email address widely used by Chinese netizens, has always won the trust of users with its stable and efficient services. NetEase Mailbox Master is an email software specially created for mobile phone users. It greatly simplifies the process of sending and receiving emails and makes our email processing more convenient. So how to use NetEase Mailbox Master, and what specific functions it has. Below, the editor of this site will give you a detailed introduction, hoping to help you! First, you can search and download the NetEase Mailbox Master app in the mobile app store. Search for "NetEase Mailbox Master" in App Store or Baidu Mobile Assistant, and then follow the prompts to install it. After the download and installation is completed, we open the NetEase email account and log in. The login interface is as shown below

How to download Beilehu children's songs How to download Beilehu children's songs Mar 28, 2024 am 11:10 AM

As an indispensable accompaniment to children's growth, Beilehu's children's songs have won the love of countless parents and children with their cheerful melody, vivid pictures and entertaining and educational content. In order to allow babies to enjoy the joy brought by children's songs anytime and anywhere, many parents hope to download Beilehu's children's songs to their mobile phones or tablets so that they can listen to their children at any time, but how to save Beilehu's children's songs? On your mobile phone, this tutorial will bring you a detailed introduction. Users who don’t understand it yet can come and read along with this article to learn more. Beilehu Nursery Rhymes Download Children's Songs Multi-Picture Tutorial: Open the software and select a children's song you want to download. The editor takes "Classic Children's Songs" as an example. 2. Click the "Download" button below the children's song star.

How to use Baidu Netdisk app How to use Baidu Netdisk app Mar 27, 2024 pm 06:46 PM

Cloud storage has become an indispensable part of our daily life and work nowadays. As one of the leading cloud storage services in China, Baidu Netdisk has won the favor of a large number of users with its powerful storage functions, efficient transmission speed and convenient operation experience. And whether you want to back up important files, share information, watch videos online, or listen to music, Baidu Cloud Disk can meet your needs. However, many users may not understand the specific use method of Baidu Netdisk app, so this tutorial will introduce in detail how to use Baidu Netdisk app. Users who are still confused can follow this article to learn more. ! How to use Baidu Cloud Network Disk: 1. Installation First, when downloading and installing Baidu Cloud software, please select the custom installation option.

How to install Android apps on Linux? How to install Android apps on Linux? Mar 19, 2024 am 11:15 AM

Installing Android applications on Linux has always been a concern for many users. Especially for Linux users who like to use Android applications, it is very important to master how to install Android applications on Linux systems. Although running Android applications directly on Linux is not as simple as on the Android platform, by using emulators or third-party tools, we can still happily enjoy Android applications on Linux. The following will introduce how to install Android applications on Linux systems.

How to download and save Douyin videos How to download and save Douyin videos Mar 25, 2024 pm 09:46 PM

How to download and save Douyin videos? You can download and save videos in Douyin short video APP. Most users don’t know how to download and save Douyin videos. Next is the diagram of how to download and save Douyin videos brought by the editor. Text tutorial, interested users come and take a look! Tutorial on how to use Douyin: How to download and save Douyin videos 1. First open the Douyin short video APP, enter the main page and click the [Share] button on the right; 2. After that, the multi-function bar will expand below, slide to the right to find [ Save local] icon; 3. Then you need to wait for the download, and then the [Saved, please go to the album to view] border will appear; 4. Finally jump to the album page, and you can see that the video you just downloaded has been saved.

See all articles