search

    随着自己电影网站资源逐渐增多,增加电影资源搜索服务成为必然。直接操作数据库的搜索,IO口请求增多减低了搜索性能。之前项目中有sphinx的使用基础,加之支持中文检索服务,最后决定采用基于sphinx的Coreseek搜索服务。

    下载安装步骤【本人采用 linux环境下 4.1版本,系统支持mysql和xml数据源】:

  1.  coreseek下载地址,下载 coreseek-4.1-beta.tar.gz 包

  2.   解压gz包,tar zxvf coreseek-4.1-beta.tar.gz

  3.  编译安装 mmseg【中文分词包】

    1. ./bootstrap

    2. ./configure --prefix=/usr/local/mmseg3 

    3. make && make install

  4.  编译安装 coreseek 

    1. sh buildconf.sh  #输出的warning信息可以忽略,如果出现error则需要解决 

    2. ./configure --prefix=/usr/local/coreseek  --without-unixodbc --with-mmseg --with-mmseg-includes=/usr/local/mmseg3/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg3/lib/ --with-mysql  #with-mmseg-libs就是mmseg中文分词路径

    3. make && make install

    电影网站更新周期比较长,sphinx采用主索引+增量索引方式进行索引,最后合并两个索引文件。下面开始部署自己的搜索配置文件:

  1. 进入coreseek安装目录下的etc文件,新建或修改 .conf配置文件

  2. 配置source源 

    1. source movie
      {
          type              = mysql
          sql_host        = localhost #mysql数据库host
          sql_user        = root    #mysql用户
          sql_pass        =           #mysql用户密码
          sql_db          = movie  #movie
          sql_port        = 3306   # optional, default is 3306
          sql_query_pre            = SET NAMES utf8
        
          #建立增量索引 
          sql_query_pre = REPLACE INTO movie_sph_counter SELECT 1, MAX(id) FROM movie
          sql_query = SELECT id, UNIX_TIMESTAMP(cdate) AS date ,id AS movie_id ,name, year, type,status,sync_status FROM movie WHERE id

         #搜索返回字段
          sql_attr_uint   = movie_id
          sql_attr_uint   = year
          sql_attr_uint   = type
          sql_attr_uint   = date
          sql_attr_uint   = status
          sql_attr_uint   = sync_status                   
          sql_field_string = name

          sql_query_info_pre      = SET NAMES utf8                                        #命令行查询时,设置正确的字符集
          sql_query_info            = SELECT * FROM movie WHERE id=$id #命令行查询时,从数据库读取原始数据信息
      }

      #增量索引源
      source delta : movie
      {
          sql_query_pre = SET NAMES utf8
          sql_query = SELECT id, UNIX_TIMESTAMP(cdate) AS date ,id AS movie_id ,name , year, type ,status,sync_status FROM movie WHERE id>( SELECT max_movie_id FROM movie_sph_counter WHERE counter_id=1 )
          sql_query_post_index =  REPLACE INTO movie_sph_counter SELECT 1, MAX(id) FROM movie
      }

  3. 配置索引

    1. #index定义
      index movie
      {
          source            = movie            #对应的source名称
          path              = /usr/local/coreseek/var/data/movie #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
          docinfo            = extern
          mlock            = 0
          morphology        = none
          min_word_len        = 1
          html_strip                = 0

          #中文分词配置,详情请查看:http://www.coreseek.cn/products-install/coreseek_mmseg/
          charset_dictpath = /usr/local/mmseg/etc/ #BSD、Linux环境下设置,/符号结尾  mmseg路径
        
          charset_type        = zh_cn.utf-8  #中文编码
      }

      index delta : movie
      {
          source = delta
          path            = /usr/local/coreseek/var/data/movie_delta   #注意!!不要和主索引路径名称一样

          docinfo         = extern
          mlock           = 0
          morphology      = none
          min_word_len    = 1
          html_strip      = 0

          charset_dictpath = /usr/local/mmseg/etc/
          charset_type     = zh_cn.utf-8
      }

  4.  配置搜索服务 

    1. #searchd服务定义
      searchd
      {
          listen                  =   9312  #端口号,可以自己定义
          read_timeout        = 5
          max_children        = 30
          max_matches            = 1000
          seamless_rotate        = 0
          preopen_indexes        = 0
          unlink_old            = 1
          
          compat_sphinxql_magics=0
          pid_file = /usr/local/coreseek/var/log/searchd_mysql.pid  #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
          log = /usr/local/coreseek/var/log/searchd_mysql.log        #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
          query_log = /usr/local/coreseek/var/log/query_mysql.log #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
          binlog_path =                                #关闭binlog日志
      }

  5. 执行命令建立索引:  /usr/local/coreseek/bin/indexer -c movie.conf --all

  6. 后台开启搜索服务运行:/usr/local/coreseek/bin/searchd  -c movie.conf

  7. 建立定时任务,执行增量索引:/usr/local/coreseek/bin/indexer -c csft_movie.conf delta --rotate

  8. 建立定时任务,合并索引:/usr/local/coreseek/bin/indexer -c csft_movie.conf --merge movie delta --merge-dst-range deleted 0 0 --rotate

  9. 至此基于sphinx+mysql的搜索服务已经搭建完毕,接下来就是根据sphinxapi.php开发搜索接口代码……

    第一次自己搭建sphinx搜索服务,最后测试网站搜索,速度杠杠的。

    特此分享,希望对大家有所帮助



Statement
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
11 Best PHP URL Shortener Scripts (Free and Premium)11 Best PHP URL Shortener Scripts (Free and Premium)Mar 03, 2025 am 10:49 AM

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

Build a React App With a Laravel Back End: Part 2, ReactBuild a React App With a Laravel Back End: Part 2, ReactMar 04, 2025 am 09:33 AM

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

cURL in PHP: How to Use the PHP cURL Extension in REST APIscURL in PHP: How to Use the PHP cURL Extension in REST APIsMar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Announcement of 2025 PHP Situation SurveyAnnouncement of 2025 PHP Situation SurveyMar 03, 2025 pm 04:20 PM

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

Notifications in LaravelNotifications in LaravelMar 04, 2025 am 09:22 AM

In this article, we're going to explore the notification system in the Laravel web framework. The notification system in Laravel allows you to send notifications to users over different channels. Today, we'll discuss how you can send notifications ov

See all articles

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 agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)