| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 lmb_require('limb/dbal/src/query/lmbInsertQuery.class.php'); 10 lmb_require('limb/dbal/src/query/lmbSelectQuery.class.php'); 11 lmb_require('limb/dbal/src/criteria/lmbSQLFieldCriteria.class.php'); 12 lmb_require('limb/dbal/src/query/lmbUpdateQuery.class.php'); 13 14 /** 15 * class lmbFullTextSearchIndexer. 16 * 17 * @package search 18 * @version $Id: lmbFullTextSearchIndexer.class.php 5945 2007-06-06 08:31:43Z pachanga $ 19 */ 20 class lmbFullTextSearchIndexer 21 { 22 protected $normalizer = null; 23 24 protected $left_bound = '<!-- no index start -->'; 25 protected $right_bound = '<!-- no index end -->'; 26 protected $use_noindex = false; 27 28 protected $conn; 29 30 function __construct($normalizer) 31 { 32 $this->normalizer = $normalizer; 33 $this->conn = lmbToolkit :: instance()->getDefaultDbConnection(); 34 } 35 36 function useNOINDEX($status = true) 37 { 38 $this->use_noindex = $status; 39 } 40 41 function index($uri, $content) 42 { 43 $title = $this->_extractTitle($content); 44 $content = $this->_getIndexedContent($content); 45 46 $content = $this->normalizer->process($content); 47 48 if($record = $this->findIndexRecordByUri($uri)) 49 { 50 $this->_updateIndexRecordById($record->get('id'), $content, $title); 51 return $record->get('id'); 52 } 53 else 54 return $this->_insertNewIndexRecord($uri, $content, $title); 55 } 56 57 function _getIndexedContent($content) 58 { 59 if(!$this->use_noindex) 60 return $content; 61 62 $regex = '~' . 63 preg_quote($this->left_bound) . 64 '(.*?)' . 65 preg_quote($this->right_bound) . 66 '~s'; 67 68 return preg_replace($regex, ' ', $content); 69 } 70 71 function _extractTitle(&$content) 72 { 73 $regex = '~<title>([^<]*)</title>~'; 74 if(preg_match($regex, $content, $matches)) 75 return $matches[1]; 76 else 77 return ''; 78 } 79 80 function _insertNewIndexRecord($uri, $content, $title) 81 { 82 $query = new lmbInsertQuery(FULL_TEXT_SEARCH_INDEXER_TABLE, $this->conn); 83 $query->addField('uri', $uri->toString()); 84 $query->addField('content', $content); 85 $query->addField('last_modified', time()); 86 $query->addField('title', $title); 87 $stmt = $query->getStatement(); 88 return $stmt->insertId('id'); 89 } 90 91 function _updateIndexRecordById($id, $content, $title) 92 { 93 $query = new lmbUpdateQuery(FULL_TEXT_SEARCH_INDEXER_TABLE, $this->conn); 94 $query->addField('content', $content); 95 $query->addField('last_modified', time()); 96 $query->addField('title', $title); 97 $query->addCriteria(new lmbSQLFieldCriteria('id', $id)); 98 $stmt = $query->getStatement(); 99 $stmt->execute(); 100 } 101 102 function findIndexRecordByUri($uri) 103 { 104 $query = new lmbSelectQuery(null, $this->conn); 105 $query->addTable(FULL_TEXT_SEARCH_INDEXER_TABLE); 106 $query->addCriteria(new lmbSQLFieldCriteria('uri', $uri->toString())); 107 $rs = $query->getRecordSet(); 108 $rs->rewind(); 109 if($rs->valid()) 110 return $rs->current(); 111 } 112 } 113 114 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat Nov 22 03:48:54 2008 | Cross-referenced by PHPXref 0.7 |