Selaa lähdekoodia

wordindex支持pg

visuddhinanda 4 vuotta sitten
vanhempi
sitoutus
12906c5a6c

+ 2 - 2
app/admin/word_index_weight_refresh.php

@@ -82,7 +82,7 @@ for ($i = $from; $i <= $to; $i++) {
                     $bold_count = $end - $begin + 1;
                     if ($bold_count == 1) {
 
-                        $query = "SELECT * from wordindex where id=" . $fetch[$iWord]["wordindex"];
+                        $query = "SELECT * from "._TABLE_WORD_INDEX_." where id=" . $fetch[$iWord]["wordindex"];
                         $stmt_word = $dh_word->query($query);
                         $wordinfo = $stmt_word->fetch(PDO::FETCH_ASSOC);
                         $bookId = (int) $fetch[$iWord]["book"];
@@ -100,7 +100,7 @@ for ($i = $from; $i <= $to; $i++) {
                         for ($iBold = $begin; $iBold <= $end; $iBold++) {
                             # code...
                             $boldid = $fetch[$iBold]["wordindex"];
-                            $query = "SELECT len from wordindex where id=" . $boldid;
+                            $query = "SELECT len from "._TABLE_WORD_INDEX_." where id=" . $boldid;
                             $stmt_bold = $dh_word->query($query);
                             $wordbold = $stmt_bold->fetch(PDO::FETCH_ASSOC);
                             $len_sum += $wordbold["len"];

+ 2 - 9
app/dict/comp_csv.php

@@ -23,15 +23,8 @@ $myfile = fopen(_DIR_TEMP_DICT_TEXT_ . "/comp.csv", "a");
 $filefail = fopen(_DIR_TEMP_DICT_TEXT_ . "/comp_fail.txt", "a");
 $iMax = 2;//输出前三个结果
 /*
-$dns = "" . _FILE_DB_WORD_INDEX_;
-$dbh_word = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true));
-$dbh_word->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
-
-$query = "SELECT * from wordindex where 1";
-$stmt = $dbh_word->query($query);
-
-while ($word = $stmt->fetch(PDO::FETCH_ASSOC))
- */
+不用全pali单词表 用redis里的wordindex 原因是需要排除语法书中的特别的词
+*/
 $redis = redis_connect();
 if ($redis == false) {
     echo "no redis connect\n";

+ 5 - 5
app/install/db_insert_index.php

@@ -74,11 +74,11 @@ $aNewWordIndex = array(); //词内容
 $sNewWord = array(); //词头索引
 
 global $dbh_word_index;
-$dns = "" . _FILE_DB_WORD_INDEX_;
+$dns = _FILE_DB_WORD_INDEX_;
 $dbh_word_index = new PDO($dns, _DB_USERNAME_, _DB_PASSWORD_, array(PDO::ATTR_PERSISTENT => true));
 $dbh_word_index->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
 
-$query = "select id from wordindex where 1 order by id DESC ";
+$query = "SELECT id from "._TABLE_WORD_INDEX_." where true order by id DESC ";
 $stmt = $dbh_word_index->prepare($query);
 $stmt->execute(array());
 $id = $stmt->fetch(PDO::FETCH_ASSOC);
@@ -89,7 +89,7 @@ if ($id === false) {
 }
 $db_file = _FILE_DB_PALI_INDEX_;
 PDO_Connect($db_file,_DB_USERNAME_,_DB_PASSWORD_);
-$query = "SELECT id from "._TABLE_WORD_." where 1 order by id DESC ";
+$query = "SELECT id from "._TABLE_WORD_." where true order by id DESC ";
 $stmt = $PDO->prepare($query);
 $stmt->execute(array());
 $id = $stmt->fetch(PDO::FETCH_ASSOC);
@@ -246,7 +246,7 @@ $iFile = $from;
 //首先插入新的词
 // 开始一个事务,关闭自动提交
 $dbh_word_index->beginTransaction();
-$query = "INSERT INTO wordindex ('id','word','word_en','count','normal','bold','is_base','len') VALUES ( ? , ? , ? , ? , ? , ? , ? , ? )";
+$query = "INSERT INTO "._TABLE_WORD_INDEX_." ('id','word','word_en','count','normal','bold','is_base','len') VALUES ( ? , ? , ? , ? , ? , ? , ? , ? )";
 $stmt = $dbh_word_index->prepare($query);
 
 echo "INSERT:" . count($aNewWordIndex) . "words<br>";
@@ -278,7 +278,7 @@ if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
 //然后修改已经有的词
 // 开始一个事务,关闭自动提交
 $dbh_word_index->beginTransaction();
-$query = "UPDATE wordindex SET count = ? , normal = ? , bold = ?   where  id = ?  ";
+$query = "UPDATE "._TABLE_WORD_INDEX_." SET count = ? , normal = ? , bold = ?   where  id = ?  ";
 $stmt = $dbh_word_index->prepare($query);
 
 echo "UPDATE:" . count($iAllWordIndex) . "words<br>";

+ 3 - 4
app/install/db_insert_index_once.php

@@ -72,8 +72,7 @@ if ($to == 0 || $to >= $fileNums) {
     $to = $fileNums - 1;
 }
 
-$db_file = _FILE_DB_INDEX_;
-PDO_Connect("$db_file");
+PDO_Connect(_FILE_DB_INDEX_);
 
 for ($iFile = $from; $iFile <= $to; $iFile++) {
     echo "<h3>{$iFile}</h3>";
@@ -110,7 +109,7 @@ for ($iFile = $from; $iFile <= $to; $iFile++) {
 
     // 开始一个事务,关闭自动提交
     $PDO->beginTransaction();
-    $query = "INSERT INTO word ('id','book','paragraph','wordindex','bold') VALUES (?,?,?,?,?)";
+    $query = "INSERT INTO "._TABLE_WORD_." ('id','book','paragraph','wordindex','bold') VALUES (?,?,?,?,?)";
     $stmt = $PDO->prepare($query);
     $count = 0;
     $count1 = 0;
@@ -182,7 +181,7 @@ for ($iFile = $from; $iFile <= $to; $iFile++) {
 
 // 开始一个事务,关闭自动提交
 $PDO->beginTransaction();
-$query = "INSERT INTO wordindex ('id','word','word_en','count','normal','bold','is_base','len') VALUES (?,?,?,?,?,?,?,?)";
+$query = "INSERT INTO "._TABLE_WORD_INDEX_." ('id','word','word_en','count','normal','bold','is_base','len') VALUES (?,?,?,?,?,?,?,?)";
 $stmt = $PDO->prepare($query);
 
 echo count($iAllWordIndex) . "words<br>";

+ 3 - 3
app/install/db_insert_wordindex_from_csv.php

@@ -24,15 +24,15 @@ $log = "";
 echo "<h2>doing : No.{$from}  </h2>";
 
 global $dbh_word_index;
-$dns = "" . _FILE_DB_WORD_INDEX_;
-$dbh_word_index = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true));
+$dns = _FILE_DB_WORD_INDEX_;
+$dbh_word_index = new PDO($dns, _DB_USERNAME_, _DB_PASSWORD_, array(PDO::ATTR_PERSISTENT => true));
 $dbh_word_index->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
 
 if (($fpoutput = fopen(_DIR_CSV_PALI_CANON_WORD_INDEX_ . "/{$from}.csv", "r")) !== false) {
 
     // 开始一个事务,关闭自动提交
     $dbh_word_index->beginTransaction();
-    $query = "INSERT INTO wordindex ('id','word','word_en','count','normal','bold','is_base','len') VALUES (?,?,?,?,?,?,?,?)";
+    $query = "INSERT INTO "._TABLE_WORD_INDEX_." (id , word , word_en , count , normal , bold , is_base , len ) VALUES (?,?,?,?,?,?,?,?)";
 
     $stmt = $dbh_word_index->prepare($query);
 

+ 13 - 12
app/path.php

@@ -90,19 +90,24 @@ define("_FILE_DB_BOOK_WORD_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_."
 //define("_FILE_DB_BOOK_WORD_", "sqlite:" . __DIR__ . "/../tmp/appdata/palicanon/bookword.db3");
 define("_TABLE_BOOK_WORD_", "bookword");
 
-//单词索引=92万词+单词索引
-//define("_FILE_DB_INDEX_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
-define("_FILE_DB_INDEX_", "sqlite:" . __DIR__ . "/../tmp/appdata/palicanon/index.db3");
-
-//92万词
-//define("_FILE_DB_WORD_INDEX_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
-define("_FILE_DB_WORD_INDEX_", "sqlite:" . __DIR__ . "/../tmp/appdata/palicanon/wordindex.db3");
-
 //单词索引
 define("_FILE_DB_PALI_INDEX_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
 //define("_FILE_DB_PALI_INDEX_", "sqlite:" . __DIR__ . "/../tmp/appdata/palicanon/paliindex.db3");
 define("_TABLE_WORD_", "word");
 
+//92万词
+define("_FILE_DB_WORD_INDEX_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
+//define("_FILE_DB_WORD_INDEX_", "sqlite:" . __DIR__ . "/../tmp/appdata/palicanon/wordindex.db3");
+define("_TABLE_WORD_INDEX_", "wordindex");
+
+//单词索引=92万词+单词索引
+define("_FILE_DB_INDEX_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
+//define("_FILE_DB_INDEX_", "sqlite:" . __DIR__ . "/../tmp/appdata/palicanon/index.db3");
+
+//黑体字数据表
+//define("_FILE_DB_BOLD_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
+define("_FILE_DB_BOLD_", "sqlite:" . __DIR__ . "/../tmp/appdata/palicanon/bold.db3");
+
 
 //单词分析表
 //define("_FILE_DB_STATISTICS_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
@@ -126,10 +131,6 @@ define("_FILE_DB_PALI_TOC_", "sqlite:" . __DIR__ . "/../tmp/appdata/palicanon/pa
 define("_FILE_DB_PAGE_INDEX_", "sqlite:" . __DIR__ . "/../tmp/appdata/palicanon/pagemap.db3");
 
 
-//黑体字数据表
-//define("_FILE_DB_BOLD_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
-define("_FILE_DB_BOLD_", "sqlite:" . __DIR__ . "/../tmp/appdata/palicanon/bold.db3");
-
 # 字典数据表 全部存入redis
 #巴缅字典
 //define("_DICT_DB_PM_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");

+ 10 - 10
app/search/dict_find3.php

@@ -32,9 +32,9 @@ global $PDO;
 
 switch ($op) {
     case "pre": //预查询
-        PDO_Connect(_FILE_DB_WORD_INDEX_);
+        PDO_Connect(_FILE_DB_WORD_INDEX_,_DB_USERNAME_,_DB_PASSWORD_);
         echo "<div>";
-        $query = "select word,count from wordindex where \"word_en\" like " . $PDO->quote($word . '%') . " OR \"word\" like " . $PDO->quote($word . '%') . " limit 50";
+        $query = "SELECT word,count from "._TABLE_WORD_INDEX_." where \"word_en\" like " . $PDO->quote($word . '%') . " OR \"word\" like " . $PDO->quote($word . '%') . " limit 50";
         echo $query;
         $Fetch = PDO_FetchAll($query);
         $iFetch = count($Fetch);
@@ -103,8 +103,8 @@ switch ($op) {
         /*查找实际出现的拼写
 
          */
-        PDO_Connect(_FILE_DB_WORD_INDEX_);
-        $query = "select id,word,count from wordindex where \"word\" in  $strQueryWord";
+        PDO_Connect(_FILE_DB_WORD_INDEX_,_DB_USERNAME_,_DB_PASSWORD_);
+        $query = "SELECT id,word,count from "._TABLE_WORD_INDEX_." where \"word\" in  $strQueryWord";
         $arrRealWordList = PDO_FetchAll($query);
         $countWord = count($arrRealWordList);
         echo "$word<br />共{$countWord}单词符合<br />";
@@ -141,7 +141,7 @@ switch ($op) {
 
         //查找这些词出现在哪些书中
         PDO_Connect(_FILE_DB_BOOK_WORD_);
-        $query = "SELECT book,sum(count) as co FROM "._TABLE_BOOK_WORD_." WHERE wordindex IN $strQueryWordId  GROUP BY book LIMIT 217";
+        $query = "SELECT book,sum(count) as co FROM "._TABLE_BOOK_WORD_." WHERE "._TABLE_WORD_INDEX_." IN $strQueryWordId  GROUP BY book LIMIT 217";
         $Fetch = PDO_FetchAll($query);
         $iFetch = count($Fetch);
         if ($iFetch > 0) {
@@ -175,9 +175,9 @@ switch ($op) {
         echo "<div id=\"dict_bold_right\" style='flex:7;'>";
         //前20条记录
 
-        PDO_Connect(_FILE_DB_WORD_INDEX_);
+        PDO_Connect(_FILE_DB_WORD_INDEX_,_DB_USERNAME_,_DB_PASSWORD_);
 
-        $query = "SELECT book,paragraph, wordindex FROM word WHERE \"wordindex\" in $strQueryWordId LIMIT 20";
+        $query = "SELECT book,paragraph, wordindex FROM "._TABLE_WORD_." WHERE \"wordindex\" in $strQueryWordId LIMIT 20";
         $Fetch = PDO_FetchAll($query);
         $iFetch = count($Fetch);
         if ($iFetch > 0) {
@@ -238,7 +238,7 @@ switch ($op) {
                 }
 
                 //查找这些词出现在哪些书中
-                $query = "SELECT book,sum(count) as co from "._TABLE_BOOK_WORD_." where wordindex in $wordlist group by book order by co DESC";
+                $query = "SELECT book,sum(count) as co from "._TABLE_BOOK_WORD_." where "._TABLE_WORD_INDEX_." in $wordlist group by book order by co DESC";
                 $Fetch = PDO_FetchAll($query);
                 $iFetch = count($Fetch);
                 if ($iFetch > 0) {
@@ -305,9 +305,9 @@ switch ($op) {
                 }
                 //查找这些词出现在哪些书中结束
                 //前20条记录
-                PDO_Connect(_FILE_DB_WORD_INDEX_);
+                PDO_Connect(_FILE_DB_WORD_INDEX_,_DB_USERNAME_,_DB_PASSWORD_);
 
-                $query = "select * from word where \"wordindex\" in $wordlist and \"book\" in $booklist group by book,paragraph  limit 20";
+                $query = "SELECT * from "._TABLE_WORD_." where \"wordindex\" in $wordlist and \"book\" in $booklist group by book,paragraph  limit 20";
                 $Fetch = PDO_FetchAll($query);
                 $iFetch = count($Fetch);
                 if ($iFetch > 0) {

+ 2 - 2
app/search/paliword_sc_pre.php

@@ -11,7 +11,7 @@ $word = mb_strtolower($_GET["key"], 'UTF-8');
 $arrWordList = str_getcsv($word, " ");
 
 $searching = $arrWordList[count($arrWordList) - 1];
-PDO_Connect(_FILE_DB_WORD_INDEX_);
+PDO_Connect(_FILE_DB_WORD_INDEX_,_DB_USERNAME_,_DB_PASSWORD_);
 
 if (count($arrWordList) > 1) {
     //echo "<div>";
@@ -20,7 +20,7 @@ if (count($arrWordList) > 1) {
     }
 
 } else {
-    $query = "SELECT word,word_en,count,bold FROM wordindex WHERE word_en  like  ? OR word like ? limit 0,20";
+    $query = "SELECT word,word_en,count,bold FROM "._TABLE_WORD_INDEX_." WHERE word_en  like  ? OR word like ? limit 20";
     $Fetch = PDO_FetchAll($query, array("{$searching}%", "{$searching}%"));
     if (count($Fetch) < 10) {
         $Fetch1 = PDO_FetchAll($query, array("%{$searching}%", "%{$searching}%"));

+ 3 - 3
app/search/paliword_search.php

@@ -33,7 +33,7 @@ switch ($op) {
             $time_start = microtime_float();
 
             $searching = $arrWordList[count($arrWordList) - 1];
-            PDO_Connect(_FILE_DB_WORD_INDEX_);
+            PDO_Connect(_FILE_DB_WORD_INDEX_,_DB_USERNAME_,_DB_PASSWORD_);
 
             if (count($arrWordList) > 1) {
                 echo "<div>";
@@ -43,7 +43,7 @@ switch ($op) {
                 echo "</div>";
             }
 
-            $query = "select word,count from wordindex where \"word_en\" like " . $PDO->quote($searching . '%') . " OR \"word\" like " . $PDO->quote($searching . '%') . " limit 20";
+            $query = "SELECT word,count from "._TABLE_WORD_INDEX_." where \"word_en\" like " . $PDO->quote($searching . '%') . " OR \"word\" like " . $PDO->quote($searching . '%') . " limit 20";
             $Fetch = PDO_FetchAll($query);
             $queryTime = (microtime_float() - $time_start) * 1000;
 
@@ -69,7 +69,7 @@ switch ($op) {
                 }
                 $strQuery = substr($strQuery, 0, -3);
                 PDO_Connect(_FILE_DB_PALITEXT_);
-                $query = "SELECT book,paragraph, html FROM _TABLE_PALI_TEXT_ WHERE {$strQuery}  LIMIT 20";
+                $query = "SELECT book,paragraph, html FROM "._TABLE_PALI_TEXT_." WHERE {$strQuery}  LIMIT 20";
                 $Fetch = PDO_FetchAll($query);
                 echo "<div>$query</div>";
                 $iFetch = count($Fetch);

+ 4 - 4
app/search/search.php

@@ -118,7 +118,7 @@ switch ($op) {
             $time_start = microtime_float();
 
             $searching = $arrWordList[count($arrWordList) - 1];
-            PDO_Connect(_FILE_DB_WORD_INDEX_);
+            PDO_Connect(_FILE_DB_WORD_INDEX_,_DB_USERNAME_,_DB_PASSWORD_);
 
             if (count($arrWordList) > 1) {
                 echo "<div>";
@@ -128,7 +128,7 @@ switch ($op) {
                 echo "</div>";
             }
             echo "<div>";
-            $query = "select word,count from wordindex where \"word_en\" like " . $PDO->quote($searching . '%') . " OR \"word\" like " . $PDO->quote($searching . '%') . " limit 50";
+            $query = "SELECT word,count from "._TABLE_WORD_INDEX_." where \"word_en\" like " . $PDO->quote($searching . '%') . " OR \"word\" like " . $PDO->quote($searching . '%') . " limit 50";
             echo $query;
             $Fetch = PDO_FetchAll($query);
             $queryTime = (microtime_float() - $time_start) * 1000;
@@ -210,8 +210,8 @@ switch ($op) {
             //查找实际出现的拼写
 
             $time_start = microtime_float();
-            PDO_Connect(_FILE_DB_WORD_INDEX_);
-            $query = "select id,word,count from wordindex where \"word\" in  $strQueryWord";
+            PDO_Connect(_FILE_DB_WORD_INDEX_,_DB_USERNAME_,_DB_PASSWORD_);
+            $query = "SELECT id,word,count from "._TABLE_WORD_INDEX_." where \"word\" in  $strQueryWord";
             $arrRealWordList = PDO_FetchAll($query);
             $countWord = count($arrRealWordList);
             if ($countWord == 0) {

+ 3 - 5
app/search/word_function.php

@@ -255,10 +255,8 @@ function countWordInPali($word, $sort = false, $limit = 0)
 
     //查找实际出现的拼写
 
-    $dsn = "" . _FILE_DB_WORD_INDEX_;
-    $user = "";
-    $password = "";
-    $PDO = new PDO($dsn, $user, $password, array(PDO::ATTR_PERSISTENT => true));
+    $dsn = _FILE_DB_WORD_INDEX_;
+    $PDO = new PDO($dsn, _DB_USERNAME_, _DB_PASSWORD_, array(PDO::ATTR_PERSISTENT => true));
     $PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
     if ($limit == 0) {
         $sSqlLimit = "";
@@ -271,7 +269,7 @@ function countWordInPali($word, $sort = false, $limit = 0)
         $sSqlSort = "";
     }
 
-    $query = "select id,word,count,bold,len from wordindex where \"word\" in  $strQueryWord " . $sSqlSort . " " . $sSqlLimit;
+    $query = "SELECT id,word,count,bold,len from "._TABLE_WORD_INDEX_." where \"word\" in  $strQueryWord " . $sSqlSort . " " . $sSqlLimit;
 
     $stmt = $PDO->query($query);
     $arrRealWordList = $stmt->fetchAll(PDO::FETCH_ASSOC);