PHP Implementation Search Class encapsulation example, PHP implementation encapsulation example
This article for everyone to share the PHP implementation of the search class package examples for your reference, the specific content as follows
<?php/** * soclass.php * Index and search class */class Soclass {private $_xindex; Private $_xsearch; Private $_project; Public function __construct ($project) {//Load 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 '); The Public Function query ($keyWord, $row =20, $jnum =0) {$xs = new xs ($this->_project); $xs->search->setfuzzy (); $xs->search->setautosynonyms (); $xs->search->setquery ($keyWord); Support synonym search, open by default $xs->search->setlimit ($row, $jnum); Set the return result to a maximum of 5 and skip the first 10 $docs = $xs->search->search (); Perform a search to save the search results document in a $docs array $count = $xs->search->count (); Gets the total number of matches for the search result 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 (); The Public Function Hotword ($num, $type = ' lastnum ') {return $this->_xsearch->gethotquery ($num, $type); The public function expanded ($keyWord) {return $this->_xsearch->getexpandedquery ($keyWord); } public Function LastCount () {return $this->_xsearch->getlastcount (); Public Function Index ($data, $update =0) {//Create Document Object $doc = new Xsdocument; $doc->setfields ($data); Add or update to the index database if (! $update) {$this->_xindex->add ($doc); }else{$this->_xindex->update ($doc); }} Public Function Delete ($idArray) {//delete index (primary key Delete Array (' 1 ', ' 2 ', ' 3 ')) $this->_xindex->del ($idArray); } Public Function addsynonym ($word 1, $word 2) {$this->_xindex->addsynonym ($word 1, $word 2); Public Function Clearindex () {$this->_xindex->clean (); }}?>
The above is the whole content of this article, I hope that you learn PHP programming help.
Articles you may be interested in:
- Search and highlight the implementation code for keywords within the PHP station
- Php+ajax do imitation Baidu search dropdown automatic prompt box (there are instances)
- PHP write to get each search Spider crawl record code
- PHP access to search engine keywords from the source of functions (support Baidu and Google and other search engines)
- Youdao Search and IP138 IP API interface (PHP application)
- PHP screen spider access code and common search engine http_user_agent
- How to search for associated array key values in PHP and get them
- thinkphp How to keep pagination in search state
- jquery+php automatic prompt for search box
- Thinkphp method of maintaining conditional paging for home page and search page when searching
http://www.bkjia.com/PHPjc/1117054.html www.bkjia.com true http://www.bkjia.com/PHPjc/1117054.html techarticle PHP Implementation Search class encapsulation example, PHP Implementation Package example this article for everyone to share the PHP implementation of the search class package examples for your reference, the specific content as follows php/** * soclass.php * index and search ...