Search by sphenders + PHP

Source: Internet
Author: User
With the increasing number of movie website resources, increasing the number of movie resource search services becomes inevitable. The direct operation of database search reduces the search performance by increasing IO port requests. In the previous project, there was a basis for the use of sphsearch. In addition, the Chinese search service was supported. Finally, we decided to use the sphinx-based Coreseek search service.

Download and install [I use mysql 4.1 in linux, and the system supports mysql and xml data sources ]:

  1. Coreseek, download coreseek-4.1-beta.tar.gz package

  2. Unzip the gz package, tar zxvf coreseek-4.1-beta.tar.gz

  3. Compile and install mmseg [Chinese word segmentation package]

    1. ./Bootstrap

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

    3. Make & make install

  4. Compile and install coreseek

    1. Sh buildconf. sh # The output warning information can be ignored. If an error occurs, it must be resolved.

    2. . /Configure -- prefix =/usr/local/coreseek -- without-unixodbc -- with-mmseg-separated des =/usr/local/mmseg3/include/mmseg/--- mmseg-libs =/usr/local/mmseg3/lib/-- with-mysql # with-mmseg-libs is the mmseg Chinese word segmentation path

    3. Make & make install

The update cycle of a movie website is relatively long. sphsf-indexing adopts the primary index + incremental index method, and then merges the two index files. Deploy your own search configuration file as follows:

  1. Go to The etc file under the coreseek installation directory and create or modify the. conf configuration file.

  2. Configure source

    1. Source movie
      {
      Type = mysql
      SQL _host = localhost # mysql database host
      SQL _user = root # mysql User
      SQL _pass = # mysql User password
      SQL _db = movie # movie
      SQL _port = 3306 # optional, default is 3306
      SQL _query_pre = SET NAMES utf8

      # Create an incremental index
      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 <= (SELECT max_movie_id FROM movie_sph_counter WHERE counter_id = 1)

      # Search for returned fields
      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 # SET the correct character SET during command line query
      SQL _query_info = SELECT * FROM movie WHERE id = $ id # When querying through the command line, read the original data FROM the database
      }

      # Incremental Index Source
      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. Configure indexes

    1. # Index definition
      Index movie
      {
      Source = movie # corresponding source name
      Path =/usr/local/coreseek/var/data/movie # change it to the actual absolute path, for example,/usr/local/coreseek/var /...
      Docinfo = extern
      Mlock = 0
      Morphology = none
      Min_word_len = 1
      Html_strip = 0

      # Chinese word segmentation configuration, for details, see: http://www.coreseek.cn/products-install/coreseek_mmseg/
      Charset_dictpath =/usr/local/mmseg/etc/# BSD, set in Linux environment,/mmseg path at the end of symbol

      Charset_type = zh_cn.utf-8 # Chinese encoding
      }

      Index delta: movie
      {
      Source = delta
      Path =/usr/local/coreseek/var/data/movie_delta # note !! Do not use the same name as the primary index path

      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. Configure search service

    1. # Searchd service definition
      Searchd
      {
      Listen = 9312 # port number, which can be customized
      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 # change it to the actual absolute path, for example,/usr/local/coreseek/var /...
      Log =/usr/local/coreseek/var/log/searchd_mysql.log # change it to the actual absolute path, for example,/usr/local/coreseek/var /...
      Query_log =/usr/local/coreseek/var/log/query_mysql.log # change it to the actual absolute path, for example,/usr/local/coreseek/var /...
      Binlog_path = # Disable binlog
      }

  5. Run the command to create an index:/usr/local/coreseek/bin/indexer-c movie. conf -- all

  6. Start the search service running in the background:/usr/local/coreseek/bin/searchd-c movie. conf

  7. Create a scheduled task and run the incremental index:/usr/local/coreseek/bin/indexer-c csft_movie.conf delta -- rotate

  8. Create a scheduled task and merge indexes:/usr/local/coreseek/bin/indexer-c csft_movie.conf -- merge movie delta -- merge-dst-range deleted 0 0 -- rotate

  9. So far, the search service based on sphsf-+ mysql has been set up. The next step is to develop the search interface code according to sphinxapi. php ......

The first time you build your own sphinx search service, and finally test the website search speed.

I would like to share with you the hope to help you

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.