Table of Contents
Articles you may be interested in
Home Backend Development PHP Tutorial Install and use Sphinx under windows [Supports Chinese full-text search]_PHP tutorial

Install and use Sphinx under windows [Supports Chinese full-text search]_PHP tutorial

Jul 13, 2016 am 10:31 AM
sphinx windows use Full Text Search Install

A while ago I tried to use Sphinx, a full-text search system that can be easily called by various languages ​​​​(PHP/Python/Ruby/etc). Most of the information on the Internet is installed and used in the Linux environment. Of course, as a production environment, it is necessary to deploy it in a *nix environment. For learning and testing, the Windows environment is more convenient.

This article aims to provide a convenient way to install and configure Sphinx under Windows to support Chinese full-text search. The configuration part is common under Linux.

1. About Sphinx

Sphinx is a full-text search engine released under GPLv2. Commercial licensing (for example, embedding into other programs) requires contacting the author (Sphinxsearch.com) to obtain commercial licensing.

Generally speaking, Sphinx is an independent search engine, intended to provide high-speed, low-space-occupancy, and high-result-relevant full-text search capabilities for other applications. Sphinx can be easily integrated with SQL databases and scripting languages.

The current system has built-in support for MySQL and PostgreSQL database data sources, and also supports reading XML data in specific formats from standard input. By modifying the source code, users can add new data sources (for example, native support for other types of DBMS).

The search API supports PHP, Python, Perl, Rudy and Java, and can also be used as a MySQL storage engine. The search API is very simple and can be ported to new languages ​​within a few hours.

Sphinx Features:

  • High-speed indexing (on modern CPUs, peak performance can reach 10MB/sec);
  • High-performance search (average response time per retrieval is less than 0.1 seconds on 2–4GB of text data);
  • Can handle massive amounts of data (currently known to be able to process more than 100GB of text data, and 100M documents on a single CPU system);
  • Provides an excellent relevance algorithm, a composite Ranking method based on phrase similarity and statistics (BM25);
  • Support distributed search;
  • Providing excerpt generation of documents;
  • Can be used as a MySQL storage engine to provide search services;
  • Supports multiple search modes such as Boolean, phrase, word similarity, etc.;
  • The document supports multiple full-text search fields (maximum no more than 32);
  • Documents support multiple additional attribute information (for example: grouping information, timestamp, etc.);
  • Stop word query;
  • Supports single byte encoding and UTF-8 encoding;
  • Native MySQL support (supports both MyISAM and InnoDB);
  • Native PostgreSQL support.

The Chinese manual is available here, thanks to the translator for his hard work.

2. Installation of Sphinx on Windows

1. Find the latest windows version directly at http://www.sphinxsearch.com/downloads.html. What I downloaded here is Win32 release binaries with MySQL support. After downloading, unzip it in the D:sphinx directory;

2. Create a new data directory under D:sphinx to store index files and a log directory for log files. Copy D:sphinxsphinx.conf.in to D:sphinxbinsphinx.conf (note to modify the file name);

3. Modify D:sphinxbinsphinx.conf. Here are a few that need to be modified:

