Enable Sphinx Full-text Search and instance

Source: Internet
Author: User

There are a lot of sphinx when compiling the installationChinesegarbled, and finally throws the error stuck. I go to the official download an RPM package directly, the installation is very cool ... The specific error does not want to study. Busy to develop it ~ ~


Install two packages. One is mmseg this is the generation of the Chinese dictionaryprogramOne is csft, the Chinese version of Sphinx.


RPM-IVH after the installation is complete. Very smooth ~ ~ In less than half a minute to install the finished ...


Lazy, Chinese dictionary library, I went directly to the csft official download. Very good thought very thoughtful ...


Unigram.txt Uni.lib


Unigram.txt dictionary text, you can add your own keywords inside


and then use


Mmseg-u Unigram.txt Dictionary Generationfile: Unigram.txt.uni Then rename uni.lib This is Sphinx know the dictionary.


Where to put it? Put in the dictionary path that you have configured inside the sphinx.conf.


And then basically, almost.


Look at the Sphinx a few practical programs


[Root@beihai365/]# csft-


Csft-indexer Csft-search Csft-searchd


Csft-indexer is the program that generates the Full-text search index


Csft-search is to test whether the search is effective or not, and it works well, as I have no use for client script development, you can use this to see if Full-text search is successful


Csft-searchd This is the Sphinx search daemon. After startup, you can use scripting Php python and so on, openQueryOut.


It's so simple ~ ~


Look at the two key parts.


sphinx.conf configuration file


View Plaincopy to Clipboardprint?


SOURCE Tmsgs


{


Type =MySQL


Sql_host = localhost


Sql_user = root


Sql_pass = 1


sql_db = PHPWIND75SP3


Sql_port = 3306 # optional, default is 3306


#sql_sock =/tmp/mysql3307.sock


Sql_query_pre = SET NAMES GBK


Sql_query = SELECT Id,name,type,stock from Pw_tools


#sql_attr_uint = ID


Sql_attr_uint = Stock


}





Index Tmsgsindex


{


Source = Tmsgs


Path =/var/mmseg/searchdata/beihai365


DocInfo = extern


Charset_type = ZH_CN.GBK


#min_prefix_len = 0


#min_infix_len = 2


#ngram_len = 2


Charset_dictpath =/var/mmseg/data


#min_prefix_len = 0


#min_infix_len = 0


#min_word_len = 2


}





Indexer


{


Mem_limit = 128M


}





Searchd


{


#listen = 3312


Log =/var/log/searchd.log


Query_log =/var/log/query.log


Read_timeout = 5


Max_children = 30


Pid_file =/var/log/searchd.pid


max_matches = 1000


#seamless_rotate = 1


#preopen_indexes = 0


#unlink_old = 1


}


SOURCE Tmsgs


{


Type = MySQL


Sql_host = localhost


Sql_user = root


Sql_pass = 1


sql_db = PHPWIND75SP3


Sql_port = 3306 # optional, default is 3306


#sql_sock =/tmp/mysql3307.sock


Sql_query_pre = SET NAMES GBK


Sql_query = SELECT Id,name,type,stock from Pw_tools


#sql_attr_uint = ID


Sql_attr_uint = Stock


}


Index Tmsgsindex


{


Source = Tmsgs


Path =/var/mmseg/searchdata/beihai365


DocInfo = extern


Charset_type = ZH_CN.GBK


#min_prefix_len = 0


#min_infix_len = 2


#ngram_len = 2


Charset_dictpath =/var/mmseg/data


#min_prefix_len = 0


#min_infix_len = 0


#min_word_len = 2


}


Indexer


{


Mem_limit = 128M


}


Searchd


{


#listen = 3312


Log =/var/log/searchd.log


Query_log =/var/log/query.log


Read_timeout = 5


Max_children = 30


Pid_file =/var/log/searchd.pid


max_matches = 1000


#seamless_rotate = 1


#preopen_indexes = 0


#unlink_old = 1


}





Look at the test client again.Code


View Plaincopy to Clipboardprint?


<?php


Header ("content-type:text/HTML; Charset=utf-8 ");


Include ' sphinxapi.php ';


$CL = new Sphinxclient ();


$cl->setserver (' localhost ', 3312);


$CL->setmatchmode (Sph_match_all);


$cl->setarrayresult (TRUE);


$res = $cl->query ("name card", "*");


Print_r ($res);





?>


<?php


Header ("Content-type:text/html;charset=utf-8");


Include ' sphinxapi.php ';


$CL = new Sphinxclient ();


$cl->setserver (' localhost ', 3312);


$CL->setmatchmode (Sph_match_all);


$cl->setarrayresult (TRUE);


$res = $cl->query ("name card", "*");


Print_r ($res);





?>


The keyword "name card" was added to my dictionary manually. To see if I can actually search


View Plaincopy to Clipboardprint?


Array


(


[ERROR] =>


[WARNING] =>


[Status] => 0


[Fields] => Array


(


[0] => name


[1] => type


)





[Attrs] => Array


(


[Stock] => 1


)





[Matches] => Array


(


[0] => Array


(


[ID] => 8


[Weight] => 1


[Attrs] => Array


(


[Stock] => 100


)





)





)





[Total] => 1


[Total_found] => 1


[Time] => 0.018


[Words] => Array


(


[Name card] => Array


(


[Docs] => 1


[Hits] => 1


)





)





)


Array


(


[ERROR] =>


[WARNING] =>


[Status] => 0


[Fields] => Array


(


[0] => name


[1] => type


)


[Attrs] => Array


(


[Stock] => 1


)


[Matches] => Array


(


[0] => Array


(


[ID] => 8


[Weight] => 1


[Attrs] => Array


(


[Stock] => 100


)


)


)


[Total] => 1


[Total_found] => 1


[Time] => 0.018


[Words] => Array


(


[Name card] => Array


(


[Docs] => 1


[Hits] => 1


)


)


)


No problem at all. The search came out.


A few key operations


[root@beihai365/]# csft-searchd--stop Stop search Guardian


[root@beihai365/]# csft-indexer--all generates indexes for all nodes. You can also generate indexes for a node, such as: Csft-indexer XX


[root@beihai365/]# csft-search app search keyword app. But look at the following information not found and did not hit any of the documents.


Coreseek Full Text Server 3.1


Copyright (c) 2006-2008 coreseek.com


Using config file './csft.conf ' ...


1,


Pt:1, 1; Index ' tmsgsindex ': Query ' App ': returned 0 matches of 0 Total in 0.017 sec


Words


1. ' App ': 0 documents, 0 hits


When you are running these commands, find the path to your own manual sticky--config sphinx.conf configuration file. It's not convenient.


So I simply ln-s one in./. It doesn't have to be typing--config every time.

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.