title_search.php 16 KB

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