Windows + sphinx + php installation + configuration + usage

Source: Internet
Author: User

This article describes how to install and configure sphinx in windows, how to use real-time indexes of sphinx and PHP, and how to add the sphinx service to the windows service.

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

1. install and configure sphinx in windows

1 .:

Http://sphinxsearch.com/downloads/ try to get a higher version, I'm using sph1_2.0.6-release,

Download and decompress the package to f:/sphinx (according to your situation ).

Copy the sphexample. conf. in file to/bin/sphexample. conf.

New: f:/sphinx/data folder

New: f:/sphfolder/log folder

2. modify the configuration file (see http://blog.csdn.net/design321/article/details/8895608 for detailed configuration)

# Minimal sphinx configuration sample (clean, simple, functional) # source src1 {# database information type = MySQL SQL _host = localhost SQL _user = root SQL _pass = 123456 SQL _db = test SQL _port = 3306 SQL _query_pre = set names utf8 SQL _query = select ID, group_id, unix_timestamp (date_added) as date_added, title, content from sorted ents SQL _attr_uint = group_id sorted = date_added SQL _query_info = select * From sorted ents where id = $ id} index Test2 {source = src1 Path = F: /sphinx/data/test1 // the newly created data directory docinfo = extern charset_type = UTF-8 min_prefix_len = 0 min_infix_len = 0 min_word_len = 1 ngram_len = 1 ngram_chars = u + 3000 .. U + 2fa1f charset_table = 0 .. 9, .. z-> .. z, _, .. z, U + 410 .. U + 42f-> U + 430 .. U + 44f, U + 430 .. U + 44f} indexer {mem_limit = 32 m} searchd {Port = 3312 log = F:/sphinx/log/searchd. log # New log directory # query_log = F:/sphinx/log/query. log # the newly created log directory read_timeout = 5 max_children = 30 pid_file = F:/sphinx/log/searchd. pid # New log directory max_matches = 1000 preopen_indexes = 0 unlink_old = 1 seamless_rotate = 0} # EOF

Configuration complete

3. Import test data to mysql

Run the example. SQL file in the test database.

Note that the imported data is not in utf8 format and you need to change the note set in the database.

4. Create an index

F:\sphinx\bin>indexer.exe --config f:/sphinx/bin/sphinx.conf --all

Sph00002.0.6-release (r3473)
Copyright (c) 2001-2012, Andrew Aksyonoff
Copyright (c) 2008-2012, sphsf-technologies Inc (http://sphinxsearch.com)

Using config file 'f:/sphinx/bin/sphinx. conf '...
Indexing index 'test2 '...
Collected 3 docs, 0.0 MB
Sorted 0.0 Mhits, 100.0% done
Total 3 docs, 138 bytes
Total 0.011 sec, 12402 bytes/sec, 269.61 docs/sec
Total 2 reads, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avg
Total 9 writes, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avg

5. Search

F:\sphinx\bin>search.exe test

Sph00002.0.6-release (r3473)
Copyright (c) 2001-2012, Andrew Aksyonoff
Copyright (c) 2008-2012, sphsf-technologies Inc (http://sphinxsearch.com)

Using config file './sphexample. conf '...
Index 'test2': query 'test': returned 3 matches of 3 total in 0.000 sec

Displaying matches:
1. document = 2, weight = 2252, group_id = 1, date_added = Mon May 06 18:43:15 2013
Id = 2
Group_id = 1
Group_id2 = 6
Date_added = 2013-05-06 18:43:15
Title = test two
Content = ?? This is my test document number two
2. Document = 3, Weight = 1319, group_id = 2, date_added = mon May 06 18:43:15 2013
Id = 3
Group_id = 2
Group_id2 = 7
Date_added = 2013-05-06 18:43:15
Title = another doc
Content = this is another group ?? Test
3. document = 4, weight = 1319, group_id = 2, date_added = Mon May 06 18:43:15 2013
Id = 4
Group_id = 2
Group_id2 = 8
Date_added = 2013-05-06 18:43:15
Title = doc number four
Content = this is to test groups ??

Words:
1. 'test': 3 documents, 4 hits

The installation is successful.

2. Enable PHP to use sphinx

1. Start the sphinx Service

F:\sphinx\bin>searchd.exe

Sph00002.0.6-release (r3473)
Copyright (c) 2001-2012, Andrew Aksyonoff
Copyright (c) 2008-2012, sphsf-technologies Inc (http://sphinxsearch.com)

Using config file './sphexample. conf '...
WARNING: compat_sphinxql_magics = 1 is deprecated; please update your application
And config
Listening on all interfaces, port = 3312
Precaching index 'test2'
Precached 1 indexes in 0.002 sec
Binlog: replaying log./binlog.001

2. Copy F: \ sphinx \ api \ sphinxapi. php to the website directory under apach for calling.

3. Simple examples of using existing Indexes

<? Phprequire 'sphinxapi. php '; $ s = new SphinxClient (); $ s-> SetServer ('2017. 0.0.1 ', 3312); // server name, sphsf-port number $ result = $ s-> Query ('test', 'test2'); // keyword, index name (same as in the configuration file, * indicates all) echo '<pre>'; var_dump ($ result); echo '<pre>';?>

4. Example of creating a real-time index

<? PHP require 'sphinxapi. PHP '; $ keyword = 'Chinese'; $ sphsf-= new sphinxclient (); $ sphsf--> setserver ("localhost", 3312); $ sphsf--> setmatchmode (sph_match_any ); // $ sphits-> setlimits (); // offset $ result = $ sphits-> query ("$ keyword", "Test2 "); // echo "<PRE>"; // print_r ($ result); // echo "</PRE>"; $ IDs = join (",", array_keys ($ result ['matches']); mysql_connect ("localhost", "root", "123456"); mysql_select_db ("test "); $ SQL = "select * from statements where ID in ({$ IDs})"; mysql_query ("set names utf8"); $ rst = mysql_query ($ SQL ); $ opts = array ("before_match" => "<button style = 'font-weight: bold; color: # f00'> ", "after_match" => "</button>"); While ($ ROW = mysql_fetch_assoc ($ RST) {$ rst2 = $ sphsf-> buildexcerpts ($ row, "Main", $ keyword, $ opts); echo '<PRE>'; var_dump ($ row); echo ''; /* echo "post {$ rst2 [0]} <br>"; echo "title: {$ rst2 [1]} <br>"; echo "content: {$ rst2 [2]} <br> "; echo" <HR> ";*/}

3. Add the sphinx service to the windows Service

F:\sphinx\bin>searchd.exe --install -c f:\sphinx\bin\sphinx.conf --servicename s

Phonics
Sph00002.0.6-release (r3473)
Copyright (c) 2001-2012, Andrew Aksyonoff
Copyright (c) 2008-2012, sphsf-technologies Inc (http://sphinxsearch.com)

Installing service...
Service 'pushcallback' installed successfully.

F:\sphinx\bin>net start sphinx

The sphworker service is starting.
The sphinx service has been started successfully.

F:\sphinx\bin>net stop sphinx

The sphworker service is stopping ..

The sphinx service has been stopped successfully.

F:\sphinx\bin>sc delete sphinx

[SC] DeleteService SUCCESS

End.

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.