search.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. <?php
  2. //全文搜索
  3. require_once '../public/casesuf.inc';
  4. require_once '../public/union.inc';
  5. require_once "../public/config.php";
  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($strWordlist,$booklist=null){
  23. //查找这些词出现在哪些书中
  24. $arrBookType=json_decode(file_get_contents("../public/book_name/booktype.json"));
  25. $dictFileName=_FILE_DB_BOOK_WORD_;
  26. PDO_Connect("sqlite:$dictFileName");
  27. if(isset($booklist)){
  28. foreach($booklist as $oneBook){
  29. $aInputBook["{$oneBook}"]=1;
  30. }
  31. }
  32. $query = "select book,sum(count) as co from bookword where \"wordindex\" in $strWordlist group by book order by co DESC";
  33. $Fetch = PDO_FetchAll($query);
  34. $iFetch=count($Fetch);
  35. $newBookList=array();
  36. if($iFetch>0){
  37. $booktypesum["vinaya"]=array(0,0);
  38. $booktypesum["sutta"]=array(0,0);
  39. $booktypesum["abhidhamma"]=array(0,0);
  40. $booktypesum["anna"]=array(0,0);
  41. $booktypesum["mula"]=array(0,0);
  42. $booktypesum["atthakattha"]=array(0,0);
  43. $booktypesum["tika"]=array(0,0);
  44. $booktypesum["anna2"]=array(0,0);
  45. for($i=0;$i<$iFetch;$i++){
  46. $book=$Fetch[$i]["book"];
  47. $sum=$Fetch[$i]["co"];
  48. array_push($newBookList,array($book,$sum));
  49. $t1=$arrBookType[$book-1]->c1;
  50. $t2=$arrBookType[$book-1]->c2;
  51. if(isset($booktypesum[$t1])){
  52. $booktypesum[$t1][0]++;
  53. $booktypesum[$t1][1]+=$sum;
  54. }
  55. else{
  56. $booktypesum[$t1][0]=1;
  57. $booktypesum[$t1][1]=$sum;
  58. }
  59. if(isset($booktypesum[$t2])){
  60. $booktypesum[$t2][0]++;
  61. $booktypesum[$t2][1]+=$sum;
  62. }
  63. else{
  64. $booktypesum[$t2][0]=1;
  65. $booktypesum[$t2][1]=$sum;
  66. }
  67. }
  68. echo "<div id='bold_book_list_new'>";
  69. echo "出现在{$iFetch}本书中:<br />";
  70. echo "<input id='bold_all_book' type='checkbox' checked onclick=\"dict_bold_book_all_select()\" />全选<br />";
  71. 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 />";
  72. 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 />";
  73. 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 />";
  74. 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 />";
  75. 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 />";
  76. 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 />";
  77. 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 />";
  78. 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 />";
  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. $dictFileName=_FILE_DB_word_INDEX_;
  115. PDO_Connect("sqlite:$dictFileName");
  116. if(count($arrWordList)>1){
  117. echo "<div>";
  118. foreach($arrWordList as $oneword){
  119. echo $oneword."+";
  120. }
  121. echo "</div>";
  122. }
  123. echo "<div>";
  124. $query = "select word,count from wordindex where \"word_en\" like ".$PDO->quote($searching.'%')." OR \"word\" like ".$PDO->quote($searching.'%')." limit 0,50";
  125. echo $query;
  126. $Fetch = PDO_FetchAll($query);
  127. $queryTime=(microtime_float()-$time_start)*1000;
  128. echo "<div >搜索时间:$queryTime </div>";
  129. $iFetch=count($Fetch);
  130. if($iFetch>0){
  131. for($i=0;$i<$iFetch;$i++){
  132. $word=$Fetch[$i]["word"];
  133. $count=$Fetch[$i]["count"];
  134. echo "<div class='dict_word_list'>";
  135. echo "<a onclick='dict_pre_word_click(\"$word\")'>$word-$count</a>";
  136. echo "</div>";
  137. }
  138. }
  139. echo "</div>";
  140. break;
  141. }
  142. case "search":
  143. {
  144. if(count($arrWordList)>1){
  145. $strQuery="";
  146. foreach($arrWordList as $oneword){
  147. $strQuery.="\"text\" like \"% {$oneword} %\" AND";
  148. }
  149. $strQuery = substr($strQuery,0,-3);
  150. $dictFileName=_FILE_DB_PALITEXT_;
  151. PDO_Connect("sqlite:$dictFileName");
  152. $query = "SELECT book,paragraph, html FROM pali_text WHERE {$strQuery} LIMIT 0,20";
  153. $Fetch = PDO_FetchAll($query);
  154. echo "<div>$query</div>";
  155. $iFetch=count($Fetch);
  156. foreach($Fetch as $row){
  157. $html = $row["html"];
  158. foreach($arrWordList as $oneword){
  159. $html=str_replace($oneword,"<hl>{$oneword}</hl>",$html);
  160. }
  161. echo "<div class='dict_word'>{$html}</div>";
  162. }
  163. return;
  164. }
  165. $strDictTab="<li id=\"dt_dict\" class=\"act\" onclick=\"tab_click('dict_ref','dt_dict')\">字典</li>";
  166. //加语尾
  167. $arrNewWord=array();
  168. for ($row = 0; $row < count($case); $row++) {
  169. $len=mb_strlen($case[$row][0],"UTF-8");
  170. $end=mb_substr($word, 0-$len,NULL,"UTF-8");
  171. if($end==$case[$row][0]){
  172. $newWord=mb_substr($word, 0,mb_strlen($word,"UTF-8")-$len,"UTF-8").$case[$row][1];
  173. $arrNewWord[$newWord]=1;
  174. }
  175. }
  176. //加连读词尾
  177. $arrUnWord=array();
  178. for ($row = 0; $row < count($union); $row++) {
  179. $len=mb_strlen($union[$row][0],"UTF-8");
  180. foreach($arrNewWord as $x=>$x_value){
  181. $end=mb_substr($x, 0-$len,NULL,"UTF-8");
  182. if($end==$union[$row][0]){
  183. $newWord=mb_substr($x, 0,mb_strlen($x,"UTF-8")-$len,"UTF-8").$union[$row][1];
  184. $arrUnWord[$newWord]=1;
  185. }
  186. }
  187. }
  188. //将连读词和$arrNewWord混合
  189. foreach($arrUnWord as $x=>$x_value){
  190. $arrNewWord[$x]=1;
  191. }
  192. if(count($arrNewWord)>0){
  193. $strQueryWord="(";
  194. foreach($arrNewWord as $x=>$x_value) {
  195. $strQueryWord.="'{$x}',";
  196. }
  197. $strQueryWord=mb_substr($strQueryWord, 0,mb_strlen($strQueryWord,"UTF-8")-1,"UTF-8");
  198. $strQueryWord.=")";
  199. }
  200. else{
  201. $strQueryWord="('{$word}')";
  202. }
  203. //查找实际出现的拼写
  204. $time_start = microtime_float();
  205. $dictFileName=_FILE_DB_word_INDEX_;
  206. PDO_Connect("sqlite:$dictFileName");
  207. $query = "select id,word,count from wordindex where \"word\" in $strQueryWord";
  208. $arrRealWordList = PDO_FetchAll($query);
  209. $countWord=count($arrRealWordList);
  210. if($countWord==0){
  211. echo "<p>没有查到。可能是拼写有问题。</p>";
  212. exit;
  213. }
  214. echo "<div id=\"dict_bold\">";
  215. //主显示区开始
  216. echo "<div style='display:flex;'>";
  217. //主显示区左侧开始
  218. echo "<div style='flex:3;max-width: 17em;min-width: 10em;'>";
  219. echo "<button onclick=\"dict_update_bold(0)\">筛选</button>";
  220. echo "<div>共{$countWord}单词符合</div>";
  221. $strQueryWordId="(";//实际出现的单词id查询字串
  222. $aQueryWordList=array();//id 为键 拼写为值的数组
  223. $aShowWordList=array();//拼写为键 个数为值的数组
  224. $aShowWordIdList=array();//拼写为键 值Id的数组
  225. for($i=0;$i<$countWord;$i++){
  226. $value= $arrRealWordList[$i];
  227. $strQueryWordId.="'{$value["id"]}',";
  228. $aQueryWordList["{$value["id"]}"]=$value["word"];
  229. $aShowWordList[$value["word"]]=$value["count"];
  230. $aShowWordIdList[$value["word"]]=$value["id"];
  231. }
  232. $strQueryWordId=mb_substr($strQueryWordId, 0,mb_strlen($strQueryWordId,"UTF-8")-1,"UTF-8");
  233. $strQueryWordId.=")";
  234. $queryTime=(microtime_float()-$time_start)*1000;
  235. //显示单词列表
  236. echo "<div>";
  237. echo "<input id='bold_all_word' type='checkbox' checked='true' value='' onclick=\"dict_bold_word_all_select()\"/>全选<br />";
  238. arsort($aShowWordList);
  239. $i=0;
  240. foreach($aShowWordList as $x=>$x_value) {
  241. $wordid=$aShowWordIdList[$x];
  242. echo "<input id='bold_word_{$i}' type='checkbox' checked value='{$wordid}' />";
  243. echo "<a onclick=\"dict_bold_word_select({$i})\">";
  244. echo $x.":".$x_value."<br />";
  245. echo "</a>";
  246. $i++;
  247. }
  248. echo "<input id='bold_word_count' type='hidden' value='{$countWord}' />";
  249. echo "</div>";
  250. //查找这些词出现在哪些书中
  251. echo "<div id='bold_book_list'>";
  252. $booklist=render_book_list($strQueryWordId);
  253. echo "</div>";
  254. $wordInBookCounter=0;
  255. $strFirstBookList="(";
  256. foreach($booklist as $onebook){
  257. $wordInBookCounter+=$onebook[1];
  258. $strFirstBookList.="'".$onebook[0]."',";
  259. if($wordInBookCounter>=20){
  260. break;
  261. }
  262. }
  263. $strFirstBookList=mb_substr($strFirstBookList, 0,mb_strlen($strFirstBookList,"UTF-8")-1,"UTF-8");
  264. $strFirstBookList.=")";
  265. echo "</div>";
  266. //黑体字主显示区左侧结束
  267. //黑体字主显示区右侧开始
  268. echo "<div id=\"dict_bold_right\" style='flex:7;'>";
  269. //前20条记录
  270. $time_start=microtime_float();
  271. $dictFileName=_FILE_DB_INDEX_;
  272. PDO_Connect("sqlite:$dictFileName");
  273. $query = "SELECT book,paragraph, wordindex FROM word WHERE \"wordindex\" in $strQueryWordId and book in $strFirstBookList group by book,paragraph LIMIT 0,20";
  274. $Fetch = PDO_FetchAll($query);
  275. //echo "<div>$query</div>";
  276. $queryTime=(microtime_float()-$time_start)*1000;
  277. $iFetch=count($Fetch);
  278. if($iFetch>0){
  279. $dictFileName=$_file_db_pali_text;
  280. PDO_Connect("sqlite:$dictFileName");
  281. for($i=0;$i<$iFetch;$i++){
  282. $paliwordid=$Fetch[$i]["wordindex"];
  283. $paliword=$aQueryWordList["{$paliwordid}"];
  284. $book=$Fetch[$i]["book"];
  285. $paragraph=$Fetch[$i]["paragraph"];
  286. $bookInfo = _get_book_info($book);
  287. $bookname=$bookInfo->title;
  288. $c1=$bookInfo->c1;
  289. $c2=$bookInfo->c2;
  290. $c3=$bookInfo->c3;
  291. echo "<div class='dict_word'>";
  292. echo "<div class='mean'><b>$paliword</b></div><br/>";
  293. $path_1 = $c1.">";
  294. if($c2 !== ""){
  295. $path_1=$path_1.$c2.">";
  296. }
  297. if($c3 !== ""){
  298. $path_1=$path_1.$c3.">";
  299. }
  300. $path_1=$path_1."《{$bookname}》>";
  301. $query = "select * from pali_text where \"book\" = '{$book}' and \"paragraph\" = '{$paragraph}' limit 0,1";
  302. $FetchPaliText = PDO_FetchAll($query);
  303. $countPaliText=count($FetchPaliText);
  304. if($countPaliText>0){
  305. $path="";
  306. $parent = $FetchPaliText[0]["parent"];
  307. $deep=0;
  308. $sFirstParentTitle="";
  309. //循环查找父标题 得到整条路径
  310. while($parent>-1){
  311. $query = "select * from pali_text where \"book\" = '{$book}' and \"paragraph\" = '{$parent}' limit 0,1";
  312. $FetParent = PDO_FetchAll($query);
  313. $path="{$FetParent[0]["toc"]}>{$path}";
  314. if($sFirstParentTitle==""){
  315. $sFirstParentTitle = $FetParent[0]["toc"];
  316. }
  317. $parent = $FetParent[0]["parent"];
  318. $deep++;
  319. if($deep>5){
  320. break;
  321. }
  322. }
  323. $path=$path_1.$path."para. ".$paragraph;
  324. echo "<div class='mean'>$path</div>";
  325. for($iPali=0;$iPali<$countPaliText;$iPali++){
  326. if(substr($paliword,-1)=="n"){
  327. $paliword=substr($paliword,0,-1);
  328. }
  329. $htmltext=$FetchPaliText[0]["html"];
  330. $light_text=str_replace($paliword,"<hl>{$paliword}</hl>",$htmltext);
  331. echo "<div class='wizard_par_div'>{$light_text}</div>";
  332. }
  333. //echo "<div class='wizard_par_div'>{$light_text}</div>";
  334. echo "<div class='search_para_tools'><button onclick=\"search_edit_now('{$book}','{$paragraph}','{$sFirstParentTitle}')\">Edit</button></div>";
  335. }
  336. echo "</div>";
  337. }
  338. }
  339. $queryTime=(microtime_float()-$time_start)*1000;
  340. echo "<div >搜索时间:$queryTime </div>";
  341. echo "</div>";
  342. //黑体字主显示区右侧结束
  343. echo "</div>";
  344. //黑体字主显示区结束
  345. echo "</div>";
  346. //查黑体字结束
  347. echo "<div id='real_dict_tab'>$strDictTab</div>";
  348. break;
  349. }
  350. case "update":
  351. $target=$_GET["target"];
  352. switch($target){
  353. case "bold";
  354. $wordlist=$_GET["wordlist"];
  355. $booklist=$_GET["booklist"];
  356. $aBookList=ltrim($booklist,"(");
  357. $aBookList=rtrim($aBookList,")");
  358. $aBookList=str_replace("'","",$aBookList);
  359. $aBookList=str_getcsv($aBookList);
  360. $arrBookType=json_decode(file_get_contents("../public/book_name/booktype.json"));
  361. //查找这些词出现在哪些书中
  362. $newBookList=render_book_list($wordlist,$aBookList);
  363. //前20条记录
  364. $time_start=microtime_float();
  365. $dictFileName=_FILE_DB_INDEX_;
  366. PDO_Connect("sqlite:$dictFileName");
  367. $query = "select * from word where \"wordindex\" in $wordlist and \"book\" in $booklist group by book,paragraph limit 0,20";
  368. $Fetch = PDO_FetchAll($query);
  369. //echo "<div>$query</div>";
  370. $queryTime=(microtime_float()-$time_start)*1000;
  371. echo "<div >搜索时间:$queryTime </div>";
  372. $iFetch=count($Fetch);
  373. if($iFetch>0){
  374. $dictFileName=$_file_db_pali_text;
  375. PDO_Connect("sqlite:$dictFileName");
  376. for($i=0;$i<$iFetch;$i++){
  377. $paliword=$Fetch[$i]["wordindex"];
  378. //$paliword=$wordlist["{$paliwordid}"];
  379. $book=$Fetch[$i]["book"];
  380. $bookInfo = _get_book_info($book);
  381. $bookname=$bookInfo->title;
  382. $c1=$bookInfo->c1;
  383. $c2=$bookInfo->c2;
  384. $c3=$bookInfo->c3;
  385. $paragraph=$Fetch[$i]["paragraph"];
  386. $path_1 = $c1.">";
  387. if($c2 !== ""){
  388. $path_1=$path_1.$c2.">";
  389. }
  390. if($c3 !== ""){
  391. $path_1=$path_1.$c3.">";
  392. }
  393. $path_1=$path_1."《{$bookname}》>";
  394. echo "<div class='dict_word'>";
  395. echo "<div class='dict'>《{$bookname}》 $c1 $c2 </div>";
  396. echo "<div class='mean'>$paliword</div>";
  397. $query = "select * from pali_text where \"book\" = '{$book}' and \"paragraph\" = '{$paragraph}' limit 0,20";
  398. $FetchPaliText = PDO_FetchAll($query);
  399. $countPaliText=count($FetchPaliText);
  400. if($countPaliText>0){
  401. for($iPali=0;$iPali<$countPaliText;$iPali++){
  402. $path="";
  403. $parent = $FetchPaliText[0]["parent"];
  404. $deep=0;
  405. $sFirstParentTitle="";
  406. while($parent>-1){
  407. $query = "select * from pali_text where \"book\" = '{$book}' and \"paragraph\" = '{$parent}' limit 0,1";
  408. $FetParent = PDO_FetchAll($query);
  409. if($sFirstParentTitle==""){
  410. $sFirstParentTitle = $FetParent[0]["toc"];
  411. }
  412. $path="{$FetParent[0]["toc"]}>{$path}";
  413. $parent = $FetParent[0]["parent"];
  414. $deep++;
  415. if($deep>5){
  416. break;
  417. }
  418. }
  419. $path=$path_1.$path."No. ".$paragraph;
  420. echo "<div class='mean'>$path</div>";
  421. //echo "<div class='mean'>$paliword</div>";
  422. if(substr($paliword,-1)=="n"){
  423. $paliword=substr($paliword,0,-1);
  424. }
  425. $light_text=str_replace($paliword,"<hl>{$paliword}</hl>",$FetchPaliText[$iPali]["html"]);
  426. echo "<div class='wizard_par_div'>{$light_text}</div>";
  427. echo "<div class='search_para_tools'><button onclick=\"search_edit_now('{$book}','{$paragraph}','{$sFirstParentTitle}')\">Edit</button></div>";
  428. }
  429. }
  430. echo "</div>";
  431. }
  432. }
  433. break;
  434. }
  435. break;
  436. }
  437. ?>