search.php 21 KB

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