Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install sphinx engine in Windows

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to install the sphinx engine in Windows. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

1 install the sphinx engine first

Download address: http://sphinxsearch.com/downloads/archive/

The directory structure downloaded is as follows

Put sphinx.conf.in in charge of renaming sphinx.conf and put it under bin directory. Modify sphinx.conf. Pay attention to the creation of log directory and data directory. It will not be created automatically under windows.

# data sources

Source src1

{

Type = mysql

Sql_host = 78.47.160.11

Sql_user = hello

Sql_pass = hello

Sql_db = ama_db

Sql_port = 3306 # optional, default is 3306

# indexed data sources

Sql_query = SELECT * FROM tbl_user

Sql_attr_uint = group_id

Sql_attr_timestamp = date_added

# query conditions to be used for query

Sql_query_info = SELECT * FROM tbl_user WHERE user_id=$id

}

# Index

Index test1

{

Source = src1

Path = D:/sphinx/data/

Charset_type = utf-8

# simple word segmentation. Only 0 and 1 are supported. If you want to search Chinese, please specify 1.

Ngram_len = 1

# A word segmentation character is required. If you want to search Chinese, remove the previous comments.

Ngram_chars = U+3000..U+2FA1F

}

Indexer

{

Mem_limit = 80m

}

# search process

Searchd

{

Listen = 9312

Listen = 9306:mysql41

Log = D:/sphinx/log/searchd.log

Query_log = D:/sphinx/log/query.log

Read_timeout = 5

Max_children = 30

Pid_file = D:/sphinx/log/searchd.pid

Max_matches = 1000

Seamless_rotate = 1

Preopen_indexes = 1

Unlink_old = 1

Workers = threads # for RT to work

Binlog_path = D:/sphinx/binlog/

}

Before you can create an index, the database you connect to must have this table data tbl_user

Then run. / indexer.exe test1 (index name) under the bin directory

If you see this interface, it proves that the index has been created.

Here's how to witness a miracle. Use the command to verify that something can be searched, and use the command. / search.exe "cus_CjTmevgv423JEa"

If you can see this interface, it will prove that the index is already in effect. Congratulations.

How to use php to operate sphinx

First of all, install the sphinx extension of php, download it at https://pecl.php.net/package/sphinx/1.3.3/windows, and find the extension you need corresponding to the version of php.

The downloaded directory is as follows

We just need to put the php_sphinx.dll file in the ext file of php, add extension=php_sphinx.dell under php.ini, and restart apache or nginx.

It has been successfully installed.

Start the searchd of sphinx with the command. / searchd.exe-- pidfile

Then you can download some operation packages installed by others to operate sphinx, or you can use extended methods to create a test.php.

$s = new\ SphinxClient

$s-> setServer ("127.0.0.1", 9312)

$s-> setMatchMode (SPH_MATCH_ALL)

/ / $s-> SetMatchMode (SPH_MATCH_EXTENDED2); / / set mode

/ / $s-> SetRankingMode (SPH_RANK_PROXIMITY); / / set the scoring mode

/ / $s-> SetFieldWeights (['art_product_group'= > 2,' art_name'= > 1,])

$s-> SetLimits ((1-1) * 32, 1000, 1000)

$s-> SetMaxQueryTime (1000)

/ / sort

$s-> SetSortMode (SPH_SORT_RELEVANCE)

/ / $s-> SetSortMode (SPH_SORT_EXPR,'@weight'); / / sort by weight

/ / $search ='*'. $search.'*'

$search = "zhongchengbin"

$res = $s-> query ($search,'test1')

Echo ""

Var_dump ($res)

Echo ""

Run localhost/test.php in a browser

At this point, the entire sphinx search engine has been built. If it is a linux environment, it is necessary to assign a timing task to update the index and open the search daemon.

Matches is the result of the query, but it doesn't seem to be the data we want. For example, the content of the titile,content field has not been queried. According to the official statement, Sphinx is not connected to MySQL to get the data, but is only calculated according to its own index content. Therefore, if we want to use the API provided by Sphinx to get the data we want, we must also rely on the query results. Query MySQL again to get the data we want.

The key values in the query results indicate that the 2 unique primary key weight weight attrs sql_attr_* is configured so far, the search engine is more than half complete, and the rest can be done on your own.

For example:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report