Browse Source

bookword 表 支持pg

visuddhinanda 4 years ago
parent
commit
d2fa52619e

+ 28 - 18
app/install/db_insert_bookword_from_csv.php

@@ -8,8 +8,8 @@ require_once "install_head.php";
 <body>
 <h2>Insert to Index</h2>
 <?php
-include "./_pdo.php";
-include "../path.php";
+require_once "./_pdo.php";
+require_once "../path.php";
 if (isset($_GET["from"]) == false) {
     ?>
 <form action="db_insert_bookword_from_csv.php" method="get">
@@ -33,8 +33,8 @@ $log = "";
 echo "<h2>doing : No.{$from} book </h2>";
 
 global $dbh_word_index;
-$dns = "" . _FILE_DB_BOOK_WORD_;
-$dbh_word_index = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true));
+$dns = _FILE_DB_BOOK_WORD_;
+$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) {
@@ -61,26 +61,36 @@ if (($fpoutput = fopen(_DIR_CSV_PALI_CANON_WORD_ . "/{$from}_words.csv", "r")) !
         $count++;
     }
 }
-
-// 开始一个事务,关闭自动提交
-$dbh_word_index->beginTransaction();
-$query = "INSERT INTO "._TABLE_BOOK_WORD_." ('book','wordindex','count') VALUES ( ? , ? , ?  )";
+#删除原来的数据
+$query = "DELETE FROM "._TABLE_BOOK_WORD_." WHERE book = ?";
 $stmt = $dbh_word_index->prepare($query);
-
-foreach ($bookword as $key => $value) {
-    $stmt->execute(array($book, $key, $value));
-}
-// 提交更改
-$dbh_word_index->commit();
+$stmt->execute(array($book));
 if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-    $error = $dbh_word_index->errorInfo();
+	$error = $dbh_word_index->errorInfo();
     echo "error - $error[2] <br>";
     $log .= "$from, $FileName, error, $error[2] \r\n";
-} else {
-    echo "updata $count recorders.<br />";
-    $log .= "updata $count recorders.\r\n";
+}else{
+	// 开始一个事务,关闭自动提交
+	$dbh_word_index->beginTransaction();
+	$query = "INSERT INTO "._TABLE_BOOK_WORD_." (book , wordindex , count) VALUES ( ? , ? , ?  )";
+	$stmt = $dbh_word_index->prepare($query);
+
+	foreach ($bookword as $key => $value) {
+		$stmt->execute(array($book, $key, $value));
+	}
+	// 提交更改
+	$dbh_word_index->commit();
+	if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
+		$error = $dbh_word_index->errorInfo();
+		echo "error - $error[2] <br>";
+		$log .= "$from, $FileName, error, $error[2] \r\n";
+	} else {
+		echo "updata $count recorders.<br />";
+		$log .= "updata $count recorders.\r\n";
+	}	
 }
 
+
 $myLogFile = fopen($dirLog . "insert_index.log", "a");
 fwrite($myLogFile, $log);
 fclose($myLogFile);

+ 7 - 4
app/path.php

