The installation

Assuming you have Homebrew installed on your system, execute the following command:

➜ ~ brew install MySQL

Start the MySQL:

➜  ~ mysql.server start

MySQL > disable MySQL >

➜  ~ mysql.server stop

Install Sphinx and support MySQL:

Brew install ➜ ~ # sphinx sphinx - with - mysql default installed in/usr/local/Celler/sphinx / / version number

Install the Sphinx extension for PHP

➜  ~ brew install homebrew/php/php56-sphinx
# PHP-Sphinx 扩展默认安装在 /usr/local/Cellar/php56-sphinx/[版本号]/

Verify that the installation of Sphinx and extensions was successful

Step 1: Configure Sphinx to connect to the database

The configuration file: / usr/local/Celler/sphinx sphinx. Conf

# If the configuration file does not exist, copy sphinx.conf.dist to sphinx.conf # Source src1 {type = mysql // IP sql_user = user // sql_pass = pass // IP src1 {type = mysql // IP sql_user = user // SQL_PORT = 3306 // Database port....

By default, you only need to change the database username and password.

Step 2: Create a new test database in the database that will be indexed by Sphinx

➜ ~ mysql-u root-p // mysql> create database test; Mysql > create database test > exit; Exit / / mysql / / import test data mysql -u/database username - p/database password < / usr/local/Cellar/sphinx / / version number/etcexample SQL

If there are no errors, the database has been created successfully. Next build the index.

Step 3: Build indexes using Indexer

➜ ~ / usr/local/Cellar/sphinx / / version number/bin/indexer - all

The output is as follows (version number may vary) :

Sphinx 2.2.10-ID64-Release (2C212E0) Copyright (C) 2001-2015, Andrew Aksyonoff Copyright (C) 2008-2015, Sphinx Technologies Inc (http://sphinxsearch.com) using the config file '/ usr/local/Cellar/Sphinx / 2.2.10 / etc/Sphinx. Conf'...  indexing index 'test1'... Collected 4 docs, 0.0MB sorted 0.0Mhits, 100.0% done total 4 docs, 193 bytes total 0.160 SEC, 1198 bytes/ SEC, 24.84 docs/ SEC indexing index 'test1stemmed'... Collected 4 docs, 0.0MB sorted 0.0Mhits, 100.0% done total 4 docs, 193 bytes total 0.005 SEC, 32339 bytes/ SEC, Collected 4 docs, 0.0MB sorted 0.0Mhits, 100.0% done total 4 docs, 32339 bytes/ SEC, Skipping Non Plain Index 'DIST1' for Skipping Non Plain Index 'DIST1 '... skipping non-plain index 'rt'... Total 8 reads, 0.000 SEC, 0.1kb /call AVG, 0.0 msec/call AVG total 24 writes, 0.000 SEC, 0.1kb /call AVG, 0.0 MSEC /call AVG rolling indices: successfully sent SIGHUP to searchd (PID =1342).

Step 4: Start searchd

➜  ~ searchd

Enter the following information:

Sphinx 2.2.10-ID64-Release (2C212E0) Copyright (C) 2001-2015, Andrew Aksyonoff Copyright (C) 2008-2015, Sphinx Technologies Inc (http://sphinxsearch.com) using the config file '/ usr/local/Cellar/Sphinx / 2.2.10 / etc/Sphinx. Conf'...  listening on all interfaces, port=9312 listening on all interfaces, Port =9306 Precaching Index 'Test1' Precaching Index 'Test1Stemmed' Precached Index 'RT' Precached 3 Indexes in 0.003 sec

The above information appears, indicating that the startup was successful!

Step 5: Use PHP to verify that Sphinx and the extension were successfully installed

<? php header('Content-type: text/html; charset=utf-8'); // Check whether the php-spinx module is installed successfully if (! In_array (' Sphinx ', get_loaded_extensions())) {die(' Module does not exist, please check! '); } $docs = array ( "this is my test text to be highlighted, and for the sake of the testing we need to pump its length somewhat", "another test text to be highlighted, below limit", "test number three, without phrase match", "final test, not only without phrase match, but also above limit and with swapped phrase text test as well", ); $words = "test text"; $index = "test1"; $opts = array ( "before_match" => "<b>", "after_match" => "</b>", "chunk_separator" => " ... ", "limit" => 60, "around" => 3, ); Foreach (array(0,1) as exact) {$exact ["exact_phrase"] = $exact; print "exact_phrase=$exact\n"; $cl = new SphinxClient (); $res = $cl->BuildExcerpts ( $docs, $index, $words, $opts ); if ( ! $res ) { die ( "ERROR: " . $cl->GetLastError() . ".\n" ); } else { $n = 0; foreach ( $res as $entry ) { $n++; print "n=$n, res=$entry\n"; } print "\n"; }}

The above source output:

exact_phrase=0
n=1, res=this is my <b>test</b> <b>text</b> to be highlighted,  ... 
n=2, res=another <b>test</b> <b>text</b> to be highlighted, below limit
n=3, res=<b>test</b> number three, without phrase match
n=4, res=final <b>test</b>, not only  ... with swapped phrase <b>text</b> <b>test</b> as well

exact_phrase=1
n=1, res=this is my <b>test text</b> to be highlighted,  ... 
n=2, res=another <b>test text</b> to be highlighted, below limit
n=3, res=test number three, without phrase match
n=4, res=final test, not only without phrase match, but also above  ... 

Done!