search.php 22 KB

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