type        = mysql # 数据源,我这里是mysql<br>sql_host    = localhost # 数据库服务器<br>sql_user    = root # 数据库用户名<br>sql_pass    = '' # 数据库密码<br>sql_db      = test # 数据库<br>sql_port    = 3306 # 数据库端口
Copy after login
sql_query_pre   = SET NAMES utf8 # 去掉此行前面的注释,如果你的数据库是uft8编码的
Copy after login
index test1<br>{<br># 放索引的目录<br> path   = D:/sphinx/data/<br># 编码<br> charset_type  = utf-8<br> #  指定utf-8的编码表<br> charset_table  = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F<br> # 简单分词,只支持0和1,如果要搜索中文,请指定为1<br> ngram_len    = 1<br># 需要分词的字符,如果要搜索中文,去掉前面的注释<br> ngram_chars   = U+3000..U+2FA1F<br>}
Copy after login
# index test1stemmed : test1<br># {<br> # path   = @CONFDIR@/data/test1stemmed<br> # morphology  = stem_en<br># }<br><br># 如果没有分布式索引,注释掉下面的内容<br><br># index dist1<br># {<br> # 'distributed' index type MUST be specified<br> # type    = distributed
Copy after login
 # local index to be searched<br> # there can be many local indexes configured<br> # local    = test1<br> # local    = test1stemmed
Copy after login
 # remote agent<br> # multiple remote agents may be specified<br> # syntax is 'hostname:port:index1,[index2[,...]]<br> # agent    = localhost:3313:remote1<br> # agent    = localhost:3314:remote2,remote3
Copy after login
 # remote agent connection timeout, milliseconds<br> # optional, default is 1000 ms, ie. 1 sec<br> # agent_connect_timeout = 1000
Copy after login
 # remote agent query timeout, milliseconds<br> # optional, default is 3000 ms, ie. 3 sec<br> # agent_query_timeout  = 3000<br># }
Copy after login
# 搜索服务需要修改的部分<br>searchd<br>{<br> # 日志<br> log     = D:/sphinx/log/searchd.log
Copy after login
 # PID file, searchd process ID file name<br> pid_file   = D:/sphinx/log/searchd.pid
Copy after login
# windows下启动searchd服务一定要注释掉这个<br> # seamless_rotate  = 1<br>}
Copy after login

4. Import test data

C:Program FilesMySQLMySQL Server 5.0bin>mysql -uroot test

5. Create index

D:sphinxbin>indexer.exe –all
Sphinx 0.9.8-release (r1533)
Copyright (c) 2001-2008, Andrew Aksyonoff

using config file ‘./sphinx.conf’…
indexing index ‘test1′…
collected 4 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 4 docs, 193 bytes
total 0.101 sec, 1916.30 bytes/sec, 39.72 docs/sec

D:sphinxbin>

6. Search for ‘test’ and try

D:sphinxbin>search.exe test
Sphinx 0.9.8-release (r1533)
Copyright (c) 2001-2008, Andrew Aksyonoff

using config file ‘./sphinx.conf’…
index ‘test1′: query ‘test ‘: returned 3 matches of 3 total in 0.000 sec

displaying matches:
1. document=1, weight=2, group_id=1, date_added=Wed Nov 26 14:58:59 2008
id=1
group_id=1
group_id2=5
date_added=2008-11-26 14:58:59
title=test one
content=this is my test document number one. also checking search within
phrases.
2. document=2, weight=2, group_id=1, date_added=Wed Nov 26 14:58:59 2008
id=2
group_id=1
group_id2=6
date_added=2008-11-26 14:58:59
title=test two
content=this is my test document number two
3. document=4, weight=1, group_id=2, date_added=Wed Nov 26 14:58:59 2008
id=4
group_id=2
group_id2=8
date_added=2008-11-26 14:58:59
title=doc number four
content=this is to test groups

words:
1. ‘test’: 3 documents, 5 hits
D:sphinxbin>

Everyone has come out.

6. Test Chinese search

Modify the documents data table in the test database,

UPDATE `test`.`documents` SET `title` = 'Test Chinese', `content` = 'this is my test document number two, you should be able to find it' WHERE `documents`.`id` = 2 ;

Rebuild index:

D:sphinxbin>indexer.exe –all

Try searching for ‘中文’:

D:sphinxbin>search.exe Chinese
Sphinx 0.9.8-release (r1533)
Copyright (c) 2001-2008, Andrew Aksyonoff

using config file ‘./sphinx.conf’…
index ‘test1′: query ‘中文‘: returned 0 matches of 0 total in 0.000 sec

words:
D:sphinxbin>

It seems that it is not found. This is because the encoding in the windows command line is gbk, so of course it cannot be found. We can try it with a program, create a new file foo.php under D:sphinxapi, pay attention to utf-8 encoding

require ‘sphinxapi.php’;
$s = new SphinxClient();
$s->SetServer(’localhost’,3312);
$result = $s->Query('中文');
var_dump($result);
?>

Start Sphinx searchd service

D:sphinxbin>searchd.exe
Sphinx 0.9.8-release (r1533)
Copyright (c) 2001-2008, Andrew Aksyonoff

WARNING: forcing –console mode on Windows
using config file ‘./sphinx.conf’…
creating server socket on 0.0.0.0:3312
accepting connections

Execute PHP query:

php d:/sphinx/api/foo.php

Have the results come out? The remaining work is to read the manual and slowly explore the high-level configuration.

Articles you may be interested in

  • Installation and configuration tutorial of memcache under windows
  • How to run PHP files under the command line under windows
  • Implementation of sphinx Chinese full-text search
  • Master-slave synchronization backup steps of mysql database in windows environment
  • Installing memcache under windows system
  • How to install and configure PHP to run under Windows 7 Environment
  • How to determine whether a string is in English, pure Chinese, or a combination of Chinese and English
  • Windows cannot start this hardware because its configuration information (in the registry) is incomplete or damaged equipment. (Code 19) Solution

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/764167.htmlTechArticleI tried to use Sphinx a while ago, which can be used by various languages ​​​​(PHP/Python/Ruby/etc) Full-text search system that is easy to call. Most of the information on the Internet is for installation and use in the Linux environment...
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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

Can I install mysql on Windows 7 Can I install mysql on Windows 7 Apr 08, 2025 pm 03:21 PM

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

How to solve mysql cannot connect to local host How to solve mysql cannot connect to local host Apr 08, 2025 pm 02:24 PM

The MySQL connection may be due to the following reasons: MySQL service is not started, the firewall intercepts the connection, the port number is incorrect, the user name or password is incorrect, the listening address in my.cnf is improperly configured, etc. The troubleshooting steps include: 1. Check whether the MySQL service is running; 2. Adjust the firewall settings to allow MySQL to listen to port 3306; 3. Confirm that the port number is consistent with the actual port number; 4. Check whether the user name and password are correct; 5. Make sure the bind-address settings in my.cnf are correct.

Solutions to the errors reported by MySQL on a specific system version Solutions to the errors reported by MySQL on a specific system version Apr 08, 2025 am 11:54 AM

The solution to MySQL installation error is: 1. Carefully check the system environment to ensure that the MySQL dependency library requirements are met. Different operating systems and version requirements are different; 2. Carefully read the error message and take corresponding measures according to prompts (such as missing library files or insufficient permissions), such as installing dependencies or using sudo commands; 3. If necessary, try to install the source code and carefully check the compilation log, but this requires a certain amount of Linux knowledge and experience. The key to ultimately solving the problem is to carefully check the system environment and error information, and refer to the official documents.

MySQL can't be installed after downloading MySQL can't be installed after downloading Apr 08, 2025 am 11:24 AM

The main reasons for MySQL installation failure are: 1. Permission issues, you need to run as an administrator or use the sudo command; 2. Dependencies are missing, and you need to install relevant development packages; 3. Port conflicts, you need to close the program that occupies port 3306 or modify the configuration file; 4. The installation package is corrupt, you need to download and verify the integrity; 5. The environment variable is incorrectly configured, and the environment variables must be correctly configured according to the operating system. Solve these problems and carefully check each step to successfully install MySQL.

Unable to access mysql from terminal Unable to access mysql from terminal Apr 08, 2025 pm 04:57 PM

Unable to access MySQL from the terminal may be due to: MySQL service not running; connection command error; insufficient permissions; firewall blocks connection; MySQL configuration file error.

How to copy and paste mysql How to copy and paste mysql Apr 08, 2025 pm 07:18 PM

Copy and paste in MySQL includes the following steps: select the data, copy with Ctrl C (Windows) or Cmd C (Mac); right-click at the target location, select Paste or use Ctrl V (Windows) or Cmd V (Mac); the copied data is inserted into the target location, or replace existing data (depending on whether the data already exists at the target location).

How to pull the vertical reference line of PS How to pull the vertical reference line of PS Apr 06, 2025 pm 08:18 PM

Pull vertical guides in Photoshop: Enable ruler view (View &gt; ruler). Hover the mouse over the vertical edge of the ruler, and then the cursor becomes a vertical line with double arrows and hold and drag the mouse to pull out the reference line. Click Delete by dragging the guide, or hovering it into a cross.

Can vs code run in Windows 8 Can vs code run in Windows 8 Apr 15, 2025 pm 07:24 PM

VS Code can run on Windows 8, but the experience may not be great. First make sure the system has been updated to the latest patch, then download the VS Code installation package that matches the system architecture and install it as prompted. After installation, be aware that some extensions may be incompatible with Windows 8 and need to look for alternative extensions or use newer Windows systems in a virtual machine. Install the necessary extensions to check whether they work properly. Although VS Code is feasible on Windows 8, it is recommended to upgrade to a newer Windows system for a better development experience and security.

See all articles