Table of Contents
首先明确几个概念
安装mmseg的时候,./configure出现错误:config.status: error: cannot find input file: src/Makefile.in
在安装csrf的时候,文档提示需要指定mysql,但是我的mysql是yum安装的,找不到安装路径
配置文件提示unknown key: sql_attr_string
如何安装php的sphinx扩展
如何配置sphinx.conf配置文件
php调用SphinxClient的例子如下:
参考文章:
Home php教程 php手册 Coreseek + Sphinx + Mysql + PHP构建中文检索引擎

Coreseek + Sphinx + Mysql + PHP构建中文检索引擎

Jun 06, 2016 pm 07:48 PM
coreseek mysql php sphinx Construct

首先明确几个概念 Sphinx是开源的搜索引擎,它支持英文的全文检索。所以如果单独搭建Sphinx,你就已经可以使用全文索引了。但是往往我们要求的是中文索引,怎么做呢?国人提供了一个可供企业使用的,基于Sphinx的中文全文检索引擎。也就是说Coreseek实际上的

首先明确几个概念

Sphinx是开源的搜索引擎,它支持英文的全文检索。所以如果单独搭建Sphinx,你就已经可以使用全文索引了。但是往往我们要求的是中文索引,怎么做呢?国人提供了一个可供企业使用的,基于Sphinx的中文全文检索引擎。也就是说Coreseek实际上的内核还是Sphinx。那么他们的版本对应呢?

 

Coreseek发布了3.2.14版本和4.1版本,其中的3.2.14版本是2010年发布的,它是基于Sphinx0.9.9搜索引擎的。而4.1版本是2011年发布的,它是基于Sphinx2.0.2的。Sphinx从0.9.9到2.0.2还是有改变了很多的,有很多功能,比如sql_attr_string等是在0.9.9上面不能使用的。所以在安装之前请判断清楚你需要安装的是哪个版本,在google问题的时候也要弄清楚这个问题的问题和答案是针对哪个版本的。我个人强烈建议使用4.1版本。

 

网上有一篇文章说的是Sphinx和Coreseek是怎么安装的,其中它的coreseek安装这部分使用coreseek-4.1来替换就可以使用了。

 

详细步骤看上面篇文章就理解了,这里说一下我在安装过程中遇到的几个问题:

安装mmseg的时候,./configure出现错误:config.status: error: cannot find input file: src/Makefile.in

这个时候需要先运行下automake

结果我运行的时候竟然提示automake的版本不对

所以这个时候,你可能需要去官网下个对应的版本(有可能是需要老版本)再来运行

在安装csrf的时候,文档提示需要指定mysql,但是我的mysql是yum安装的,找不到安装路径

./configure 

--prefix=/usr/local/coreseek --with-mysql=/usr/local/mysql

 --with-mmseg=/usr/local/mmseg --with-mmseg-includes=/usr/local/mmseg/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg/lib/
Copy after login

 

 

yum安装的mysql的include和libs文件夹一般是安装在/usr/include/mysql和/usr/lib64/mysql下面

所以这里的--with-mysql可以使用--with-mysql-includes和--with-mysql-libs来进行替换。

./configure 

--prefix=/usr/local/coreseek --with-mysql-includes=/usr/includes/mysql --with-mysql-libs=/usr/lib64/mysql/

 --with-mmseg=/usr/local/mmseg --with-mmseg-includes=/usr/local/mmseg/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg/lib/
Copy after login

 

配置文件提示unknown key: sql_attr_string

如上文,就需要检查下自己的sphinx版本了

如何安装php的sphinx扩展

