visuddhinanda 4 anni fa
parent
commit
0858a27730

+ 8 - 8
app/admin/word_index_weight_refresh.php

@@ -20,30 +20,30 @@ if (isset($_GET["from"])) {
     }
 }
 
-$dh_word = new PDO( _FILE_DB_WORD_INDEX_, "", "");
+$dh_word = new PDO( _FILE_DB_WORD_INDEX_, _DB_USERNAME_, _DB_PASSWORD_);
 $dh_word->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
 
-$dh_pali = new PDO( _FILE_DB_PALI_INDEX_, "", "");
+$dh_pali = new PDO( _FILE_DB_PALI_INDEX_, _DB_USERNAME_, _DB_PASSWORD_);
 $dh_pali->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
 
 echo "from=$from to = $to \n";
 for ($i = $from; $i <= $to; $i++) {
     $time_start = microtime(true);
     echo "正在处理 book= $i ";
-    $query = "SELECT max(paragraph) from word where book=?";
+    $query = "SELECT max(paragraph) from "._TABLE_WORD_." where book=?";
 	$stmt = $dh_pali->prepare($query);
     $stmt->execute(array($i));
     $row = $stmt->fetch(PDO::FETCH_NUM);
     if ($row) {
         $max_para = $row[0];
-        echo "段落数量:$max_para \n";
+        echo "段落数量:$max_para ";
         for ($j = 0; $j <= $max_para; $j++) {
             # code...
-            $query = "SELECT id,book,wordindex,bold from word where book={$i} and paragraph={$j} order by id ASC";
+            $query = "SELECT id,book,wordindex,bold from "._TABLE_WORD_." where book={$i} and paragraph={$j} order by id ASC";
             $stmt = $dh_pali->query($query);
             $fetch = $stmt->fetchAll(PDO::FETCH_ASSOC);
 
-            $query = "SELECT wordindex,count(*) as co from word where book={$i} and paragraph={$j} group by wordindex";
+            $query = "SELECT wordindex,count(*) as co from "._TABLE_WORD_." where book={$i} and paragraph={$j} group by wordindex";
             $stmt = $dh_pali->query($query);
             $fetch_voc = $stmt->fetchAll(PDO::FETCH_ASSOC);
             $vocabulary = array();
@@ -116,7 +116,7 @@ for ($i = $from; $i <= $to; $i++) {
             }
             # 将整段权重写入据库
             $dh_pali->beginTransaction();
-            $query = "UPDATE word set weight = ? where id=? ";
+            $query = "UPDATE "._TABLE_WORD_." set weight = ? where id=? ";
             $stmt_weight = $dh_pali->prepare($query);
             foreach ($fetch as $key => $value) {
                 $stmt_weight->execute(array($value["weight"], $value["id"]));
@@ -132,5 +132,5 @@ for ($i = $from; $i <= $to; $i++) {
     } else {
         echo "无法获取段落最大值";
     }
-    echo "处理时间 :" . (microtime(true) - $time_start);
+    echo "处理时间 :" . (microtime(true) - $time_start). "\n";
 }

+ 34 - 28
app/install/db_insert_index.php

@@ -1,5 +1,34 @@
 <?php
+/*
+用csv 单词列表文件更新 wordindex and word
+可以用 db_insert_word_from_csv.php取代
+*/
 require_once "install_head.php";
+
+function dict_lookup($word)
+{
+    global $dbh_word_index;
+    $query = "select * from wordindex where \"word\" = ? ";
+    $stmt = $dbh_word_index->prepare($query);
+    $stmt->execute(array($word));
+    return $stmt->fetch(PDO::FETCH_ASSOC);
+}
+
+function getWordEn($strIn)
+{
+    $out = $strIn;
+    $out = str_replace("ā", "a", $out);
+    $out = str_replace("ī", "i", $out);
+    $out = str_replace("ū", "u", $out);
+    $out = str_replace("ṅ", "n", $out);
+    $out = str_replace("ñ", "n", $out);
+    $out = str_replace("ṭ", "t", $out);
+    $out = str_replace("ḍ", "d", $out);
+    $out = str_replace("ṇ", "n", $out);
+    $out = str_replace("ḷ", "l", $out);
+    $out = str_replace("ṃ", "m", $out);
+    return ($out);
+}
 ?>
 <!DOCTYPE html>
 <html>
@@ -46,7 +75,7 @@ $sNewWord = array(); //词头索引
 
 global $dbh_word_index;
 $dns = "" . _FILE_DB_WORD_INDEX_;
-$dbh_word_index = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true));
+$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 ";
@@ -59,8 +88,8 @@ if ($id === false) {
     $wordindex_max_index = $id["id"];
 }
 $db_file = _FILE_DB_PALI_INDEX_;
-PDO_Connect("$db_file");
-$query = "select id from word where 1 order by id DESC ";
+PDO_Connect($db_file,_DB_USERNAME_,_DB_PASSWORD_);
+$query = "SELECT id from "._TABLE_WORD_." where 1 order by id DESC ";
 $stmt = $PDO->prepare($query);
 $stmt->execute(array());
 $id = $stmt->fetch(PDO::FETCH_ASSOC);
@@ -69,30 +98,8 @@ if ($id === false) {
 } else {
     $g_wordCounter = $id["id"];
 }
-function dict_lookup($word)
-{
-    global $dbh_word_index;
-    $query = "select * from wordindex where \"word\" = ? ";
-    $stmt = $dbh_word_index->prepare($query);
-    $stmt->execute(array($word));
-    return $stmt->fetch(PDO::FETCH_ASSOC);
-}
 
-function getWordEn($strIn)
-{
-    $out = $strIn;
-    $out = str_replace("ā", "a", $out);
-    $out = str_replace("ī", "i", $out);
-    $out = str_replace("ū", "u", $out);
-    $out = str_replace("ṅ", "n", $out);
-    $out = str_replace("ñ", "n", $out);
-    $out = str_replace("ṭ", "t", $out);
-    $out = str_replace("ḍ", "d", $out);
-    $out = str_replace("ṇ", "n", $out);
-    $out = str_replace("ḷ", "l", $out);
-    $out = str_replace("ṃ", "m", $out);
-    return ($out);
-}
+
 
 if (($handle = fopen("filelist.csv", 'r')) !== false) {
     while (($filelist[$fileNums] = fgetcsv($handle, 0, ',')) !== false) {
@@ -103,7 +110,6 @@ if ($to == 0 || $to >= $fileNums) {
     $to = $fileNums - 1;
 }
 
-//for($iFile=$from;$iFile<=$to;$iFile++)
 $iFile = $from;
 {
 
@@ -140,7 +146,7 @@ $iFile = $from;
 
     // 开始一个事务,关闭自动提交
     $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;

+ 11 - 5
app/install/db_insert_word_from_csv.php

@@ -22,8 +22,8 @@ To: <input type="text" name="to" value="216"><br>
 return;
 }
 
-$from = $_GET["from"];
-$to = $_GET["to"];
+$from = (int)$_GET["from"];
+$to = (int)$_GET["to"];
 
 $dirLog = _DIR_LOG_ . "/";
 $dirXmlBase = _DIR_PALI_CSV_ . "/";
@@ -34,8 +34,8 @@ $log = "";
 echo "<h2>doing : No.{$from} book </h2>";
 
 global $dbh_word_index;
-$dns = "" . _FILE_DB_PALI_INDEX_;
-$dbh_word_index = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true));
+$dns = _FILE_DB_PALI_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 (($handle = fopen("filelist.csv", 'r')) !== false) {
@@ -47,10 +47,16 @@ if ($to == 0 || $to >= $fileNums) {
     $to = $fileNums - 1;
 }
 
+#删除
+$query = "DELETE FROM "._TABLE_WORD_." WHERE book = ?";
+$stmt = $dbh_word_index->prepare($query);
+$stmt->execute(array($from+1));
+
+
 if (($fpoutput = fopen(_DIR_CSV_PALI_CANON_WORD_ . "/{$from}_words.csv", "r")) !== false) {
     // 开始一个事务,关闭自动提交
     $dbh_word_index->beginTransaction();
-    $query = "INSERT INTO word ('id','book','paragraph','wordindex','bold') VALUES (?,?,?,?,?)";
+    $query = "INSERT INTO "._TABLE_WORD_." ( sn , book , paragraph , wordindex , bold ) VALUES (?,?,?,?,?)";
     $stmt = $dbh_word_index->prepare($query);
 
     $count = 0;

+ 13 - 11
app/path.php

@@ -90,6 +90,19 @@ 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");
+
 
 //单词分析表
 //define("_FILE_DB_STATISTICS_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
@@ -107,17 +120,6 @@ define("_FILE_DB_PALI_SENTENCE_SIM_", "sqlite:" . __DIR__ . "/../tmp/appdata/pal
 //define("_FILE_DB_PALI_TOC_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
 define("_FILE_DB_PALI_TOC_", "sqlite:" . __DIR__ . "/../tmp/appdata/palicanon/pali_toc.db3");
 
-//单词索引=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("_FILE_DB_PAGE_INDEX_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");

+ 2 - 2
app/search/paliword_sc.php

@@ -206,11 +206,11 @@ $time_start = microtime_float();
 
 PDO_Connect(_FILE_DB_PALI_INDEX_);
 
-$query = "SELECT count(*) from (SELECT book FROM word WHERE \"wordindex\" in $strQueryWordId  $strQueryBookId group by book,paragraph) where 1 ";
+$query = "SELECT count(*) from (SELECT book FROM "._TABLE_WORD_." WHERE \"wordindex\" in $strQueryWordId  $strQueryBookId group by book,paragraph) as qr where true ";
 $result["record_count"] = PDO_FetchOne($query);
 $result["time"][] = array("event" => "查询记录数", "time" => microtime(true) - $_start);
 
-$query = "SELECT book,paragraph, wordindex, sum(weight) as wt FROM word WHERE \"wordindex\" in $strQueryWordId $strQueryBookId GROUP BY book,paragraph ORDER BY wt DESC LIMIT ? OFFSET ?";
+$query = "SELECT book,paragraph, wordindex, sum(weight) as wt FROM "._TABLE_WORD_." WHERE \"wordindex\" in $strQueryWordId $strQueryBookId GROUP BY wordindex,book,paragraph ORDER BY wt DESC LIMIT ? OFFSET ?";
 $Fetch = PDO_FetchAll($query,array($_pagesize , $_page * $_pagesize));
 $result["time"][] = array("event" => "查询结束", "time" => microtime(true) - $_start);
 $out_data = array();

+ 3 - 3
app/search/paliword_search.php

@@ -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 0,20";
+            $query = "select word,count from wordindex 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;
 
@@ -163,7 +163,7 @@ switch ($op) {
 
             PDO_Connect(_FILE_DB_PALI_INDEX_);
 			//TODO 在没有查到书的时候$strFirstBookList为 (  需要修改
-            $query = "SELECT book,paragraph, wordindex FROM word WHERE \"wordindex\" in $strQueryWordId and book in $strFirstBookList group by book,paragraph LIMIT 0,20";
+            $query = "SELECT book,paragraph, wordindex FROM "._TABLE_WORD_." WHERE \"wordindex\" in $strQueryWordId and book in $strFirstBookList group by book,paragraph LIMIT 20";
             $Fetch = PDO_FetchAll($query);
             //echo "<div>$query</div>";
             $queryTime = (microtime_float() - $time_start) * 1000;
@@ -267,7 +267,7 @@ switch ($op) {
                 $time_start = microtime_float();
                 PDO_Connect(_FILE_DB_PALI_INDEX_);
 
-                $query = "select * from word where \"wordindex\" in $wordlist and \"book\" in $booklist group by book,paragraph  limit 0,20";
+                $query = "SELECT * from "._TABLE_WORD_." where \"wordindex\" in $wordlist and \"book\" in $booklist group by book,paragraph  limit 20";
                 $Fetch = PDO_FetchAll($query);
                 $queryTime = (microtime_float() - $time_start) * 1000;
                 //echo "<div >搜索时间:$queryTime </div>";

+ 2 - 2
app/search/search.php

@@ -286,7 +286,7 @@ switch ($op) {
             //前20条记录
             $time_start = microtime_float();
             PDO_Connect(_FILE_DB_PALI_INDEX_);
-            $query = "SELECT book,paragraph, wordindex FROM word WHERE \"wordindex\" in $strQueryWordId and book in $strFirstBookList group by book,paragraph LIMIT 20";
+            $query = "SELECT book,paragraph, wordindex FROM "._TABLE_WORD_." WHERE \"wordindex\" in $strQueryWordId and book in $strFirstBookList group by book,paragraph LIMIT 20";
             $Fetch = PDO_FetchAll($query);
             //echo "<div>$query</div>";
             $queryTime = (microtime_float() - $time_start) * 1000;
@@ -385,7 +385,7 @@ switch ($op) {
                 $time_start = microtime_float();
                 PDO_Connect(_FILE_DB_PALI_INDEX_);
 
-                $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);
                 //echo "<div>$query</div>";
                 $queryTime = (microtime_float() - $time_start) * 1000;

+ 1 - 1
app/search/title_search.php

@@ -268,7 +268,7 @@ switch ($op) {
 
                 PDO_Connect(_FILE_DB_PALI_INDEX_);
 
-                $query = "select * from word where \"wordindex\" in $wordlist and \"book\" in $booklist group by book,paragraph  limit 0,20";
+                $query = "SELECT * from "._TABLE_WORD_." where \"wordindex\" in $wordlist and \"book\" in $booklist group by book,paragraph  limit 20";
                 $Fetch = PDO_FetchAll($query);
                 //echo "<div>$query</div>";
                 $queryTime = (microtime_float() - $time_start) * 1000;