paliword_search.php 11 KB

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