paliword_search.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. <?php
  2. //全文搜索
  3. require_once '../path.php';
  4. require_once '../public/casesuf.inc';
  5. require_once '../public/union.inc';
  6. require_once "../public/_pdo.php";
  7. require_once "../public/load_lang.php";//语言文件
  8. require_once "../public/function.php";
  9. require_once "../search/word_function.php";
  10. _load_book_index();
  11. $op=$_GET["op"];
  12. $word=mb_strtolower($_GET["word"],'UTF-8');
  13. $org_word=$word;
  14. $arrWordList = str_getcsv($word," ");
  15. $count_return=0;
  16. $dict_list=array();
  17. global $PDO;
  18. function microtime_float()
  19. {
  20. list($usec, $sec) = explode(" ", microtime());
  21. return ((float)$usec + (float)$sec);
  22. }
  23. switch($op){
  24. case "pre"://预查询
  25. {
  26. $time_start = microtime_float();
  27. $searching=$arrWordList[count($arrWordList)-1];
  28. $dbfile = _FILE_DB_WORD_INDEX_;
  29. echo $dbfile;
  30. PDO_Connect("sqlite:".$dbfile);
  31. if(count($arrWordList)>1){
  32. echo "<div>";
  33. foreach($arrWordList as $oneword){
  34. echo $oneword."+";
  35. }
  36. echo "</div>";
  37. }
  38. echo "<div>";
  39. $query = "select word,count from wordindex where \"word_en\" like ".$PDO->quote($searching.'%')." OR \"word\" like ".$PDO->quote($searching.'%')." limit 0,50";
  40. echo $query;
  41. $Fetch = PDO_FetchAll($query);
  42. $queryTime=(microtime_float()-$time_start)*1000;
  43. echo "<div >搜索时间:$queryTime </div>";
  44. $iFetch=count($Fetch);
  45. if($iFetch>0){
  46. for($i=0;$i<$iFetch;$i++){
  47. $word=$Fetch[$i]["word"];
  48. $count=$Fetch[$i]["count"];
  49. echo "<div class='dict_word_list'>";
  50. echo "<a href='paliword.php?key={$word}'>$word-$count</a>";
  51. echo "</div>";
  52. }
  53. }
  54. echo "</div>";
  55. break;
  56. }
  57. case "search":
  58. {
  59. if(count($arrWordList)>1){
  60. $strQuery="";
  61. foreach($arrWordList as $oneword){
  62. $strQuery.="\"text\" like \"% {$oneword} %\" AND";
  63. }
  64. $strQuery = substr($strQuery,0,-3);
  65. $dictFileName=_FILE_DB_PALITEXT_;
  66. PDO_Connect("sqlite:$dictFileName");
  67. $query = "SELECT book,paragraph, html FROM pali_text WHERE {$strQuery} LIMIT 0,20";
  68. $Fetch = PDO_FetchAll($query);
  69. echo "<div>$query</div>";
  70. $iFetch=count($Fetch);
  71. foreach($Fetch as $row){
  72. $html = $row["html"];
  73. foreach($arrWordList as $oneword){
  74. $html=str_replace($oneword,"<hl>{$oneword}</hl>",$html);
  75. }
  76. echo "<div class='dict_word'>{$html}</div>";
  77. }
  78. return;
  79. }
  80. //计算某词在三藏中出现的次数
  81. $time_start = microtime_float();
  82. $arrRealWordList = countWordInPali($word);
  83. $countWord=count($arrRealWordList);
  84. if($countWord==0){
  85. echo "<p>没有查到。可能是拼写有问题。</p>";
  86. exit;
  87. }
  88. $strQueryWordId="(";//实际出现的单词id查询字串
  89. $aQueryWordList=array();//id 为键 拼写为值的数组
  90. $aShowWordList=array();//拼写为键 个数为值的数组
  91. $aShowWordIdList=array();//拼写为键 值Id的数组
  92. for($i=0;$i<$countWord;$i++){
  93. $value= $arrRealWordList[$i];
  94. $strQueryWordId.="'{$value["id"]}',";
  95. $aQueryWordList["{$value["id"]}"]=$value["word"];
  96. $aShowWordList[$value["word"]]=$value["count"];
  97. $aShowWordIdList[$value["word"]]=$value["id"];
  98. }
  99. $strQueryWordId=mb_substr($strQueryWordId, 0,mb_strlen($strQueryWordId,"UTF-8")-1,"UTF-8");
  100. $strQueryWordId.=")";
  101. $queryTime=(microtime_float()-$time_start)*1000;
  102. echo "<div id=\"dict_bold\">";
  103. //主显示区开始
  104. echo "<div style='display:flex;'>";
  105. //主显示区左侧开始
  106. echo "<div style='flex:3;max-width: 17em;min-width: 10em;'>";
  107. echo "<button onclick=\"dict_update_bold(0)\">筛选</button>";
  108. echo "<div>共{$countWord}单词符合</div>";
  109. //显示单词列表
  110. echo "<div>";
  111. echo "<input id='bold_all_word' type='checkbox' checked='true' value='' onclick=\"dict_bold_word_all_select()\"/>全选<br />";
  112. arsort($aShowWordList);
  113. $i=0;
  114. foreach($aShowWordList as $x=>$x_value) {
  115. $wordid=$aShowWordIdList[$x];
  116. echo "<input id='bold_word_{$i}' type='checkbox' checked value='{$wordid}' />";
  117. echo "<a onclick=\"dict_bold_word_select({$i})\">";
  118. echo $x.":".$x_value."<br />";
  119. echo "</a>";
  120. $i++;
  121. }
  122. echo "<input id='bold_word_count' type='hidden' value='{$countWord}' />";
  123. echo "</div>";
  124. //查找这些词出现在哪些书中
  125. echo "<div id='bold_book_list'>";
  126. $booklist=render_book_list($strQueryWordId);
  127. echo "</div>";
  128. $wordInBookCounter=0;
  129. $strFirstBookList="(";
  130. foreach($booklist as $onebook){
  131. $wordInBookCounter+=$onebook[1];
  132. $strFirstBookList.="'".$onebook[0]."',";
  133. if($wordInBookCounter>=20){
  134. break;
  135. }
  136. }
  137. $strFirstBookList=mb_substr($strFirstBookList, 0,mb_strlen($strFirstBookList,"UTF-8")-1,"UTF-8");
  138. $strFirstBookList.=")";
  139. echo "</div>";
  140. //黑体字主显示区左侧结束
  141. //黑体字主显示区右侧开始
  142. echo "<div id=\"dict_bold_right\" style='flex:7;'>";
  143. //前20条记录
  144. $time_start=microtime_float();
  145. $dictFileName=_FILE_DB_PALI_INDEX_;
  146. PDO_Connect("sqlite:$dictFileName");
  147. $query = "SELECT book,paragraph, wordindex FROM word WHERE \"wordindex\" in $strQueryWordId and book in $strFirstBookList group by book,paragraph LIMIT 0,20";
  148. $Fetch = PDO_FetchAll($query);
  149. //echo "<div>$query</div>";
  150. $queryTime=(microtime_float()-$time_start)*1000;
  151. $iFetch=count($Fetch);
  152. if($iFetch>0){
  153. $dictFileName=_FILE_DB_PALITEXT_;
  154. PDO_Connect("sqlite:$dictFileName");
  155. for($i=0;$i<$iFetch;$i++){
  156. $paliwordid=$Fetch[$i]["wordindex"];
  157. $paliword=$aQueryWordList["{$paliwordid}"];
  158. $book=$Fetch[$i]["book"];
  159. $paragraph=$Fetch[$i]["paragraph"];
  160. $bookInfo = _get_book_info($book);
  161. $bookname=$bookInfo->title;
  162. $c1=$bookInfo->c1;
  163. $c2=$bookInfo->c2;
  164. $c3=$bookInfo->c3;
  165. echo "<div class='dict_word' style='margin: 10px 0;padding: 5px;border-bottom: 1px solid var(--border-line-color);'>";
  166. echo "<div style='font-size: 130%;font-weight: 700;'>$paliword</div><br/>";
  167. //echo "<div class='dict_word'>";
  168. $path_1 = $c1.">";
  169. if($c2 !== ""){
  170. $path_1=$path_1.$c2.">";
  171. }
  172. if($c3 !== ""){
  173. $path_1=$path_1.$c3.">";
  174. }
  175. $path_1=$path_1."《{$bookname}》>";
  176. $query = "select * from pali_text where \"book\" = '{$book}' and \"paragraph\" = '{$paragraph}' limit 0,1";
  177. $FetchPaliText = PDO_FetchAll($query);
  178. $countPaliText=count($FetchPaliText);
  179. if($countPaliText>0){
  180. $path="";
  181. $parent = $FetchPaliText[0]["parent"];
  182. $deep=0;
  183. $sFirstParentTitle="";
  184. //循环查找父标题 得到整条路径
  185. while($parent>-1){
  186. $query = "select * from pali_text where \"book\" = '{$book}' and \"paragraph\" = '{$parent}' limit 0,1";
  187. $FetParent = PDO_FetchAll($query);
  188. $path="{$FetParent[0]["toc"]}>{$path}";
  189. if($sFirstParentTitle==""){
  190. $sFirstParentTitle = $FetParent[0]["toc"];
  191. }
  192. $parent = $FetParent[0]["parent"];
  193. $deep++;
  194. if($deep>5){
  195. break;
  196. }
  197. }
  198. $path=$path_1.$path."para. ".$paragraph;
  199. echo "<div class='mean'><a href='../pcdl/reader.php?book={$book}&paragraph={$FetchPaliText[0]["parent"]}' target='_blank'>$path</a></div>";
  200. for($iPali=0;$iPali<$countPaliText;$iPali++){
  201. if(substr($paliword,-1)=="n"){
  202. $paliword=substr($paliword,0,-1);
  203. }
  204. $htmltext=$FetchPaliText[0]["html"];
  205. $light_text=str_replace($paliword,"<hl>{$paliword}</hl>",$htmltext);
  206. echo "<div class='wizard_par_div'>{$light_text}</div>";
  207. }
  208. //echo "<div class='wizard_par_div'>{$light_text}</div>";
  209. echo "<div class='search_para_tools'><button onclick=\"search_edit_now('{$book}','{$paragraph}','{$sFirstParentTitle}')\">Edit</button></div>";
  210. }
  211. echo "</div>";
  212. }
  213. }
  214. $queryTime=(microtime_float()-$time_start)*1000;
  215. echo "<div >搜索时间:$queryTime </div>";
  216. echo "</div>";
  217. //黑体字主显示区右侧结束
  218. echo "<div id=\"dict_bold_review\" style='flex:2;'>";
  219. echo "haha";
  220. echo "</div>";
  221. echo "</div>";
  222. //黑体字主显示区结束
  223. echo "</div>";
  224. //查黑体字结束
  225. echo "<div id='real_dict_tab'></div>";
  226. break;
  227. }
  228. case "update":
  229. $target=$_GET["target"];
  230. switch($target){
  231. case "bold";
  232. $wordlist=$_GET["wordlist"];
  233. $booklist=$_GET["booklist"];
  234. $aBookList=ltrim($booklist,"(");
  235. $aBookList=rtrim($aBookList,")");
  236. $aBookList=str_replace("'","",$aBookList);
  237. $aBookList=str_getcsv($aBookList);
  238. $arrBookType=json_decode(file_get_contents("../public/book_name/booktype.json"));
  239. //查找这些词出现在哪些书中
  240. $newBookList=render_book_list($wordlist,$aBookList);
  241. //前20条记录
  242. $time_start=microtime_float();
  243. $dictFileName=_FILE_DB_WORD_INDEX_;
  244. PDO_Connect("sqlite:$dictFileName");
  245. $query = "select * from word where \"wordindex\" in $wordlist and \"book\" in $booklist group by book,paragraph limit 0,20";
  246. $Fetch = PDO_FetchAll($query);
  247. //echo "<div>$query</div>";
  248. $queryTime=(microtime_float()-$time_start)*1000;
  249. echo "<div >搜索时间:$queryTime </div>";
  250. $iFetch=count($Fetch);
  251. if($iFetch>0){
  252. $dictFileName=_FILE_DB_PALITEXT_;
  253. PDO_Connect("sqlite:$dictFileName");
  254. for($i=0;$i<$iFetch;$i++){
  255. $paliword=$Fetch[$i]["wordindex"];
  256. //$paliword=$wordlist["{$paliwordid}"];
  257. $book=$Fetch[$i]["book"];
  258. $bookInfo = _get_book_info($book);
  259. $bookname=$bookInfo->title;
  260. $c1=$bookInfo->c1;
  261. $c2=$bookInfo->c2;
  262. $c3=$bookInfo->c3;
  263. $paragraph=$Fetch[$i]["paragraph"];
  264. $path_1 = $c1.">";
  265. if($c2 !== ""){
  266. $path_1=$path_1.$c2.">";
  267. }
  268. if($c3 !== ""){
  269. $path_1=$path_1.$c3.">";
  270. }
  271. $path_1=$path_1."《{$bookname}》>";
  272. echo "<div class='dict_word'>";
  273. echo "<div class='dict'>《{$bookname}》 $c1 $c2 </div>";
  274. echo "<div class='mean'>$paliword</div>";
  275. $query = "select * from pali_text where \"book\" = '{$book}' and \"paragraph\" = '{$paragraph}' limit 0,20";
  276. $FetchPaliText = PDO_FetchAll($query);
  277. $countPaliText=count($FetchPaliText);
  278. if($countPaliText>0){
  279. for($iPali=0;$iPali<$countPaliText;$iPali++){
  280. $path="";
  281. $parent = $FetchPaliText[0]["parent"];
  282. $deep=0;
  283. $sFirstParentTitle="";
  284. while($parent>-1){
  285. $query = "select * from pali_text where \"book\" = '{$book}' and \"paragraph\" = '{$parent}' limit 0,1";
  286. $FetParent = PDO_FetchAll($query);
  287. if($sFirstParentTitle==""){
  288. $sFirstParentTitle = $FetParent[0]["toc"];
  289. }
  290. $path="{$FetParent[0]["toc"]}>{$path}";
  291. $parent = $FetParent[0]["parent"];
  292. $deep++;
  293. if($deep>5){
  294. break;
  295. }
  296. }
  297. $path=$path_1.$path."No. ".$paragraph;
  298. echo "<div class='mean'>$path</div>";
  299. //echo "<div class='mean'>$paliword</div>";
  300. if(substr($paliword,-1)=="n"){
  301. $paliword=substr($paliword,0,-1);
  302. }
  303. $light_text=str_replace($paliword,"<hl>{$paliword}</hl>",$FetchPaliText[$iPali]["html"]);
  304. echo "<div class='wizard_par_div'>{$light_text}</div>";
  305. echo "<div class='search_para_tools'><button onclick=\"search_edit_now('{$book}','{$paragraph}','{$sFirstParentTitle}')\">Edit</button></div>";
  306. }
  307. }
  308. echo "</div>";
  309. }
  310. }
  311. break;
  312. }
  313. break;
  314. }
  315. ?>