title_search.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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. _load_book_index();
  10. $op=$_GET["op"];
  11. $word=mb_strtolower($_GET["word"],'UTF-8');
  12. $org_word=$word;
  13. $arrWordList = str_getcsv($word," ");
  14. $count_return=0;
  15. $dict_list=array();
  16. global $PDO;
  17. function microtime_float()
  18. {
  19. list($usec, $sec) = explode(" ", microtime());
  20. return ((float)$usec + (float)$sec);
  21. }
  22. function render_book_list($strWord,$booklist=null){
  23. //查找这些词出现在哪些书中
  24. $arrBookType=json_decode(file_get_contents("../public/book_name/booktype.json"));
  25. PDO_Connect("sqlite:"._FILE_DB_RESRES_INDEX_);
  26. if(isset($booklist)){
  27. foreach($booklist as $oneBook){
  28. $aInputBook["{$oneBook}"]=1;
  29. }
  30. }
  31. $query = "select book,count(book) as co from 'index' where \"title_en\" like '%{$strWord}%' or \"title\" like '%{$strWord}%' group by book order by co DESC";
  32. $Fetch = PDO_FetchAll($query);
  33. $iFetch=count($Fetch);
  34. $newBookList=array();
  35. if($iFetch>0){
  36. $booktypesum["vinaya"]=array(0,0);
  37. $booktypesum["sutta"]=array(0,0);
  38. $booktypesum["abhidhamma"]=array(0,0);
  39. $booktypesum["anna"]=array(0,0);
  40. $booktypesum["mula"]=array(0,0);
  41. $booktypesum["atthakattha"]=array(0,0);
  42. $booktypesum["tika"]=array(0,0);
  43. $booktypesum["anna2"]=array(0,0);
  44. for($i=0;$i<$iFetch;$i++){
  45. $book=$Fetch[$i]["book"];
  46. $sum=$Fetch[$i]["co"];
  47. array_push($newBookList,array($book,$sum));
  48. $t1=$arrBookType[$book-1]->c1;
  49. $t2=$arrBookType[$book-1]->c2;
  50. if(isset($booktypesum[$t1])){
  51. $booktypesum[$t1][0]++;
  52. $booktypesum[$t1][1]+=$sum;
  53. }
  54. else{
  55. $booktypesum[$t1][0]=1;
  56. $booktypesum[$t1][1]=$sum;
  57. }
  58. if(isset($booktypesum[$t2])){
  59. $booktypesum[$t2][0]++;
  60. $booktypesum[$t2][1]+=$sum;
  61. }
  62. else{
  63. $booktypesum[$t2][0]=1;
  64. $booktypesum[$t2][1]=$sum;
  65. }
  66. }
  67. echo "<div id='bold_book_list_new'>";
  68. echo "出现在{$iFetch}本书中:<br />";
  69. echo "<input id='bold_all_book' type='checkbox' checked onclick=\"dict_bold_book_all_select()\" />全选<br />";
  70. echo "<input id='id_book_filter_vinaya' type='checkbox' checked onclick=\"search_book_filter('id_book_filter_vinaya','vinaya')\" />律藏-{$booktypesum["vinaya"][0]}-{$booktypesum["vinaya"][1]}<br />";
  71. echo "<input id='id_book_filter_sutta' type='checkbox' checked onclick=\"search_book_filter('id_book_filter_sutta','sutta')\" />经藏-{$booktypesum["sutta"][0]}-{$booktypesum["sutta"][1]}<br />";
  72. echo "<input id='id_book_filter_abhidhamma' type='checkbox' checked onclick=\"search_book_filter('id_book_filter_abhidhamma','abhidhamma')\" />阿毗达摩藏-{$booktypesum["abhidhamma"][0]}-{$booktypesum["abhidhamma"][1]}<br />";
  73. echo "<input id='id_book_filter_anna' type='checkbox' checked onclick=\"search_book_filter('id_book_filter_anna','anna')\" />其他-{$booktypesum["anna"][0]}-{$booktypesum["anna"][1]}<br /><br />";
  74. echo "<input id='id_book_filter_mula' type='checkbox' checked onclick=\"search_book_filter('id_book_filter_mula','mula')\" />根本-{$booktypesum["mula"][0]}-{$booktypesum["mula"][1]}<br />";
  75. echo "<input id='id_book_filter_atthakattha' type='checkbox' checked onclick=\"search_book_filter('id_book_filter_atthakattha','atthakattha')\" />义注-{$booktypesum["atthakattha"][0]}-{$booktypesum["atthakattha"][1]}<br />";
  76. echo "<input id='id_book_filter_tika' type='checkbox' checked onclick=\"search_book_filter('id_book_filter_tika','tika')\" />复注-{$booktypesum["tika"][0]}-{$booktypesum["tika"][1]}<br />";
  77. echo "<input id='id_book_filter_anna2' type='checkbox' checked onclick=\"search_book_filter('id_book_filter_anna2','anna2')\" />其他-{$booktypesum["anna2"][0]}-{$booktypesum["anna2"][1]}<br /><br />";
  78. echo "<hr>";
  79. for($i=0;$i<$iFetch;$i++){
  80. $book=$Fetch[$i]["book"];
  81. $bookname=_get_book_info($book)->title;
  82. if(isset($booklist)){
  83. if(isset($aInputBook["{$book}"])){
  84. $bookcheck="checked";
  85. }
  86. else{
  87. $bookcheck="";
  88. }
  89. }
  90. else{
  91. $bookcheck="checked";
  92. }
  93. $t1=$arrBookType[$book-1]->c1;
  94. $t2=$arrBookType[$book-1]->c2;
  95. echo "<div class='{$t1}'>";
  96. echo "<div class='{$t2}'>";
  97. echo "<input id='bold_book_{$i}' type='checkbox' $bookcheck value='{$book}'/>";
  98. echo "<a onclick=\"dict_bold_book_select({$i})\">";
  99. echo "《{$bookname}》({$Fetch[$i]["co"]})<br />";
  100. echo "</a>";
  101. echo "</div></div>";
  102. }
  103. echo "<input id='bold_book_count' type='hidden' value='{$iFetch}' />";
  104. echo "</div>";
  105. }
  106. return($newBookList);
  107. //查找这些词出现在哪些书中结束
  108. }
  109. switch($op){
  110. case "pre"://预查询
  111. {
  112. $time_start = microtime_float();
  113. $searching=$arrWordList[count($arrWordList)-1];
  114. PDO_Connect("sqlite:"._FILE_DB_RESRES_INDEX_);
  115. if(count($arrWordList)>1){
  116. echo "<div>";
  117. foreach($arrWordList as $oneword){
  118. echo $oneword."+";
  119. }
  120. echo "</div>";
  121. }
  122. echo "<div>";
  123. $query = "select title from 'index' where \"title_en\" like ".$PDO->quote("%".$searching.'%')." OR \"title\" like ".$PDO->quote("%".$searching.'%')." group by title limit 0,50";
  124. echo $query;
  125. $Fetch = PDO_FetchAll($query);
  126. $queryTime=(microtime_float()-$time_start)*1000;
  127. echo "<div >搜索时间:$queryTime </div>";
  128. $iFetch=count($Fetch);
  129. if($iFetch>0){
  130. for($i=0;$i<$iFetch;$i++){
  131. $word=$Fetch[$i]["title"];
  132. echo "<div class='dict_word_list' style='color:black;'>";
  133. echo "<a href='title.php?key={$word}'>$word</a>";
  134. echo "</div>";
  135. }
  136. }
  137. echo "</div>";
  138. break;
  139. }
  140. case "search":
  141. {
  142. $time_start = microtime_float();
  143. echo "<div id=\"dict_bold\">";
  144. //主显示区开始
  145. echo "<div style='display:flex;'>";
  146. //主显示区左侧开始
  147. echo "<div style='flex:3;max-width: 17em;min-width: 10em;'>";
  148. echo "<button onclick=\"dict_update_bold(0)\">筛选</button>";
  149. $queryTime=(microtime_float()-$time_start)*1000;
  150. echo "<hr>";
  151. //查找这些词出现在哪些书中
  152. echo "<div id='bold_book_list'>";
  153. $booklist=render_book_list($_GET["word"]);
  154. echo "</div>";
  155. $wordInBookCounter=0;
  156. $strFirstBookList="(";
  157. foreach($booklist as $onebook){
  158. $wordInBookCounter+=$onebook[1];
  159. $strFirstBookList.="'".$onebook[0]."',";
  160. if($wordInBookCounter>=20){
  161. break;
  162. }
  163. }
  164. $strFirstBookList=mb_substr($strFirstBookList, 0,mb_strlen($strFirstBookList,"UTF-8")-1,"UTF-8");
  165. $strFirstBookList.=")";
  166. echo "</div>";
  167. //黑体字主显示区左侧结束
  168. //黑体字主显示区右侧开始
  169. echo "<div id=\"dict_bold_right\" style='flex:7;'>";
  170. //前20条记录
  171. $time_start=microtime_float();
  172. PDO_Connect("sqlite:"._FILE_DB_RESRES_INDEX_);
  173. if(isset($_GET["booklist"])){
  174. $query = "select * from 'index' where (\"title_en\" like ".$PDO->quote("%".$_GET["word"].'%')." OR \"title\" like ".$PDO->quote("%".$_GET["word"].'%').") and book in {$_GET["booklist"]} limit 0,50";
  175. }
  176. else{
  177. $query = "select * from 'index' where \"title_en\" like ".$PDO->quote("%".$_GET["word"].'%')." OR \"title\" like ".$PDO->quote("%".$_GET["word"].'%')." limit 0,50";
  178. }
  179. $Fetch = PDO_FetchAll($query);
  180. echo "<div>$query</div>";
  181. $queryTime=(microtime_float()-$time_start)*1000;
  182. $iFetch=count($Fetch);
  183. if($iFetch>0){
  184. PDO_Connect("sqlite:"._FILE_DB_PALITEXT_);
  185. for($i=0;$i<$iFetch;$i++){
  186. $title=$Fetch[$i]["title"];
  187. $book=$Fetch[$i]["book"];
  188. $paragraph=$Fetch[$i]["paragraph"];
  189. echo "<div style='margin: 10px 0;padding: 5px;border-bottom: 1px solid var(--border-line-color);'>";
  190. echo "<div style='font-size: 130%;font-weight: 700;'><a href='../pcdl/reader.php?book={$book}&paragraph={$paragraph}' target='_blank'>$title</a></div><br/>";
  191. $bookInfo = _get_book_info($book);
  192. $bookname=$bookInfo->title;
  193. $c1=$bookInfo->c1;
  194. $c2=$bookInfo->c2;
  195. $c3=$bookInfo->c3;
  196. $path_1 = $c1.">";
  197. if($c2 !== ""){
  198. $path_1=$path_1.$c2.">";
  199. }
  200. if($c3 !== ""){
  201. $path_1=$path_1.$c3.">";
  202. }
  203. $path_1=$path_1."《{$bookname}》>";
  204. $path = _get_para_path($book,$paragraph);
  205. echo $path_1.$path;
  206. $query = "select chapter_len from pali_text where \"book\" = '{$book}' and \"paragraph\" = '{$paragraph}' limit 0,1";
  207. $chapter_len = PDO_FetchAll($query);
  208. $chapter_len = $chapter_len[0]["chapter_len"];
  209. $query = "select text from pali_text where \"book\" = '{$book}' and (\"paragraph\" > '{$paragraph}' and \"paragraph\" <= '".($paragraph+$chapter_len)."') limit 0,3";
  210. $FetchPaliText = PDO_FetchAll($query);
  211. $paliContent = "";
  212. foreach($FetchPaliText as $text){
  213. $paliContent .= $text["text"];
  214. }
  215. $paliContent = mb_substr($paliContent,0,200,"UTF-8");
  216. echo "<div>{$paliContent}</div>";
  217. echo "<div class='search_para_tools'><button onclick=\"search_edit_now('{$book}','{$paragraph}','{$title}')\">Edit</button></div>";
  218. echo "</div>";
  219. }
  220. }
  221. $queryTime=(microtime_float()-$time_start)*1000;
  222. echo "<div >搜索时间:$queryTime </div>";
  223. echo "</div>";
  224. //黑体字主显示区右侧结束
  225. echo "<div id=\"dict_bold_review\" style='flex:2;'>";
  226. echo "haha";
  227. echo "</div>";
  228. echo "</div>";
  229. //黑体字主显示区结束
  230. echo "</div>";
  231. //查黑体字结束
  232. echo "<div id='real_dict_tab'></div>";
  233. break;
  234. }
  235. case "update":
  236. $target=$_GET["target"];
  237. switch($target){
  238. case "bold";
  239. $wordlist=$_GET["wordlist"];
  240. $booklist=$_GET["booklist"];
  241. $aBookList=ltrim($booklist,"(");
  242. $aBookList=rtrim($aBookList,")");
  243. $aBookList=str_replace("'","",$aBookList);
  244. $aBookList=str_getcsv($aBookList);
  245. $arrBookType=json_decode(file_get_contents("../public/book_name/booktype.json"));
  246. //查找这些词出现在哪些书中
  247. $newBookList=render_book_list($wordlist,$aBookList);
  248. //前20条记录
  249. $time_start=microtime_float();
  250. $dictFileName=_FILE_DB_PALI_INDEX_;
  251. PDO_Connect("sqlite:$dictFileName");
  252. $query = "select * from word where \"wordindex\" in $wordlist and \"book\" in $booklist group by book,paragraph limit 0,20";
  253. $Fetch = PDO_FetchAll($query);
  254. //echo "<div>$query</div>";
  255. $queryTime=(microtime_float()-$time_start)*1000;
  256. echo "<div >搜索时间:$queryTime </div>";
  257. $iFetch=count($Fetch);
  258. if($iFetch>0){
  259. $dictFileName=_FILE_DB_PALITEXT_;
  260. PDO_Connect("sqlite:$dictFileName");
  261. for($i=0;$i<$iFetch;$i++){
  262. $paliword=$Fetch[$i]["wordindex"];
  263. //$paliword=$wordlist["{$paliwordid}"];
  264. $book=$Fetch[$i]["book"];
  265. $bookInfo = _get_book_info($book);
  266. $bookname=$bookInfo->title;
  267. $c1=$bookInfo->c1;
  268. $c2=$bookInfo->c2;
  269. $c3=$bookInfo->c3;
  270. $paragraph=$Fetch[$i]["paragraph"];
  271. $path_1 = $c1.">";
  272. if($c2 !== ""){
  273. $path_1=$path_1.$c2.">";
  274. }
  275. if($c3 !== ""){
  276. $path_1=$path_1.$c3.">";
  277. }
  278. $path_1=$path_1."《{$bookname}》>";
  279. echo "<div class='dict_word'>";
  280. echo "<div class='dict'>《{$bookname}》 $c1 $c2 </div>";
  281. echo "<div class='mean'>$paliword</div>";
  282. $query = "select * from pali_text where \"book\" = '{$book}' and \"paragraph\" = '{$paragraph}' limit 0,20";
  283. $FetchPaliText = PDO_FetchAll($query);
  284. $countPaliText=count($FetchPaliText);
  285. if($countPaliText>0){
  286. for($iPali=0;$iPali<$countPaliText;$iPali++){
  287. $path="";
  288. $parent = $FetchPaliText[0]["parent"];
  289. $deep=0;
  290. $sFirstParentTitle="";
  291. while($parent>-1){
  292. $query = "select * from pali_text where \"book\" = '{$book}' and \"paragraph\" = '{$parent}' limit 0,1";
  293. $FetParent = PDO_FetchAll($query);
  294. if($sFirstParentTitle==""){
  295. $sFirstParentTitle = $FetParent[0]["toc"];
  296. }
  297. $path="{$FetParent[0]["toc"]}>{$path}";
  298. $parent = $FetParent[0]["parent"];
  299. $deep++;
  300. if($deep>5){
  301. break;
  302. }
  303. }
  304. $path=$path_1.$path."No. ".$paragraph;
  305. echo "<div class='mean'>$path</div>";
  306. //echo "<div class='mean'>$paliword</div>";
  307. if(substr($paliword,-1)=="n"){
  308. $paliword=substr($paliword,0,-1);
  309. }
  310. $light_text=str_replace($paliword,"<hl>{$paliword}</hl>",$FetchPaliText[$iPali]["html"]);
  311. echo "<div class='wizard_par_div'>{$light_text}</div>";
  312. echo "<div class='search_para_tools'><button onclick=\"search_edit_now('{$book}','{$paragraph}','{$sFirstParentTitle}')\">Edit</button></div>";
  313. }
  314. }
  315. echo "</div>";
  316. }
  317. }
  318. break;
  319. }
  320. break;
  321. }
  322. ?>