可以在这里(http://pecl.php.net/package/sphinx)找到sphinx的php扩展源码

注意,使用phpize,configure的时候可能会要求要安装libsphinxclient,它在coreseek-4.1-beta/csft-4.1/api/libsphinxclient/里面能找到,编译安装它以后就可以configure,make,生成动态so文件了。

如何配置sphinx.conf配置文件

最复杂的部分就是sphinx.conf配置文件的配置了,里面的注释代码非常多,我建议使用的时候把注释代码去掉,我贴出自己使用的最简单的一个成功的配置文件:

source src1
{
        type                    = mysql

        sql_host                = localhost
        sql_user                = yejianfeng
        sql_pass                = test
        sql_db                  = mysite
        sql_port                = 3306  # optional, default is 3306

        sql_query_pre           = SET NAMES utf8
        sql_query_pre           = SET SESSION query_cache_type=OFF

        sql_query               = select id, id AS id_new,name, name AS name_query,descr, descr AS descr_query,city FROM account
        sql_attr_string = name
        sql_attr_string = descr

        sql_query_info          = SELECT * FROM account WHERE id=$id
}

source src1throttled : src1
{
        sql_ranged_throttle     = 100
}

index test1
{
        source                  = src1
        path                    = /home/yejianfeng/instance/coreseek/var/data/test1
        docinfo                 = extern
        mlock                   = 0
        morphology              = none
        min_word_len            = 1
        charset_type = zh_cn.utf-8
        charset_dictpath  = /home/yejianfeng/instance/mmseg/etc/
        html_strip              = 0
}



indexer
{
        mem_limit               = 256M
}

searchd
{
        listen                  = 9312
        listen                  = 9306:mysql41

        log                     = /home/yejianfeng/instance/coreseek/var/log/searchd.log
        query_log               = /home/yejianfeng/instance/coreseek/var/log/query.log
        read_timeout            = 5
        client_timeout          = 300
        max_children            = 30
        pid_file                = /home/yejianfeng/instance/coreseek/var/log/searchd.pid
        max_matches             = 1000
        seamless_rotate         = 1
        preopen_indexes         = 1
        unlink_old              = 1
        mva_updates_pool        = 1M
        max_packet_size         = 8M
        max_filters             = 256
        max_filter_values       = 4096
}
Copy after login

php调用SphinxClient的例子如下:

首先要确保已经启动了searchd

[yejianfeng@AY130416142121702aac etc]$ ps aux|grep searchd
501      30897  0.0  0.0  60824  1396 pts/2    S    17:19   0:00 /home/yejianfeng/instance/coreseek/bin/searchd -c /home/yejianfeng/instance/coreseek/etc/sphinx.conf
501      30999  0.0  0.0 103232   856 pts/2    S+   18:10   0:00 grep searchd
Copy after login

php提供的调用SphinxClient的接口

<?php $s = new SphinxClient;
$s->setServer("localhost", 9312);
$s->setArrayResult(true);
$s->setSelect();
$s->setMatchMode(SPH_MATCH_ALL);

$result = $s->query('美女', 'test1');
print_r($result);
Copy after login

参考文章:

http://www.coreseek.cn/docs/coreseek_4.1-sphinx_2.0.1-beta.html

http://www.coreseek.cn/

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)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
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)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

How to fix mysql_native_password not loaded errors on MySQL 8.4 How to fix mysql_native_password not loaded errors on MySQL 8.4 Dec 09, 2024 am 11:42 AM

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the &quot;MySQL Native Password&quot; plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

Top 10 PHP CMS Platforms For Developers in 2024 Top 10 PHP CMS Platforms For Developers in 2024 Dec 05, 2024 am 10:29 AM

CMS stands for Content Management System. It is a software application or platform that enables users to create, manage, and modify digital content without requiring advanced technical knowledge. CMS allows users to easily create and organize content

How to Add Elements to the End of an Array in PHP How to Add Elements to the End of an Array in PHP Feb 07, 2025 am 11:17 AM

Arrays are linear data structures used to process data in programming. Sometimes when we are processing arrays we need to add new elements to the existing array. In this article, we will discuss several ways to add elements to the end of an array in PHP, with code examples, output, and time and space complexity analysis for each method. Here are the different ways to add elements to an array: Use square brackets [] In PHP, the way to add elements to the end of an array is to use square brackets []. This syntax only works in cases where we want to add only a single element. The following is the syntax: $array[] = value; Example

See all articles