Просмотр исходного кода

两个或以上关键词的搜索

visuddhinanda 5 лет назад
Родитель
Сommit
1e3497eacd
4 измененных файлов с 91 добавлено и 146 удалено
  1. 21 4
      app/search/paliword.js
  2. 30 140
      app/search/paliword_sc.php
  3. 40 0
      app/search/paliword_sc_pre.php
  4. 0 2
      app/search/search.css

+ 21 - 4
app/search/paliword.js

@@ -44,6 +44,11 @@ function paliword_search(keyword, words = new Array(), book = new Array()) {
 			}
 			html += "</div>";
 			if (result.book_list) {
+				let allcount = 0;
+				for (const iterator of result.book_list) {
+					allcount += parseInt(iterator.count);
+				}
+				html += render_book_list({ book: 0, title: "All", count: allcount });
 				for (const iterator of result.book_list) {
 					html += render_book_list(iterator);
 				}
@@ -54,8 +59,16 @@ function paliword_search(keyword, words = new Array(), book = new Array()) {
 	);
 }
 function highlightWords(line, word) {
-	var regex = new RegExp("(" + word + ")", "gi");
-	return line.replace(regex, "<highlight>$1</highlight>");
+	if (line && line.length > 0) {
+		let output = line;
+		for (const iterator of word) {
+			let regex = new RegExp("(" + iterator + ")", "gi");
+			output = output.replace(regex, "<highlight>$1</highlight>");
+		}
+		return output;
+	} else {
+		return "";
+	}
 }
 function render_word_result(worddata) {
 	let html = "";
@@ -190,7 +203,11 @@ function search_book_filter(objid, type) {
 
 //选择需要过滤的书
 function book_select(bookid) {
-	paliword_search(_key_word, _filter_word, [bookid]);
+	if (bookid == 0) {
+		paliword_search(_key_word, _filter_word);
+	} else {
+		paliword_search(_key_word, _filter_word, [bookid]);
+	}
 }
 function book_search_filter() {
 	let booklist = new Array();
@@ -217,7 +234,7 @@ function book_filter_cancel() {
 
 function search_pre_search(word) {
 	$.get(
-		"../search/paliword_sc.php",
+		"../search/paliword_sc_pre.php",
 		{
 			op: "pre",
 			key: word,

+ 30 - 140
app/search/paliword_sc.php

@@ -29,30 +29,7 @@ function microtime_float()
 $result = array();
 $result["error"]="";
 
-switch($op){
-	case "pre"://预查询
-	{
-		$time_start = microtime_float();
-		
-		$searching=$arrWordList[count($arrWordList)-1];
-		$dbfile = _FILE_DB_WORD_INDEX_;
-		PDO_Connect("sqlite:".$dbfile);
-		
-		if(count($arrWordList)>1){
-			//echo "<div>";
-			foreach($arrWordList as $oneword){
-				//echo $oneword."+";
-			}
-			//echo "</div>";
-		}
 
-		$query = "SELECT word,count,bold FROM wordindex WHERE word_en  like  ? OR word like ? limit 0,20";
-		$Fetch = PDO_FetchAll($query,array("{$searching}%","{$searching}%"));
-		echo json_encode($Fetch,JSON_UNESCAPED_UNICODE);
-		break;
-	}
-	case "search":
-	{
 		$_pagesize = 20;
 		if(isset($_GET["page"])){
 			$_page = (int)$_GET["page"];
@@ -67,8 +44,20 @@ switch($op){
 			# 首先精确匹配
 			$words = implode(" ",$arrWordList);
 			$query = "SELECT book,paragraph, text FROM pali_text WHERE text like ?  LIMIT ? , ?";
-			$Fetch = PDO_FetchAll($query,array("%{$words}%",$_page*$_pagesize,$_pagesize));
-			#然后查不精确的
+			$Fetch1 = PDO_FetchAll($query,array("%{$words}%",$_page*$_pagesize,$_pagesize));
+
+			foreach ($Fetch1 as $key => $value) {
+				# code...
+				$newRecode["title"]="title";
+				$newRecode["path"] = _get_para_path($value["book"],$value["paragraph"]);
+				$newRecode["book"] = $value["book"];
+				$newRecode["para"] = $value["paragraph"];
+				$newRecode["palitext"] = $value["text"];
+				$newRecode["keyword"] = $arrWordList;
+				$newRecode["wt"] = 0;				
+				$out_data[] = $newRecode;	
+			}
+			#然后查分散的
 			$strQuery="";
 			foreach($arrWordList as $oneword){
 				$strQuery.="\"text\" like \"% {$oneword} %\" AND";
@@ -76,19 +65,23 @@ switch($op){
 			$strQuery = substr($strQuery,0,-3);
 
 			$query = "SELECT book,paragraph, html FROM pali_text WHERE {$strQuery}  LIMIT 0,20";
-			$Fetch = PDO_FetchAll($query);
+			$Fetch2 = PDO_FetchAll($query);
 
-			$iFetch=count($Fetch);
-			foreach($Fetch as $row){
-				$html = $row["html"];
-				foreach($arrWordList as $oneword){
-					$html=str_replace($oneword,"<hl>{$oneword}</hl>",$html);
-				}
-				//echo "<div class='dict_word'>{$html}</div>";
+			foreach ($Fetch2 as $key => $value) {
+				# code...
+				$newRecode["title"]="title";
+				$newRecode["path"] = _get_para_path($value["book"],$value["paragraph"]);
+				$newRecode["book"] = $value["book"];
+				$newRecode["para"] = $value["paragraph"];
+				$newRecode["palitext"] = $value["text"];
+				$newRecode["keyword"] = $arrWordList;
+				$newRecode["wt"] = 0;
+				$out_data[] = $newRecode;	
 			}
-
+			$result["data"] = $out_data;
+			echo json_encode($result,JSON_UNESCAPED_UNICODE);
 			# 然后查特别不精确的
-			return;
+			exit;			
 		}
 		
 	//计算某词在三藏中出现的次数		
@@ -277,117 +270,14 @@ switch($op){
 					$newRecode["book"] = $book;
 					$newRecode["para"] = $paragraph;
 					$newRecode["palitext"] = $FetchPaliText[0]["html"];
-					$newRecode["keyword"] = $paliword;
-					$newRecode["wt"] = $Fetch[$i]["wt"];
-//					echo  "<div class='mean' style='font-size:120%'><a href='../reader/?view=para&book={$book}&para={$paragraph}' target='_blank'>$path</a></div>";
-					
+					$newRecode["keyword"] = array($paliword);
+					$newRecode["wt"] = $Fetch[$i]["wt"];				
 					$out_data[] = $newRecode;
 				}
 				
 			}
 		}
-		$queryTime=(microtime_float()-$time_start)*1000;
 		$result["data"] = $out_data;
 		echo json_encode($result,JSON_UNESCAPED_UNICODE);
-		break;
-	}
-	case "update":
-		$target=$_GET["target"];
-		switch($target){
-			case "bold";
-				$wordlist=$_GET["wordlist"];
-				$booklist=$_GET["booklist"];
-				$aBookList=ltrim($booklist,"(");
-				$aBookList=rtrim($aBookList,")");
-				$aBookList=str_replace("'","",$aBookList);
-				$aBookList=str_getcsv($aBookList);
-				$arrBookType=json_decode(file_get_contents("../public/book_name/booktype.json"));
-				//查找这些词出现在哪些书中
-				$newBookList=render_book_list($wordlist,$aBookList);
-				
-				//前20条记录
-				$time_start=microtime_float();
-				$dictFileName=_FILE_DB_PALI_INDEX_;
-				PDO_Connect("sqlite:$dictFileName");
-
-				$query = "select * from word where \"wordindex\" in $wordlist and \"book\" in $booklist group by book,paragraph  limit 0,20";
-				$Fetch = PDO_FetchAll($query);
-				$queryTime=(microtime_float()-$time_start)*1000;
-				//echo "<div >搜索时间:$queryTime </div>";
-				if($booklist=="()"){
-					echo "<div >请选择书名</div>";
-				}
-				$iFetch=count($Fetch);
-				if($iFetch>0){
-					$dictFileName=_FILE_DB_PALITEXT_;
-					PDO_Connect("sqlite:$dictFileName");
-					for($i=0;$i<$iFetch;$i++){
-						$paliword=$Fetch[$i]["wordindex"];
-						//$paliword=$wordlist["{$paliwordid}"];
-						
-						$book=$Fetch[$i]["book"];
-						$bookInfo = _get_book_info($book);
-						$bookname=$bookInfo->title;
-						$c1=$bookInfo->c1;
-						$c2=$bookInfo->c2;
-						$c3=$bookInfo->c3;
-						$paragraph=$Fetch[$i]["paragraph"];
-
-						$path_1 = $c1.">";
-						if($c2 !== ""){
-							$path_1=$path_1.$c2.">";
-						}
-						if($c3 !== ""){
-							$path_1=$path_1.$c3.">";
-						}
-						$path_1=$path_1."《{$bookname}》>";
-
-						echo "<div class='dict_word'>";
-						echo  "<div class='book' ><span style='font-size:110%;font-weight:700;'>《{$bookname}》</span> <tag>$c1</tag> <tag>$c2</tag> </div>";
-						echo  "<div class='mean'>$paliword</div>";
-
-						$query = "select * from pali_text where \"book\" = '{$book}' and \"paragraph\" = '{$paragraph}' limit 0,20";
-						$FetchPaliText = PDO_FetchAll($query);
-						$countPaliText=count($FetchPaliText);
-						if($countPaliText>0){
-							for($iPali=0;$iPali<$countPaliText;$iPali++){
-								$path="";
-								$parent = $FetchPaliText[0]["parent"];
-								$deep=0;
-								$sFirstParentTitle="";
-								while($parent>-1){
-									$query = "select * from pali_text where \"book\" = '{$book}' and \"paragraph\" = '{$parent}' limit 0,1";
-									$FetParent = PDO_FetchAll($query);
-									if($sFirstParentTitle==""){
-										$sFirstParentTitle = $FetParent[0]["toc"];
-									}	
-									$path="{$FetParent[0]["toc"]}>{$path}";
-									$parent = $FetParent[0]["parent"];
-									$deep++;
-									if($deep>5){
-										break;
-									}
-								}
-								$path=$path."No. ".$paragraph;
-								echo  "<div class='mean' style='font-size:120%;'><a href='../reader/?view=para&book={$book}&para={$paragraph}' target='_blank' >$path</a></div>";
-																
-								if(substr($paliword,-1)=="n"){
-									$paliword=substr($paliword,0,-1);
-								}
-								$light_text=str_replace($paliword,"<hl>{$paliword}</hl>",$FetchPaliText[$iPali]["html"]);
-								echo  "<div class='wizard_par_div'>{$light_text}</div>";
-								echo  "<div class='search_para_tools'></div>";
-
-							}
-						}
-
-						echo  "</div>";
-					}
-				}		
-				break;
-		}
-		break;
-}
-
 
 ?>

+ 40 - 0
app/search/paliword_sc_pre.php

@@ -0,0 +1,40 @@
+<?php
+//全文搜索 预查询
+require_once '../path.php';
+require_once '../public/casesuf.inc';
+require_once '../public/union.inc';
+require_once "../public/_pdo.php";
+require_once "../public/function.php";
+require_once "../search/word_function.php";
+		
+$word=mb_strtolower($_GET["key"],'UTF-8');
+$arrWordList = str_getcsv($word," ");
+
+$searching=$arrWordList[count($arrWordList)-1];
+$dbfile = _FILE_DB_WORD_INDEX_;
+PDO_Connect("sqlite:".$dbfile);
+
+if(count($arrWordList)>1){
+	//echo "<div>";
+	foreach($arrWordList as $oneword){
+		//echo $oneword."+";
+	}
+
+}
+else{
+	$query = "SELECT word,word_en,count,bold FROM wordindex WHERE word_en  like  ? OR word like ? limit 0,20";
+	$Fetch = PDO_FetchAll($query,array("{$searching}%","{$searching}%"));
+	if(count($Fetch)<10){
+		$Fetch1 = PDO_FetchAll($query,array("%{$searching}%","%{$searching}%"));
+		foreach ($Fetch1 as $key => $value) {
+			# 
+			$Fetch[] = $value;
+		}
+	}
+	echo json_encode($Fetch,JSON_UNESCAPED_UNICODE);	
+}
+
+
+
+
+?>

+ 0 - 2
app/search/search.css

@@ -86,5 +86,3 @@ highlight {
 .fileter_item > .selected a:visited {
 	font-weight: 700;
 }
-.book_item > .selected {
-}