Răsfoiți Sursa

字典支持redis 术语字典

visuddhinanda 5 ani în urmă
părinte
comite
af4c8dcdee

+ 202 - 43
app/dict/dict_lookup.php

@@ -10,13 +10,22 @@ require_once "../search/word_function.php";
 require_once "../ucenter/active.php";
 require_once "../ucenter/function.php";
 require_once "../dict/p_ending.php";
+require_once "../redis/function.php";
+
+global $redis;
+$redis = redis_connect();
+
+global $count_return;
+$count_return = 0;
 
 _load_book_index();
 
 $word = mb_strtolower($_GET["word"], 'UTF-8');
 $org_word = $word;
 
-$count_return = 0;
+
+global $dict_list;
+
 $dict_list = array();
 
 $right_word_list = "";
@@ -24,49 +33,15 @@ $right_word_list = "";
         add_edit_event(_DICT_LOOKUP_, $word);
 
 		echo "<div id='dict_ref'>";
+		#先查原词
 		echo "<div class='pali_spell'><a name='{word_$word}'></a>" . $word . "</div>";
-        $dict_list_a = [];
-        //社区字典开始
-        PDO_Connect("" . _FILE_DB_WBW_);
-        $query = "SELECT *  from " . _TABLE_DICT_REF_ . " where pali = ? limit 0,100";
-        $Fetch = PDO_FetchAll($query, array($word));
-        $iFetch = count($Fetch);
-        $count_return += $iFetch;
-        if ($iFetch > 0) {
-            $userlist = array();
-            foreach ($Fetch as $value) {
-                if (isset($userlist[$value["creator"]])) {
-                    $userlist[$value["creator"]] += 1;
-                } else {
-                    $userlist[$value["creator"]] = 1;
-                }
-                $userwordcase = $value["type"] . "#" . $value["gramma"];
-                if (isset($userdict["{$userwordcase}"])) {
-                    $userdict["{$userwordcase}"]["mean"] .= $value["mean"] . ";";
-                    $userdict["{$userwordcase}"]["factors"] .= $value["factors"];
-                } else {
-                    $userdict["{$userwordcase}"]["mean"] = $value["mean"];
-                    $userdict["{$userwordcase}"]["factors"] = $value["factors"];
-                }
-
-            }
-            echo "<div class='dict_word'>";
-            echo "<div class='dict'>{$_local->gui->com_dict}</div><a name='net'></a>";
-            $dict_list_a[] = array("net", $_local->gui->com_dict);
+		$dict_list_a = [];
+		
+		//社区字典开始
+		echo lookup_user($word);
+		//社区字典结束
+		echo lookup_term($word);
 
-            foreach ($userdict as $key => $value) {
-                echo "<div class='mean'>{$key}:{$value["mean"]}</div>";
-            }
-			echo "<div><span>{$_local->gui->contributor}:</span>";
-			$userinfo = new UserInfo();
-            foreach ($userlist as $key => $value) {
-				$user = $userinfo->getName($key);
-                echo $user["nickname"] . "[" . $value . "]";
-            }
-            echo "</div>";
-            echo "</div>";
-        }
-        //社区字典结束
 
         PDO_Connect("" . _FILE_DB_REF_);
         //直接查询
