paliword_search.php 11 KB

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