search.php 16 KB

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