@@ -84,6 +84,13 @@ define("_FILE_DB_PALITEXT_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";
 define("_TABLE_PALI_TEXT_","pali_text");
 define("_TABLE_PALI_BOOK_NAME_","books");
 
+#单词表部分
+//以书为单位的单词汇总表
+define("_FILE_DB_BOOK_WORD_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
+//define("_FILE_DB_BOOK_WORD_", "sqlite:" . __DIR__ . "/../tmp/appdata/palicanon/bookword.db3");
+define("_TABLE_BOOK_WORD_", "bookword");
+
+
 //单词分析表
 //define("_FILE_DB_STATISTICS_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
 define("_FILE_DB_STATISTICS_", "sqlite:" . __DIR__ . "/../tmp/appdata/palicanon/word_statistics.db3");
@@ -116,10 +123,6 @@ define("_FILE_DB_PALI_INDEX_", "sqlite:" . __DIR__ . "/../tmp/appdata/palicanon/
 //define("_FILE_DB_PAGE_INDEX_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
 define("_FILE_DB_PAGE_INDEX_", "sqlite:" . __DIR__ . "/../tmp/appdata/palicanon/pagemap.db3");
 
-//以书为单位的单词汇总表
-//define("_FILE_DB_BOOK_WORD_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
-define("_FILE_DB_BOOK_WORD_", "sqlite:" . __DIR__ . "/../tmp/appdata/palicanon/bookword.db3");
-define("_TABLE_BOOK_WORD_", "bookword");
 
 //黑体字数据表
 //define("_FILE_DB_BOLD_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");

+ 7 - 7
app/search/dict_find3.php

@@ -34,7 +34,7 @@ switch ($op) {
     case "pre": //预查询
         PDO_Connect(_FILE_DB_WORD_INDEX_);
         echo "<div>";
-        $query = "select word,count from wordindex where \"word_en\" like " . $PDO->quote($word . '%') . " OR \"word\" like " . $PDO->quote($word . '%') . " limit 0,50";
+        $query = "select word,count from wordindex where \"word_en\" like " . $PDO->quote($word . '%') . " OR \"word\" like " . $PDO->quote($word . '%') . " limit 50";
         echo $query;
         $Fetch = PDO_FetchAll($query);
         $iFetch = count($Fetch);
@@ -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 0,217";
+        $query = "SELECT book,sum(count) as co FROM "._TABLE_BOOK_WORD_." WHERE wordindex IN $strQueryWordId  GROUP BY book LIMIT 217";
         $Fetch = PDO_FetchAll($query);
         $iFetch = count($Fetch);
         if ($iFetch > 0) {
@@ -177,7 +177,7 @@ switch ($op) {
 
         PDO_Connect(_FILE_DB_WORD_INDEX_);
 
-        $query = "SELECT book,paragraph, wordindex FROM word WHERE \"wordindex\" in $strQueryWordId LIMIT 0,20";
+        $query = "SELECT book,paragraph, wordindex FROM word WHERE \"wordindex\" in $strQueryWordId LIMIT 20";
         $Fetch = PDO_FetchAll($query);
         $iFetch = count($Fetch);
         if ($iFetch > 0) {
@@ -195,7 +195,7 @@ switch ($op) {
                 echo "<div class='mean'>$paliword</div>";
 
                 {
-                    $query = "select * from vri_text where \"book\" = '{$book}' and \"paragraph\" = '{$paragraph}' limit 0,1";
+                    $query = "select * from vri_text where \"book\" = '{$book}' and \"paragraph\" = '{$paragraph}' limit 1";
                     $FetchPaliText = PDO_FetchAll($query);
                     $countPaliText = count($FetchPaliText);
                     if ($countPaliText > 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 wordindex in $wordlist group by book order by co DESC";
                 $Fetch = PDO_FetchAll($query);
                 $iFetch = count($Fetch);
                 if ($iFetch > 0) {
@@ -307,7 +307,7 @@ switch ($op) {
                 //前20条记录
                 PDO_Connect(_FILE_DB_WORD_INDEX_);
 
-                $query = "select * from word where \"wordindex\" in $wordlist and \"book\" in $booklist group by book,paragraph  limit 0,20";
+                $query = "select * from 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) {
@@ -324,7 +324,7 @@ switch ($op) {
                         echo "<div class='dict'>《{$bookname}》 $c1 $c2 </div>";
                         echo "<div class='mean'>$paliword</div>";
 
-                        $query = "select * from vri_text where \"book\" = '{$book}' and \"paragraph\" = '{$paragraph}' limit 0,20";
+                        $query = "select * from vri_text where \"book\" = '{$book}' and \"paragraph\" = '{$paragraph}' limit 20";
                         $FetchPaliText = PDO_FetchAll($query);
                         $countPaliText = count($FetchPaliText);
                         if ($countPaliText > 0) {

+ 3 - 3
app/search/search.php

@@ -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 0,50";
+            $query = "select word,count from wordindex 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;
@@ -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 0,20";
+            $query = "SELECT book,paragraph, wordindex FROM 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 0,20";
+                $query = "select * from 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/word_function.php

@@ -263,7 +263,7 @@ function countWordInPali($word, $sort = false, $limit = 0)
     if ($limit == 0) {
         $sSqlLimit = "";
     } else {
-        $sSqlLimit = "limit 0 , " . $limit;
+        $sSqlLimit = "limit " . $limit;
     }
     if ($sort) {
         $sSqlSort = "order by count DESC";