Php implements the search encapsulation example, and php implements the encapsulation example. Php implements a search encapsulation example. php implements an encapsulation example. This article shares an example of php implements a search encapsulation for your reference. the specific content is as follows: php *** SoClass. php * index and search php implement search class encapsulation example, php implement encapsulation example
This article will share with you an example of how php implements search encapsulation for your reference. the specific content is as follows:
<? Php/*** SoClass. php * index and search class */class SoClass {private $ _ xindex; private $ _ xsearch; private $ _ project; public function _ construct ($ project) {// load the boot file require_once 'Lib/XS. php '; // initialize $ xs = new XS ($ project); $ this-> _ project = $ project; $ this-> _ xindex = $ xs-> index; $ this-> _ xsearch = $ xs-> search; $ this-> _ xsearch-> setCharset ('utf-8');} public function query ($ keyWord, $ row = 20, $ jnum = 0) {$ xs = new XS ($ This-> _ project); $ xs-> search-> setFuzzy (); $ xs-> search-> setAutoSynonyms (); $ xs-> search-> setQuery ($ keyWord); // You can search for synonyms. $ xs-> search-> setLimit ($ row, $ jnum) is enabled by default ); // set the maximum number of returned results to 5, and skip the first 10. $ docs = $ xs-> search (); // execute the search, save the search result document in the $ docs array $ count = $ xs-> search-> count (); // obtain the total number of matching results if ($ count) {$ data = array (); foreach ($ docs as $ key = >$ doc) {$ data [$ key] ['pid '] = $ doc-> pid; $ data [$ key] ['nid'] = $ Doc-> nid; $ data [$ key] ['Category '] = $ doc-> category; $ data [$ key] ['URL'] = $ doc-> url; $ data [$ key] ['name'] = $ xs-> search-> highlight (htmlspecialchars ($ doc-> name )); $ data [$ key] ['message'] = $ xs-> search-> highlight (htmlspecialchars ($ doc-> message ));} return array ('data' => $ data, 'count' => $ count);} return array ();} public function hotWord ($ num, $ type = 'lastnum') {return $ this-> _ xsearch-> getHotQuery ($ nu M, $ type);} public function expanded ($ keyWord) {return $ this-> _ xsearch-> getExpandedQuery ($ keyWord);} public function lastCount () {return $ this-> _ xsearch-> getLastCount ();} public function index ($ data, $ update = 0) {// create a document object $ doc = new XSDocument; $ doc-> setFields ($ data); // add or update to index database if (! $ Update) {$ this-> _ xindex-> add ($ doc);} else {$ this-> _ xindex-> update ($ doc );}} public function delete ($ idArray) {// delete an index (primary key deletes an array ('1', '2', '3 ')) $ this-> _ xindex-> del ($ idArray);} public function addSynonym ($ word1, $ word2) {$ this-> _ xindex-> addSynonym ($ word1, $ word2);} public function clearIndex () {$ this-> _ xindex-> clean () ;}}?>
The above is all the content of this article. I hope it will help you learn php programming.
Articles you may be interested in:
- Php site code for searching and highlighting keywords
- Php + ajax do imitation Baidu search drop-down automatic prompt box (with instances)
- PHP code for retrieving crawling records of search Spider
- PHP functions for retrieving search engine keyword sources (support for search engines such as Baidu and Google)
- Youdao search and IP138 ip api (PHP application)
- PHP shields spider access code and HTTP_USER_AGENT of common search engines
- In php, how do I search for the associated array key value and obtain it?
- ThinkPHP method for retaining the search status by page
- Jquery + php enables automatic prompt in the search box
- How to maintain conditional paging on the home page and search page during Thinkphp search
This article shares examples of php search encapsulation for your reference. the specific content is as follows: php/*** SoClass. php * index and search...