In recent days, a social worker library has been built for friends. The framework is Sphinx+PHP+Mysql. But the documents attached to the source code are poorly written, and it's under linux, so I found some relevant information to configure, write it out and share it with you. The general source code effect map is as follows (you can search for the source code to download by yourself):
Code resource screenshots are as follows:
order
Here only configuration is provided, no data is provided, because I do not have, equivalent to technical research.
_Briefly introduced, Sphinx is a full-text search engine based on SQL, which can be used when the amount of database data is relatively large, and the retrieval efficiency is high, as well as the specific concept of Baidu Encyclopedia. coreseek is a sphinx-based framework and supports Chinese word segmentation. That is to say, it is enough to install coreeek. The download connection of the official website is as follows:
Portal
Note: This article may require some basic knowledge of the programming industry. Pure white needs to clarify these concepts by herself.
Environment: Windows 7.
1. Install and configure wampserver:
wampserver integrates appache, php, mysql, and can build the web end more conveniently. The concept does not need to say that the configuration method is Baidu itself. If you want to be able to run the web, you have the opportunity to write again.
It's lazy, just drop a connection (casual connection, better if you need to find it yourself):
Portal
After configuring, put the code in the web directory of the wamserver you configure (ignore the txt folder, style.css, test.php, which I changed myself):
_Install navicat (the tool to connect mysql), find and download the cracked version from the Internet by oneself. After installation, you should be able to connect to it.
Run the following commands to create mysql users and databases:
-- Create a database
CREATE DATABASE `Worker`;
-- Create users and roles
-- CREATE USER 'ACCOUNT_ACC'@'localhost' IDENTIFIED BY '7ujm*IK<';
-- GRANT SELECT, INSERT, UPDATE ON `KC_ACCOUNT`.* TO 'ACCOUNT_ACC'@'localhost';
-- Mode two
GRANT USAGE ON *.* TO 'ygg'@'localhost' IDENTIFIED BY '654321';
GRANT SELECT, INSERT, UPDATE , DELETE, CREATE ON `Worker`.* TO 'ygg'@'localhost';
Download coreseek:
1. Install coreseek:
Download the coreseek and extract it to the directory you want, even if it is installed (ignore start.cm)
d. That's the startup script I wrote:
Turi has made it clear, so I won't say much about it.
2. Testing coreseek:
The test method is not really much to say, but it is helpful to configure and quote from others.
Portal:
Step 1: Import test data in mysql:
Set up a user table and insert a few pieces of data.
use worker;
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`id` int(9) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(255) default NULL,
`password` varchar(255) default NULL,
`email` varchar(255) default NULL,
KEY `username` (`username`),
KEY `email` (`email`)
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
-- ----------------------------
-- Records of users
-- ----------------------------
INSERT INTO `users` VALUES (1,'acn', '123456', '617925118@qq.com');
Step 2: Establish a configuration file:
Create a test.conf in the previously installed coreseek-4.1-win32\et directory and change its contents to the following:
source mysql
{
type = mysql
sql_host = localhost #Database Address
sql_user = ygg #Database username
sql_pass = 654321 #Database password
sql_db = worker #Database name
sql_port = 3306 #Port number
sql_query_pre = SET NAMES utf8 #Setting Character Set
sql_query = SELECT id,username,email FROM members #sql statement
sql_attr_timestamp = addtime
}
index mysql
{
source = mysql
path = E:/coreseek-4.1-win32/var/data/test #index catalogue
charset_dictpath = E:/coreseek-4.1-win32/etc/
charset_type = zh_cn.utf-8 #Code
}
searchd
{
listen = 9312 #Monitor port
max_matches = 1000 #Maximum number of queries
pid_file = E:/coreseek-4.1-win32/var/log/searchd_mysql.pid
log = E:/coreseek-4.1-win32/var/log/searchd_mysql.log
query_log = E:/coreseek-4.1-win32/var/log/query_mysql.log
}
Most of the parameters are very simple, let's not say much, understand.
Step 3: Generate an index:
Open cmd
Input:
E: coreseek-4.1-win32 bin indexer-c E: coreseek-4.1-win32\ etc test.conf-all generates an index.
Step 4: Start Sphinx:
On the same command line:
E:\coreseek-4.1-win32\bin\searchd –c E:\coreseek-4.1-win32\etc\test.conf
Configuration and start-up:
Modify mysqlcsft.conf to read as follows (of course, database, usernames are replaced by themselves) and place it in the E: coreseek-4.1-win32 etc directory:
source spdb1
{
type = mysql
sql_host = 127.0.0.1
sql_user = ygg
sql_pass = 654321
sql_db = worker
sql_port = 3306
sql_query_pre = SET NAMES utf8
sql_query = SELECT `id`, 1 AS table_id, `username`, `email`, `password` FROM spdb1
sql_attr_uint = table_id #Values read from SQL must be integers
#sql_attr_timestamp = date_added #Values read from SQL must be integers as time attributes
sql_query_info_pre = SET NAMES utf8 #When querying from the command line, set the correct character set
sql_query_info = SELECT * WHERE ID=$id #Read raw data information from the database when querying from the command line
}
source spdb2 : spdb1
{
sql_query = SELECT `id`, 2 AS table_id, `username`, `email`, `password` FROM spdb2
}
source spdb3 : spdb1
{
sql_query = SELECT `id`, 3 AS table_id, `username`, `email`, `password` FROM spdb3
}
source spdb4 : spdb1
{
sql_query = SELECT `id`, 4 AS table_id, `username`, `email`, `password` FROM spdb4
}
source spdb5 : spdb1
{
sql_query = SELECT `id`, 5 AS table_id, `username`, `email`, `password` FROM spdb5
}
#index definition
index spdb1
{
source = spdb1 #The corresponding source name
path = E:/coreseek-4.1-win32/var/data/spdb1 #Please modify the absolute path to be actually used as follows: / usr/local/coreseek/var /...
docinfo = extern
mlock = 0
morphology = none
min_word_len = 1
ondisk_dict = 1
html_strip = 0
#For Chinese word segmentation configuration, see http://www.coreseek.cn/products-install/coreseek_mmseg/
charset_dictpath = E:/coreseek-4.1-win32/etc/ #In Windows environment, it's better to give an absolute path at the end of the symbol, such as C:/usr/local/coreseek/etc/...
charset_type = zh_cn.utf-8
enable_star = 0 #Not using wildcards, not enabled by default, you can not write
min_infix_len=1 #With an infix index and a minimum index of 1, the manuals can be queried by those who do not know about this function.
infix_fields= username,email #Because infix index can cause the index volume to expand sharply, it is better to choose a few fields which you think are the most important to do the infix index. (Fuzzy Query)
}
index spdb2 : spdb1
{
source = spdb2
path = E:/coreseek-4.1-win32/var/data/spdb2
}
index spdb3 : spdb1
{
source = spdb3
path = E:/coreseek-4.1-win32/var/data/spdb3
}
index spdb4 : spdb1
{
source = spdb4
path = E:/coreseek-4.1-win32/var/data/spdb4
}
index spdb5 : spdb1
{
source = spdb5
path = E:/coreseek-4.1-win32/var/data/spdb5
}
#Global index definition
indexer
{
mem_limit = 512M #Default 32M, don't be too big, otherwise you will report an error.
}
#searchd service definition
searchd
{
listen = 9312 #Query service listener port, open before work
read_timeout = 5 #overtime
max_children = 30 #Maximum process
max_matches = 1000 #Return 1000
seamless_rotate = 0
preopen_indexes = 0
unlink_old = 1
pid_file = E:/coreseek-4.1-win32/var/log/searchd.pid #Modify to the actual absolute path, such as: / usr/local/coreseek/var /...
log = E:/coreseek-4.1-win32/var/log/searchd.log #Modify to the actual absolute path, such as: / usr/local/coreseek/var /...
query_log = E:/coreseek-4.1-win32/var/log/query.log #Modify to the actual absolute path, such as: / usr/local/coreseek/var /...
binlog_path = #Close the binlog log log
compat_sphinxql_magics = 0
}
Create the start.cmd script in the E: coreseek-4.1-win32 directory and use it to start later
As shown in the picture:
The contents are as follows:
@SET path=.;bin;%path%
@indexer -c etc\mysqlcsft.conf --all
@searchd -c etc\mysqlcsft.conf
Modify index.php, change mysql password and other data:
// Return result settings
$cl->SetServer('127.0.0.1', 9312);
$cl->SetConnectTimeout(3);
$cl->SetArrayResult(true);
// Set whether the full text matches
/* if (!empty($_GET) && !empty($_GET['f']))
{
$cl->SetMatchMode(SPH_MATCH_ANY);
} */
//$cl - > SetMatchMode (SPH_MATCH_ANY); // Set to any match
$cl->SetMatchMode(SPH_MATCH_PHRASE);//Similar to like
if (!empty($_GET) && !empty($_GET['p']))
{
$p = !intval(trim($_GET['p'])) == 0 ? intval(trim($_GET['p'])) - 1 : 0;
$p = $p * 20;
// I set the maximum number of returns to sed.conf to 1000. But when I generate page numbers, I can generate up to 20 pages, and I think I can meet most of the search needs.
// The following statement indicates that 20 items are returned at a time starting with the P parameter offset.
$cl->setLimits($p, 20);
} else
{
$cl->setLimits(0, 20);
}
$res = $cl->Query("$Keywords", "*");
//var_dump($res);
@mysql_connect("127.0.0.1", "ygg", "654321"); //Database Account Password
mysql_select_db("worker"); //Database name
mysql_query("set names utf8");
$tables = ['spdb1' ,'spdb2','spdb3','spdb4','spdb5']; //Put table names in arrays
_Almost all the modifications have been completed. You can start it directly. Start wampserver first, then double-click start.cmd to start coreseek:
That's it. Slowly import the data.