title_search.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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 "<div style='margin:1em 0 ;'></div>";
  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. $query = "select title from 'index' where \"title_en\" like ".$PDO->quote("%".$searching.'%')." OR \"title\" like ".$PDO->quote("%".$searching.'%')." group by title limit 0,20";
  123. $Fetch = PDO_FetchAll($query);
  124. $queryTime=(microtime_float()-$time_start)*1000;
  125. $iFetch=count($Fetch);
  126. if($iFetch>0){
  127. for($i=0;$i<$iFetch;$i++){
  128. $word=$Fetch[$i]["title"];
  129. echo "<a href='title.php?key={$word}'>$word</a>";
  130. }
  131. }
  132. break;
  133. }
  134. case "search":
  135. {
  136. $time_start = microtime_float();
  137. echo "<div id=\"dict_bold\">";
  138. //主显示区开始
  139. echo "<div style='display:flex;'>";
  140. //主显示区左侧开始
  141. echo "<div style='flex:3;max-width: 17em;min-width: 10em;'>";
  142. echo "<button onclick=\"dict_update_bold(0)\">筛选</button>";
  143. $queryTime=(microtime_float()-$time_start)*1000;
  144. echo "<div ></div>";
  145. //查找这些词出现在哪些书中
  146. echo "<div id='bold_book_list'>";
  147. $booklist=render_book_list($_GET["word"]);
  148. echo "</div>";
  149. $wordInBookCounter=0;
  150. $strFirstBookList="(";
  151. foreach($booklist as $onebook){
  152. $wordInBookCounter+=$onebook[1];
  153. $strFirstBookList.="'".$onebook[0]."',";
  154. if($wordInBookCounter>=20){
  155. break;
  156. }
  157. }
  158. $strFirstBookList=mb_substr($strFirstBookList, 0,mb_strlen($strFirstBookList,"UTF-8")-1,"UTF-8");
  159. $strFirstBookList.=")";
  160. echo "</div>";
  161. //黑体字主显示区左侧结束
  162. //黑体字主显示区右侧开始
  163. echo "<div id=\"dict_bold_right\" style='flex:7;'>";
  164. //前20条记录
  165. $time_start=microtime_float();
  166. PDO_Connect("sqlite:"._FILE_DB_RESRES_INDEX_);
  167. if(isset($_GET["booklist"])){
  168. $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";
  169. }
  170. else{
  171. $query = "select * from 'index' where \"title_en\" like ".$PDO->quote("%".$_GET["word"].'%')." OR \"title\" like ".$PDO->quote("%".$_GET["word"].'%')." limit 0,50";
  172. }
  173. $Fetch = PDO_FetchAll($query);
  174. $queryTime=(microtime_float()-$time_start)*1000;
  175. $iFetch=count($Fetch);
  176. if($iFetch>0){
  177. PDO_Connect("sqlite:"._FILE_DB_PALITEXT_);
  178. for($i=0;$i<$iFetch;$i++){
  179. $title=$Fetch[$i]["title"];
  180. $book=$Fetch[$i]["book"];
  181. $paragraph=$Fetch[$i]["paragraph"];
  182. echo "<div style='margin: 10px 0;padding: 5px;border-bottom: 1px solid var(--border-line-color);'>";
  183. echo "<div style='font-size: 130%;font-weight: 700;'><a href='../pcdl/reader.php?view=chapter&book={$book}&paragraph={$paragraph}' target='_blank'>$title</a></div>";
  184. $bookInfo = _get_book_info($book);
  185. $bookname=$bookInfo->title;
  186. $c1=$bookInfo->c1;
  187. $c2=$bookInfo->c2;
  188. $c3=$bookInfo->c3;
  189. $path_1 = $c1.">";
  190. if($c2 !== ""){
  191. $path_1=$path_1.$c2.">";
  192. }
  193. if($c3 !== ""){
  194. $path_1=$path_1.$c3.">";
  195. }
  196. $path_1=$path_1."《{$bookname}》>";
  197. $path = _get_para_path($book,$paragraph);
  198. echo $path_1.$path;
  199. $query = "select chapter_len from pali_text where \"book\" = '{$book}' and \"paragraph\" = '{$paragraph}' limit 0,1";
  200. $chapter_len = PDO_FetchAll($query);
  201. $chapter_len = $chapter_len[0]["chapter_len"];
  202. $query = "select text from pali_text where \"book\" = '{$book}' and (\"paragraph\" > '{$paragraph}' and \"paragraph\" <= '".($paragraph+$chapter_len)."') limit 0,3";
  203. $FetchPaliText = PDO_FetchAll($query);
  204. $paliContent = "";
  205. foreach($FetchPaliText as $text){
  206. $paliContent .= $text["text"];
  207. }
  208. $paliContent = mb_substr($paliContent,0,200,"UTF-8");
  209. echo "<div>{$paliContent}</div>";
  210. echo "<div class='search_para_tools'></div>";
  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 "</div>";
  220. echo "</div>";
  221. //黑体字主显示区结束
  222. echo "</div>";
  223. //查黑体字结束
  224. echo "<div id='real_dict_tab'></div>";
  225. break;
  226. }
  227. case "update":
  228. $target=$_GET["target"];
  229. switch($target){
  230. case "bold";
  231. $wordlist=$_GET["wordlist"];
  232. $booklist=$_GET["booklist"];
  233. $aBookList=ltrim($booklist,"(");
  234. $aBookList=rtrim($aBookList,")");
  235. $aBookList=str_replace("'","",$aBookList);
  236. $aBookList=str_getcsv($aBookList);
  237. $arrBookType=json_decode(file_get_contents("../public/book_name/booktype.json"));
  238. //查找这些词出现在哪些书中
  239. $newBookList=render_book_list($wordlist,$aBookList);
  240. //前20条记录
  241. $time_start=microtime_float();
  242. $dictFileName=_FILE_DB_PALI_INDEX_;
  243. PDO_Connect("sqlite:$dictFileName");
  244. $query = "select * from word where \"wordindex\" in $wordlist and \"book\" in $booklist group by book,paragraph limit 0,20";
  245. $Fetch = PDO_FetchAll($query);
  246. //echo "<div>$query</div>";
  247. $queryTime=(microtime_float()-$time_start)*1000;
  248. echo "<div >搜索时间:$queryTime </div>";
  249. $iFetch=count($Fetch);
  250. if($iFetch>0){
  251. $dictFileName=_FILE_DB_PALITEXT_;
  252. PDO_Connect("sqlite:$dictFileName");
  253. for($i=0;$i<$iFetch;$i++){
  254. $paliword=$Fetch[$i]["wordindex"];
  255. //$paliword=$wordlist["{$paliwordid}"];
  256. $book=$Fetch[$i]["book"];
  257. $bookInfo = _get_book_info($book);
  258. $bookname=$bookInfo->title;
  259. $c1=$bookInfo->c1;
  260. $c2=$bookInfo->c2;
  261. $c3=$bookInfo->c3;
  262. $paragraph=$Fetch[$i]["paragraph"];
  263. $path_1 = $c1.">";
  264. if($c2 !== ""){
  265. $path_1=$path_1.$c2.">";
  266. }
  267. if($c3 !== ""){
  268. $path_1=$path_1.$c3.">";
  269. }
  270. $path_1=$path_1."《{$bookname}》>";
  271. echo "<div class='dict_word'>";
  272. echo "<div class='dict'>《{$bookname}》 $c1 $c2 </div>";
  273. echo "<div class='mean'>$paliword</div>";
  274. $query = "select * from pali_text where \"book\" = '{$book}' and \"paragraph\" = '{$paragraph}' limit 0,20";
  275. $FetchPaliText = PDO_FetchAll($query);
  276. $countPaliText=count($FetchPaliText);
  277. if($countPaliText>0){
  278. for($iPali=0;$iPali<$countPaliText;$iPali++){
  279. $path="";
  280. $parent = $FetchPaliText[0]["parent"];
  281. $deep=0;
  282. $sFirstParentTitle="";
  283. while($parent>-1){
  284. $query = "select * from pali_text where \"book\" = '{$book}' and \"paragraph\" = '{$parent}' limit 0,1";
  285. $FetParent = PDO_FetchAll($query);
  286. if($sFirstParentTitle==""){
  287. $sFirstParentTitle = $FetParent[0]["toc"];
  288. }
  289. $path="{$FetParent[0]["toc"]}>{$path}";
  290. $parent = $FetParent[0]["parent"];
  291. $deep++;
  292. if($deep>5){
  293. break;
  294. }
  295. }
  296. $path=$path_1.$path."No. ".$paragraph;
  297. echo "<div class='mean'>$path</div>";
  298. //echo "<div class='mean'>$paliword</div>";
  299. if(substr($paliword,-1)=="n"){
  300. $paliword=substr($paliword,0,-1);
  301. }
  302. $light_text=str_replace($paliword,"<hl>{$paliword}</hl>",$FetchPaliText[$iPali]["html"]);
  303. echo "<div class='wizard_par_div'>{$light_text}</div>";
  304. echo "<div class='search_para_tools'></div>";
  305. }
  306. }
  307. echo "</div>";
  308. }
  309. }
  310. break;
  311. }
  312. break;
  313. }
  314. ?>