@@ -118,6 +93,17 @@ $right_word_list = "";
 		$base_list = array();
         if (count($newWord) > 0) {
             foreach ($newWord as $x => $x_value) {
+				$titleHas = false;
+				$userDictStr = lookup_user($x);
+				$termDictStr = lookup_term($x);
+
+				if(!empty($userDictStr) || !empty($termDictStr)){
+					echo "<div class='pali_spell'><a name='word_$x'></a>" . $x . "</div>";
+					$titleHas = true;
+				}
+				echo $userDictStr;
+				echo $termDictStr;
+				
                 $query = "SELECT dict.dict_id,dict.mean,info.shortname from " . _TABLE_DICT_REF_ . " LEFT JOIN info ON dict.dict_id = info.id where word = ? limit 0,30";
                 $Fetch = PDO_FetchAll($query, array($x));
                 $iFetch = count($Fetch);
@@ -125,7 +111,10 @@ $right_word_list = "";
                 if ($iFetch > 0) {
 					$base_list[] = $x;
                     $dict_list_a[] = array("word_$x", $x);
-                    echo "<div class='pali_spell'><a name='word_$x'></a>" . $x . "</div>";
+					if(!$titleHas){
+						echo "<div class='pali_spell'><a name='word_$x'></a>" . $x . "</div>";
+					}
+					
                     //语法信息
                     foreach ($_local->grammastr as $gr) {
                         $x_value = str_replace($gr->id, $gr->value, $x_value);
@@ -179,6 +168,7 @@ $right_word_list = "";
 			$base_list = array();
 			if (count($arrBase) > 0) {
 				foreach ($arrBase as $x => $x_value) {
+					
 					$query = "SELECT dict.dict_id,dict.mean,info.shortname from " . _TABLE_DICT_REF_ . " LEFT JOIN info ON dict.dict_id = info.id where word = ? limit 0,30";
 					$Fetch = PDO_FetchAll($query, array($x));
 					$iFetch = count($Fetch);
@@ -359,3 +349,172 @@ $right_word_list = "";
 
 
 
+function lookup_user($word){
+	global $dict_list;
+	global $redis;
+	global $_local;
+	global $PDO;
+	global $count_return;
+
+	$output ="";
+	$Fetch=array();
+	if($redis){
+		$wordData = $redis->hGet("dict://user",$word);
+			if($wordData){
+				if(!empty($wordData)){
+					$arrWord = json_decode($wordData,true);
+					foreach ($arrWord as  $one) {
+						# code...
+						$Fetch[] = array("id"=>$one[0],
+										"pali"=>$one[1],
+										"type"=>$one[2],
+										"gramma"=>$one[3],
+										"parent"=>$one[4],
+										"mean"=>$one[5],
+										"note"=>$one[6],
+										"factors"=>$one[7],
+										"factormean"=>$one[8],
+										"status"=>$one[9],
+										"confidence"=>$one[10],
+										"creator"=>$one[11],
+										"dict_name"=>$one[12],
+										"lang"=>$one[13],
+										);
+					}						
+				}
+			}
+			else{
+				#  没找到就不找了
+			}
+	}
+	else{
+		PDO_Connect("" . _FILE_DB_WBW_);
+		$query = "SELECT *  from " . _TABLE_DICT_REF_ . " where pali = ? limit 0,100";
+		$Fetch = PDO_FetchAll($query, array($word));
+	}
+	
+	$iFetch = count($Fetch);
+	$count_return += $iFetch;
+	if ($iFetch > 0) {
+		$userlist = array();
+		foreach ($Fetch as $value) {
+			if (isset($userlist[$value["creator"]])) {
+				$userlist[$value["creator"]] += 1;
+			} else {
+				$userlist[$value["creator"]] = 1;
+			}
+			$userwordcase = $value["type"] . "#" . $value["gramma"];
+			if (isset($userdict["{$userwordcase}"])) {
+				$userdict["{$userwordcase}"]["mean"] .= $value["mean"] . ";";
+				$userdict["{$userwordcase}"]["factors"] .= $value["factors"];
+			} else {
+				$userdict["{$userwordcase}"]["mean"] = $value["mean"];
+				$userdict["{$userwordcase}"]["factors"] = $value["factors"];
+			}
+
+		}
+		$output .= "<div class='dict_word'>";
+		$output .= "<div class='dict'>{$_local->gui->com_dict}</div><a name='net'></a>";
+		$dict_list_a[] = array("net", $_local->gui->com_dict);
+
+		foreach ($userdict as $key => $value) {
+			$output .= "<div class='mean'>{$key}:{$value["mean"]}</div>";
+		}
+		$output .= "<div><span>{$_local->gui->contributor}:</span>";
+		$userinfo = new UserInfo();
+		foreach ($userlist as $key => $value) {
+			$user = $userinfo->getName($key);
+			$output .= $user["nickname"] . " ";
+		}
+		$output .= "</div>";
+		$output .= "</div>";
+	}
+	
+	return $output;
+
+}
+
+function lookup_term($word){
+	global $dict_list;
+	global $redis;
+	global $_local;
+	global $PDO;
+	global $count_return;
+
+	$output ="";
+	$Fetch=array();
+	if($redis){
+		$wordData = $redis->hGet("dict://term",$word);
+			if($wordData){
+				if(!empty($wordData)){
+					$arrWord = json_decode($wordData,true);
+					foreach ($arrWord as  $one) {
+						# code...
+						$Fetch[] = array("id"=>$one[0],
+										"pali"=>$one[1],
+										"type"=>$one[2],
+										"gramma"=>$one[3],
+										"parent"=>$one[4],
+										"mean"=>$one[5],
+										"note"=>$one[6],
+										"factors"=>$one[7],
+										"factormean"=>$one[8],
+										"status"=>$one[9],
+										"confidence"=>$one[10],
+										"creator"=>$one[11],
+										"dict_name"=>$one[12],
+										"lang"=>$one[13],
+										);
+					}						
+				}
+			}
+			else{
+				#  没找到就不找了
+			}
+	}
+	else{
+		PDO_Connect("" . _FILE_DB_WBW_);
+		$query = "SELECT *  from " . _TABLE_DICT_REF_ . " where pali = ? limit 0,100";
+		$Fetch = PDO_FetchAll($query, array($word));
+	}
+	
+	$iFetch = count($Fetch);
+	$count_return += $iFetch;
+	if ($iFetch > 0) {
+		$userlist = array();
+		foreach ($Fetch as $value) {
+			if (isset($userlist[$value["creator"]])) {
+				$userlist[$value["creator"]] += 1;
+			} else {
+				$userlist[$value["creator"]] = 1;
+			}
+			$userwordcase = $value["type"] . "#" . $value["gramma"];
+			if (isset($userdict["{$userwordcase}"])) {
+				$userdict["{$userwordcase}"]["mean"] .= $value["mean"] . ";";
+				$userdict["{$userwordcase}"]["factors"] .= $value["factors"];
+			} else {
+				$userdict["{$userwordcase}"]["mean"] = $value["mean"];
+				$userdict["{$userwordcase}"]["factors"] = $value["factors"];
+			}
+
+		}
+		$output .= "<div class='dict_word'>";
+		$output .= "<div class='dict'>{$_local->gui->wiki_term}</div><a name='net'></a>";
+		$dict_list_a[] = array("net", $_local->gui->wiki_term);
+
+		foreach ($userdict as $key => $value) {
+			$output .= "<div class='mean'>{$key}:{$value["mean"]}</div>";
+		}
+		$output .= "<div><span>{$_local->gui->contributor}:</span>";
+		$userinfo = new UserInfo();
+		foreach ($userlist as $key => $value) {
+			$user = $userinfo->getName($key);
+			$output .= $user["nickname"] . " ";
+		}
+		$output .= "</div>";
+		$output .= "</div>";
+	}
+	
+	return $output;
+
+}

+ 1 - 1
app/dict/redis_import_dict.php

@@ -45,7 +45,7 @@ function runTask($redis,$task,$dir){
 		if (($fp = fopen($csvfile, "r")) !== false) {
 			echo "单词表load {$csvfile}\n";
 			while (($data = fgets($fp)) !== false) {
-				$data1 = explode(",",$data);
+				$data1 = explode(",",trim($data));
 				if(count($data1)>1){
 					if($data1[2]==".comp." && $data1[1]===$data1[7]){
 						continue;

+ 1 - 1
app/dict/redis_import_term.php

@@ -31,7 +31,7 @@ if (PHP_SAPI == "cli") {
 									"",
 									1,
 									100,
-									1,
+									$one["owner"],
 									"term",
 									$one["language"]
 									);

+ 1 - 1
app/dict/redis_import_user.php

@@ -31,7 +31,7 @@ if (PHP_SAPI == "cli") {
 									$one["factormean"],
 									$one["status"],
 									$one["confidence"],
-									1,
+									$one["creator"],
 									$one["dict_name"],
 									$one["language"]
 									);

+ 15 - 52
app/studio/dict_find_one.php

@@ -66,10 +66,11 @@ $word_list = str_getcsv($in_word);
 $dict_word_spell = array();
 $output = array();
 $db_file_list = array();
-//用户词典
+//词典列表
 if ($dict_name == "") {
-    $db_file_list[] = array(_FILE_DB_WBW1_,"dict://user",false);
-
+    $db_file_list[] = array(_FILE_DB_TERM_,"dict://term",true);	
+	$db_file_list[] = array(_FILE_DB_WBW1_,"dict://user",true);
+	
     $db_file_list[] = array( _DIR_DICT_SYSTEM_ . "/sys_regular.db","dict://regular",true);
     $db_file_list[] = array( _DIR_DICT_SYSTEM_ . "/sys_irregular.db","dict://irregular",true);
     $db_file_list[] = array( _DIR_DICT_SYSTEM_ . "/union.db","dict://union",true);
@@ -90,8 +91,14 @@ if ($dict_name == "") {
 $_dict_db = array();
 foreach ($db_file_list as $db_file) {
     try {
-        $dbh = new PDO("sqlite:" . $db_file[0], "", "");
-        $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
+		if ($redis && !empty($db_file[1])) {
+			$dbh=null;
+		}
+		else{
+			$dbh = new PDO("sqlite:" . $db_file[0], "", "");
+        	$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
+		}
+        
         $_dict_db[] = array("file" => $db_file[0], "dbh" => $dbh,"redis"=>$db_file[1],"static"=>$db_file[2]);
 
     } catch (PDOException $e) {
@@ -172,51 +179,7 @@ for ($i = 0; $i < $lookup_loop; $i++) {
 					}
 				}
 				else{
-					/*
-					if($db_file["static"]==false){
-						try {
-							if ($debug) {
-								echo "<spen style='color:red;'>db query</spen>:{$word} in {$db_file["file"]}<br>";
-							}
-							$query = "SELECT * from dict where pali = ? ORDER BY id DESC";
-							$stmt = $db_file["dbh"]->prepare($query);
-							$stmt->execute(array($word));
-							if ($stmt) {
-								$Fetch = $stmt->fetchAll(PDO::FETCH_ASSOC);
-								$redisWord=array();
-								foreach ($Fetch as  $one) {
-									# code...
-									$redisWord[] = array($one["id"],
-													 $one["pali"],
-													$one["type"],
-													$one["gramma"],
-													$one["parent"],
-													$one["mean"],
-													$one["note"],
-													$one["factors"],
-													$one["factormean"],
-													$one["status"],
-													$one["confidence"],
-													1,
-													$one["dict_name"],
-													$one["language"]
-													);
-								}
-								$redis->hSet($db_file["redis"],$word,json_encode($redisWord,JSON_UNESCAPED_UNICODE));
-							} else {
-								$Fetch = array();
-								if ($debug) {
-									echo "无效的Statement句柄";
-								}
-							}
-						} catch (PDOException $e) {
-							if ($debug) {
-								print "Error!: " . $e->getMessage() . "<br/>";
-							}
-							$Fetch = array();
-						}
-					}
-					*/
+					#  没找到就不找了
 				}
 			}
 		}
@@ -265,9 +228,9 @@ for ($i = 0; $i < $lookup_loop; $i++) {
                     $guid = "";
                 }
                 if (isset($one["lang"])) {
-                    $language = substr($one["lang"],0,2);
+                    $language = $one["lang"];
                 } else if (isset($one["language"])) {
-                    $language = substr($one["language"],0,2);
+                    $language = $one["language"];
                 } else {
                     $language = "en";
                 }

+ 2 - 2
app/studio/dict_updata_wbw.php

@@ -173,7 +173,7 @@ if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
 									$one["factormean"],
 									$one["status"],
 									$one["confidence"],
-									1,
+									$one["creator"],
 									$one["dict_name"],
 									$one["language"]
 									);
@@ -181,7 +181,7 @@ if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
 				$redis->hSet("dict://user",$key,json_encode($redisWord,JSON_UNESCAPED_UNICODE));
 			}				
 		}
-	
 	}
+	#更新redis结束
 
 }

+ 0 - 304
app/studio/term-.php

@@ -1,304 +0,0 @@
-<?php
-//查询term字典
-require_once "../path.php";
-require_once "../public/_pdo.php";
-require_once "./public.inc";
-require_once "../public/load_lang.php";
-
-$username = "";
-if (isset($_COOKIE["username"]) && !empty($_COOKIE["username"])) {
-    $username = $_COOKIE["username"];
-}
-
-$op = $_GET["op"];
-if (isset($_GET["word"])) {
-    if (empty($_GET["word"])) {
-        return;
-    }
-    $word = mb_strtolower($_GET["word"], 'UTF-8');
-    $org_word = $word;
-}
-
-if (isset($_GET["list"])) {
-    $list = $_GET["list"];
-}
-
-$count_return = 0;
-$dict_list = array();
-
-global $PDO;
-PDO_Connect("" . _FILE_DB_TERM_);
-switch ($op) {
-    case "pre": //预查询
-
-        echo "<wordlist>";
-        $query = "select word,count from dict where \"eword\" like " . $PDO->quote($word . '%') . " OR \"word\" like " . $PDO->quote($word . '%') . "  limit 0,100";
-        $Fetch = PDO_FetchAll($query);
-        $iFetch = count($Fetch);
-        if ($iFetch > 0) {
-            for ($i = 0; $i < $iFetch; $i++) {
-                $outXml = "<word>";
-                $word = $Fetch[$i]["word"];
-                $outXml = $outXml . "<pali>$word</pali>";
-                $outXml = $outXml . "<count>" . $Fetch[$i]["count"] . "</count>";
-                $outXml = $outXml . "</word>";
-                echo $outXml;
-            }
-        }
-        echo "</wordlist>";
-        break;
-    case "my":
-        $query = "select guid,word,meaning,other_meaning from term  where owner= " . $PDO->quote($username);
-        $Fetch = PDO_FetchAll($query);
-        $iFetch = count($Fetch);
-        if ($iFetch > 0) {
-            echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
-        }
-        break;
-    case "allpali":
-        $query = "select word from term  where 1 group by word";
-        $Fetch = PDO_FetchAll($query);
-        $iFetch = count($Fetch);
-        if ($iFetch > 0) {
-            echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
-        }
-        break;
-
-    case "allmean":
-        $query = "select meaning from term  where \"word\" = " . $PDO->quote($word) . " group by meaning";
-        $Fetch = PDO_FetchAll($query);
-        foreach ($Fetch as $one) {
-            echo "<a>" . $one["meaning"] . "</a> ";
-        }
-        //echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
-        break;
-    case "load_id":
-        if (isset($_GET["id"])) {
-            $id = $_GET["id"];
-            $query = "select * from term  where \"guid\" = " . $PDO->quote($id);
-            $Fetch = PDO_FetchAll($query);
-            echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
-        } else {
-            echo "{}";
-        }
-        break;
-    case "search":
-        //查本人数据
-        echo "<div>" . $module_gui_str['editor']['1122'] . "</div>"; //My Term
-        $query = "select * from term  where \"word\" = " . $PDO->quote($word) . " AND \"owner\"= " . $PDO->quote($username) . " limit 0,30";
-
-        $Fetch = PDO_FetchAll($query);
-        $iFetch = count($Fetch);
-        $count_return += $iFetch;
-        if ($iFetch > 0) {
-            for ($i = 0; $i < $iFetch; $i++) {
-                $mean = $Fetch[$i]["meaning"];
-                $guid = $Fetch[$i]["guid"];
-                $dict_list[$guid] = $Fetch[$i]["owner"];
-                echo "<div class='dict_word'>";
-                echo "<a name='ref_dict_$guid'></a>";
-                echo "<div class='dict'>$word</div>";
-                echo "<div id='term_dict_my_$guid'>";
-                echo "<div class='mean'>" . $mean . "</div>";
-                echo "<div class='other_mean'>" . $Fetch[$i]["other_meaning"] . "</div>";
-                echo "<div class='term_note' status=0>" . $Fetch[$i]["note"] . "</div>";
-                echo "</div>";
-                //编辑词条表单
-                echo "<div id='term_dict_my_edit_$guid' style='display:none'>";
-                echo "<input type='hidden' id='term_edit_word_$guid' value='$word' />";
-                echo "<div class='mean'><input type='input' id='term_edit_mean_$guid'  placeholder='" . $_local->gui->g_mean . "'value='$mean' /></div>"; //'意思'
-                echo "<div class='other_mean'><input type='input' id='term_edit_mean2_$guid'  placeholder=" . $_local->gui->other_meaning . " value='" . $Fetch[$i]["other_meaning"] . "' /></div>"; //'备选意思(可选项)'
-                echo "<div class='note'><textarea  id='term_edit_note_$guid'  placeholder='" . $_local->gui->note . "'>" . $Fetch[$i]["note"] . "</textarea></div>"; //'注解'
-                echo "</div>";
-                echo "<div id='term_edit_btn1_$guid'>";
-                echo "<button onclick=\"term_apply('$guid')\">" . $_local->gui->apply . "</button>"; //Apply
-                echo "<button onclick=\"term_edit('$guid')\">" . $_local->gui->edit . "</button>"; //Edit
-                echo "</div>";
-                echo "<div id='term_edit_btn2_$guid'  style='display:none'>";
-                echo "<button onclick=\"term_data_esc_edit('$guid')\">" . $_local->gui->cancel . "</button>"; //Cancel
-                echo "<button onclick=\"term_data_save('$guid')\">" . $_local->gui->cancel . "</button>"; //保存
-                echo "</div>";
-                echo "</div>";
-            }
-        }
-        //新建词条
-        echo "<div class='dict_word'>";
-        echo "<div class='dict'>" . $_local->gui->new_technic_term . "</div>"; //New Techinc Term
-        echo "<div class='mean'>";
-        echo "<span>" . $_local->gui->spell . ":</span>";
-        echo "<input type='input' placeholder=" . $_local->gui->spell . " id='term_new_word' value='{$word}' />";
-        echo "</div>"; //'拼写'
-        echo "<div class='mean'>";
-        echo "<span>" . $_local->gui->g_mean . ":</span>";
-        echo "<input type='input' placeholder='" . $_local->gui->g_mean . "' id='term_new_mean'/>";
-        echo "</div>"; //'意思'
-        echo "<div class='other_mean'>";
-        echo "<span>" . $_local->gui->other_meaning . ":</span>";
-        echo "<input type='input'  placeholder='" . $_local->gui->other_meaning . "' id='term_new_mean2'/>";
-        echo "</div>"; //'备选意思(可选项)'
-        echo "<div class='tag'>";
-        echo "<span>" . $_local->gui->tag . ":</span>";
-        echo "<input type='input'  placeholder='" . $_local->gui->tag . "' id='term_new_tag'/>";
-        echo "</div>"; //'标签'
-        echo "<div class='note'>";
-        echo "<span>" . $_local->gui->note . ":</span>";
-        echo "<textarea width='100%' height='3em'  placeholder='" . $_local->gui->note . "' id='term_new_note'></textarea>";
-        echo "</div>"; //'注解'
-        echo "<button onclick=\"term_data_save('')\">" . $_local->gui->save . "</button>"; //保存
-        echo "</div>";
-
-        //查他人数据
-        $query = "select * from term  where \"word\" = " . $PDO->quote($word) . "AND \"owner\" <> " . $PDO->quote($username) . " limit 0,30";
-
-        $Fetch = PDO_FetchAll($query);
-        $iFetch = count($Fetch);
-        $count_return += $iFetch;
-        if ($iFetch > 0) {
-            for ($i = 0; $i < $iFetch; $i++) {
-                $mean = $Fetch[$i]["meaning"];
-                $guid = $Fetch[$i]["guid"];
-                $dict_list[$guid] = $Fetch[$i]["owner"];
-                echo "<div class='dict_word'>";
-                echo "<a name='ref_dict_$guid'></a>";
-                echo "<div class='dict'>" . $Fetch[$i]["owner"] . "</div>";
-                echo "<div class='mean'>" . $mean . "</div>";
-                echo "<div class='other_mean'>" . $Fetch[$i]["other_meaning"] . "</div>";
-                echo "<div class='note'>" . $Fetch[$i]["note"] . "</div>";
-                echo "<button onclick=\"term_data_copy_to_me($guid)\">" . $module_gui_str['editor']['1123'] . "</button>"; //复制
-                echo "</div>";
-            }
-        }
-
-        //查内容
-        if ($count_return < 2) {
-            $word1 = $org_word;
-            $wordInMean = "%$org_word%";
-            echo $module_gui_str['editor']['1124'] . ":$org_word<br />";
-            $query = "select * from term  where \"meaning\" like " . $PDO->quote($word) . " limit 0,30";
-            $Fetch = PDO_FetchAll($query);
-            $iFetch = count($Fetch);
-            $count_return += $iFetch;
-            if ($iFetch > 0) {
-                for ($i = 0; $i < $iFetch; $i++) {
-                    $mean = $Fetch[$i]["meaning"];
-                    $pos = mb_stripos($mean, $word, 0, "UTF-8");
-                    if ($pos) {
-                        if ($pos > 20) {
-                            $start = $pos - 20;
-                        } else {
-                            $start = 0;
-                        }
-                        $newmean = mb_substr($mean, $start, 100, "UTF-8");
-                    } else {
-                        $newmean = $mean;
-                    }
-                    $pos = mb_stripos($newmean, $word1, 0, "UTF-8");
-                    $head = mb_substr($newmean, 0, $pos, "UTF-8");
-                    $mid = mb_substr($newmean, $pos, mb_strlen($word1, "UTF-8"), "UTF-8");
-                    $end = mb_substr($newmean, $pos + mb_strlen($word1, "UTF-8"), null, "UTF-8");
-                    $heigh_light_mean = "$head<hl>$mid</hl>$end";
-                    $outXml = "<div class='dict_word'>";
-                    $outXml = $outXml . "<div class='dict'>" . $Fetch[$i]["owner"] . "</div>";
-                    $outXml = $outXml . "<div class='pali'>" . $Fetch[$i]["word"] . "</div>";
-                    $outXml = $outXml . "<div class='mean'>" . $heigh_light_mean . "</div>";
-                    $outXml = $outXml . "<div class='note'>{$Fetch[$i]["note"]}</div>";
-                    $outXml = $outXml . "</div>";
-                    echo $outXml;
-                }
-            }
-        }
-        //查内容结束
-
-        echo "<div id='dictlist'>";
-        foreach ($dict_list as $x => $x_value) {
-            echo "<a href='#ref_dict_$x'>$x_value</a><br/>";
-        }
-        echo "</div>";
-
-        break;
-    case "save":
-        if ($_GET["guid"] != "") {
-            $mean = $_GET["mean"];
-            $query = "UPDATE term SET meaning='$mean' ,
-									other_meaning='" . $_GET["mean2"] . "' ,
-									note='" . $_GET["note"] . "'
-							where guid='" . $_GET["guid"] . "'";
-        } else {
-            $newGuid = GUIDv4();
-            $newGuid = str_replace("-", "", $newGuid);
-            $word = $_GET["word"];
-            $worden = pali2english($word);
-            $mean = $_GET["mean"];
-            $mean2 = $_GET["mean2"];
-            $note = $_GET["note"];
-            $tag = $_GET["tag"];
-            $time = time();
-            $query = "INSERT INTO term VALUES (NULL,
-											'$newGuid',
-											'$word',
-											'$worden',
-											'$mean',
-											'$mean2',
-											'$note',
-											'$tag',
-											'$time',
-											'$username',
-											'1',
-											'zh',
-											'0',
-											'0',
-											'0')";
-        }
-        $stmt = @PDO_Execute($query);
-        $respond = array("status" => 0, "message" => "");
-        if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-            $error = PDO_ErrorInfo();
-            $respond['status'] = 1;
-            $respond['message'] = $error[2];
-        } else {
-            $respond['status'] = 0;
-            $respond['message'] = $word;
-        }
-        echo json_encode($respond, JSON_UNESCAPED_UNICODE);
-        break;
-    case "copy": //拷贝到我的字典
-
-        $query = "select * from term  where \"guid\" = " . $PDO->quote($_GET["wordid"]);
-
-        $Fetch = PDO_FetchAll($query);
-        $iFetch = count($Fetch);
-        if ($iFetch > 0) {
-            /* 开始一个事务,关闭自动提交 */
-            $PDO->beginTransaction();
-            $query = "INSERT INTO term ('id','guid','word','word_en','meaning','other_meaning','note','tag','create_time','owner','hit') VALUES (null,?,?,?,?,?,?,?," . time() . ",'$username',1)";
-            $stmt = $PDO->prepare($query);
-            {
-                $stmt->execute(array(GUIDv4(false),
-                    $Fetch[0]["word"],
-                    $Fetch[0]["word_en"],
-                    $Fetch[0]["meaning"],
-                    $Fetch[0]["other_meaning"],
-                    $Fetch[0]["note"],
-                    $Fetch[0]["tag"],
-                ));
-            }
-            /* 提交更改 */
-            $PDO->commit();
-            if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-                $error = PDO_ErrorInfo();
-                echo "error - $error[2] <br>";
-            } else {
-                echo "updata ok.";
-            }
-        }
-        break;
-    case "extract":
-
-        $query = "select * from term  where \"guid\" in ($list)  limit 0,1000";
-        $Fetch = PDO_FetchAll($query);
-        $iFetch = count($Fetch);
-        if ($iFetch > 0) {
-            echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
-        }
-        break;
-}

+ 2 - 3
app/term/term.js

@@ -310,10 +310,9 @@ function term_data_save(guid) {
 		var strNote = $("#term_edit_note_" + guid).val();
 	}
 	$.post(
-		"../term/term.php",
+		"../term/term_post.php",
 		{
-			op: "save",
-			guid: guid,
+			id: guid,
 			word: strWord,
 			mean: strMean,
 			mean2: strMean2,

+ 0 - 54
app/term/term.php

@@ -254,60 +254,6 @@ switch ($op) {
             echo "<div id='dictlist'>";
             echo "</div>";
 
-            break;
-        }
-    case "save":
-        {
-            $currTime = sprintf("%d", microtime(true) * 1000);
-            if (isset($_POST["modify_time"])) {
-                $mTime = $_POST["modify_time"];
-            } else {
-                $mTime = mTime();
-            }
-            if ($_POST["guid"] != "") {
-                $query = "UPDATE term SET meaning= ? ,other_meaning = ? , tag= ? ,channal = ? ,  language = ? , note = ? , receive_time= ?, modify_time= ?   where guid= ? ";
-                $stmt = @PDO_Execute($query, array($_POST["mean"],
-                    $_POST["mean2"],
-                    $_POST["tag"],
-                    $_POST["channal"],
-                    $_POST["language"],
-                    $_POST["note"],
-                    mTime(),
-                    $mTime,
-                    $_POST["guid"],
-                ));
-            } else {
-                $parm = array();
-                $parm[] = UUID::v4();
-                $parm[] = $_POST["word"];
-                $parm[] = pali2english($_POST["word"]);
-                $parm[] = $_POST["mean"];
-                $parm[] = $_POST["mean2"];
-                $parm[] = $_POST["tag"];
-                $parm[] = $_POST["channal"];
-                $parm[] = $_POST["language"];
-                $parm[] = $_POST["note"];
-                $parm[] = $_COOKIE["userid"];
-                $parm[] = 0;
-                $parm[] = mTime();
-                $parm[] = mTime();
-                $parm[] = mTime();
-                $query = "INSERT INTO term (id, guid, word, word_en, meaning, other_meaning, tag, channal, language,note,owner,hit,create_time,modify_time,receive_time )
-															VALUES (NULL, ? , ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ";
-
-                $stmt = @PDO_Execute($query, $parm);
-            }
-
-            $respond = array("status" => 0, "message" => "");
-            if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-                $error = PDO_ErrorInfo();
-                $respond['status'] = 1;
-                $respond['message'] = $error[2] . $query;
-            } else {
-                $respond['status'] = 0;
-                $respond['message'] = $_POST["word"];
-            }
-            echo json_encode($respond, JSON_UNESCAPED_UNICODE);
             break;
         }
     case "copy": //拷贝到我的字典

+ 48 - 10
app/term/term_post.php

@@ -5,6 +5,9 @@
 require_once "../path.php";
 require_once "../public/_pdo.php";
 require_once '../public/function.php';
+require_once "../redis/function.php";
+
+$redis = redis_connect();
 
 #未登录不能修改
 if (isset($_COOKIE["userid"]) == false) {
@@ -20,16 +23,17 @@ PDO_Connect("" . _FILE_DB_TERM_);
 if ($_POST["id"] != "") {
     #更新
     $query = "UPDATE term SET meaning= ? ,other_meaning = ? , tag= ? ,channal = ? ,  language = ? , note = ? , receive_time= ?, modify_time= ?   where guid= ? and owner = ? ";
-    $stmt = @PDO_Execute($query, array($_POST["mean"],
-        $_POST["mean2"],
-        $_POST["tag"],
-        $_POST["channal"],
-        $_POST["language"],
-        $_POST["note"],
-        mTime(),
-        mTime(),
-        $_POST["id"],
-        $_COOKIE["userid"],
+	$stmt = @PDO_Execute($query, 
+						array($_POST["mean"],
+        					  $_POST["mean2"],
+        					  $_POST["tag"],
+        					  $_POST["channal"],
+        					  $_POST["language"],
+        					  $_POST["note"],
+        					  mTime(),
+        					  mTime(),
+        					  $_POST["id"],
+        					  $_COOKIE["userid"],
     ));
     if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
         $error = PDO_ErrorInfo();
@@ -68,4 +72,38 @@ if ($_POST["id"] != "") {
     }
 }
 
+	#更新 redis
+	if ($redis != false) {
+		{
+			# code...
+			$query = "SELECT id,word,meaning,other_meaning,note,owner,language from term where word = ? ";
+			$stmt = $PDO->prepare($query);
+			$stmt->execute(array($_POST["word"]));
+			if ($stmt) {
+				$Fetch = $stmt->fetchAll(PDO::FETCH_ASSOC);
+				$redisWord=array();
+				foreach ($Fetch as  $one) {
+					# code...
+					$redisWord[] = array($one["id"],
+										$one["word"],
+									"",
+									"",
+									"",
+									$one["meaning"]."$".$one["other_meaning"],
+									$one["note"],
+									"",
+									"",
+									1,
+									100,
+									$one["owner"],
+									"term",
+									$one["language"]
+									);
+				}
+				$redis->hSet("dict://term",$_POST["word"],json_encode($redisWord,JSON_UNESCAPED_UNICODE));
+			}				
+		}
+	}
+	#更新redis结束
+
 echo json_encode($respond, JSON_UNESCAPED_UNICODE);

+ 1 - 1
dicttext/rich/uhan_en.csv

@@ -1,4 +1,4 @@
-1,ā,.perfix.,,, up to$(prep$) from$towards$Until$as far as compounded with nouns:$Much used in combination with verbs and their derivatives$,,,,1,100,1,uhan_en,en
+1,ā,.perfix.,,, up to$(prep$) from$towards$Until$as far as compounded with nouns:$Much used in combination with verbs and their derivatives$,,,,1,100,1,uhan_en,en
 2,ababa,.n:base.,.nt.,, ṅame of a purgatory$a numeral with 76 ciphers$One of the high numerals representing 10,000,000(to the 11th power)$1 followed by seventy-seven ciphers,,,,1,100,5,uhan_en,en
 3,ababhāsa,.n:base.,.m.,, light$appearance$,,,,1,100,8,uhan_en,en
 4,abaddha,.adj:base.,,, unfettered$free$not bound$Not bound$unmeaning$senseless,,,,1,100,7,uhan_en,en