1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| <?php require_once("config.php"); require_once("myindex.php"); class DBManager { var $dbh; var $st; public function DBManager($table) { $this->tablename = $table; $this->dbh = new PDO("mysql:host=".DB_HOST.";dbname=".DB\_NAME, DB\_USER, DB_PASSWORD); } public function insertFullTextIndex($uri, $title, $content) { $stmt = $this->dbh->prepare("INSERT INTO ".$this->tablename." (uri, title, content, ngram\_prim, ngram\_sub) VALUES (:uri, :title, :content, :ngram\_prim, :ngram\_sub)"); $stmt->bindParam(':uri', $uri); $stmt->bindParam(':title', $title); $stmt->bindParam(':content', $content); $stmt->bindParam(':ngram_prim', $ngramp); $stmt->bindParam(':ngram_sub', $ngrams); $wa = new WordsAnalyzer(); $wa->loadStr($title); $ngramp = $wa->get_fulltext(); $wa->loadStr($content); $ngrams = $wa->get_fulltext(); return $stmt->execute(); } public function insertFullTextIndexPrimary($uri, $title, $content) { $stmt = $this->dbh->prepare("INSERT INTO ".$this->tablename." (uri, title, content, ngram\_prim) VALUES (:uri, :title, :content, :ngram\_prim)"); $stmt->bindParam(':uri', $uri); $stmt->bindParam(':title', $title); $stmt->bindParam(':content', $content); $stmt->bindParam(':ngram_prim', $ngramp); $wa = new WordsAnalyzer(); $wa->loadStr($title); $ngramp = $wa->get_fulltext(); return $stmt->execute(); } public function find($word){
$fs = new FullTextSearcher(); $matchsql = $fs->search_sql($word); $score = ", MATCH(ngram\_prim, ngram\_sub) AGAINST (".$fs->getScore().") as score"; $matchsql = "MATCH(ngram\_prim, ngram\_sub) AGAINST (".$matchsql.")"; $stmt = $this->dbh->prepare("SELECT uri, title, content".$score." FROM ".$this->tablename." WHERE ".$matchsql." ORDER BY score DESC LIMIT 0,50"); $this->fs = $fs; return $stmt; } public function findTitle($title){ $stmt = $this->dbh->prepare("SELECT uri, title, content FROM ".$this->tablename." WHERE title LIKE '%".$title."%'"); return $stmt; } public function getMarkupWords() { return $this->fs->getMarkupWords(); } } ?>
|