paliword_search.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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. require_once "../search/word_function.php";
  10. require_once "../ucenter/active.php";
  11. _load_book_index();
  12. $op = $_GET["op"];
  13. $word = mb_strtolower($_GET["word"], 'UTF-8');
  14. //$word=$_GET["word"];
  15. $org_word = $word;
  16. $arrWordList = str_getcsv($word, " ");
  17. $count_return = 0;
  18. $dict_list = array();
  19. global $PDO;
  20. function microtime_float()
  21. {
  22. list($usec, $sec) = explode(" ", microtime());
  23. return ((float) $usec + (float) $sec);
  24. }
  25. switch ($op) {
  26. case "pre": //预查询
  27. {
  28. $time_start = microtime_float();
  29. $searching = $arrWordList[count($arrWordList) - 1];
  30. PDO_Connect(_FILE_DB_WORD_INDEX_,_DB_USERNAME_,_DB_PASSWORD_);
  31. if (count($arrWordList) > 1) {
  32. echo "<div>";
  33. foreach ($arrWordList as $oneword) {
  34. echo $oneword . "+";
  35. }
  36. echo "</div>";
  37. }
  38. $query = "SELECT word,count from "._TABLE_WORD_INDEX_." where \"word_en\" like " . $PDO->quote($searching . '%') . " OR \"word\" like " . $PDO->quote($searching . '%') . " limit 20";
  39. $Fetch = PDO_FetchAll($query);
  40. $queryTime = (microtime_float() - $time_start) * 1000;
  41. $iFetch = count($Fetch);
  42. if ($iFetch > 0) {
  43. for ($i = 0; $i < $iFetch; $i++) {
  44. $word = $Fetch[$i]["word"];
  45. $count = $Fetch[$i]["count"];
  46. echo "<a href='paliword.php?key={$word}'>$word-$count</a>";
  47. }
  48. }
  49. break;
  50. }
  51. case "search":
  52. {
  53. if (count($arrWordList) > 1) {
  54. $strQuery = "";
  55. foreach ($arrWordList as $oneword) {
  56. $strQuery .= "\"text\" like \"% {$oneword} %\" AND";
  57. }
  58. $strQuery = substr($strQuery, 0, -3);
  59. PDO_Connect(_FILE_DB_PALITEXT_);
  60. $query = "SELECT book,paragraph, html FROM "._TABLE_PALI_TEXT_." WHERE {$strQuery} LIMIT 20";
  61. $Fetch = PDO_FetchAll($query);
  62. echo "<div>$query</div>";
  63. $iFetch = count($Fetch);
  64. foreach ($Fetch as $row) {
  65. $html = $row["html"];
  66. foreach ($arrWordList as $oneword) {
  67. $html = str_replace($oneword, "<hl>{$oneword}</hl>", $html);
  68. }
  69. echo "<div class='dict_word'>{$html}</div>";
  70. }
  71. return;
  72. }
  73. //计算某词在三藏中出现的次数
  74. $time_start = microtime_float();
  75. $arrRealWordList = countWordInPali($word);
  76. $countWord = count($arrRealWordList);
  77. if ($countWord == 0) {
  78. echo "<p>没有查到。可能是拼写有问题。</p>";
  79. exit;
  80. }
  81. $strQueryWordId = "("; //实际出现的单词id查询字串
  82. $aQueryWordList = array(); //id 为键 拼写为值的数组
  83. $aShowWordList = array(); //拼写为键 个数为值的数组
  84. $aShowWordIdList = array(); //拼写为键 值Id的数组
  85. $arrQueryId=array();
  86. for ($i = 0; $i < $countWord; $i++) {
  87. $value = $arrRealWordList[$i];
  88. $strQueryWordId .= "'{$value["id"]}',";
  89. $arrQueryId[] = $value["id"];
  90. $aQueryWordList["{$value["id"]}"] = $value["word"];
  91. $aShowWordList[$value["word"]] = $value["count"];
  92. $aShowWordIdList[$value["word"]] = $value["id"];
  93. }
  94. $strQueryWordId = mb_substr($strQueryWordId, 0, mb_strlen($strQueryWordId, "UTF-8") - 1, "UTF-8");
  95. $strQueryWordId .= ")";
  96. $queryTime = (microtime_float() - $time_start) * 1000;
  97. echo "<div id=\"dict_bold\">";
  98. //主显示区开始
  99. echo "<div style='display:flex;'>";
  100. //主显示区左侧开始
  101. echo "<div style='flex:3;max-width: 17em;min-width: 10em;border-right: 1px solid var(--border-line-color);text-align: right;padding-right: 1em;'>";
  102. echo "<button onclick=\"dict_update_bold(0)\">筛选</button>";
  103. echo "<div>共{$countWord}单词符合</div>";
  104. //显示单词列表
  105. echo "<div>";
  106. echo "<input id='bold_all_word' type='checkbox' checked='true' value='' onclick=\"dict_bold_word_all_select()\"/>全选<br />";
  107. arsort($aShowWordList);
  108. $i = 0;
  109. foreach ($aShowWordList as $x => $x_value) {
  110. $wordid = $aShowWordIdList[$x];
  111. echo "<a onclick=\"dict_bold_word_select({$i})\">";
  112. echo $x . ":" . $x_value;
  113. echo "</a>";
  114. echo "<input id='bold_word_{$i}' type='checkbox' checked value='{$wordid}' />";
  115. echo "<br />";
  116. $i++;
  117. }
  118. echo "<input id='bold_word_count' type='hidden' value='{$countWord}' />";
  119. echo "</div>";
  120. //查找这些词出现在哪些书中
  121. echo "<div id='bold_book_list'>";
  122. $booklist = render_book_list($strQueryWordId);
  123. echo "</div>";
  124. $wordInBookCounter = 0;
  125. $strFirstBookList = "(";
  126. foreach ($booklist as $onebook) {
  127. $wordInBookCounter += $onebook[1];
  128. $strFirstBookList .= "'" . $onebook[0] . "',";
  129. if ($wordInBookCounter >= 20) {
  130. break;
  131. }
  132. }
  133. $strFirstBookList = mb_substr($strFirstBookList, 0, mb_strlen($strFirstBookList, "UTF-8") - 1, "UTF-8");
  134. $strFirstBookList .= ")";
  135. echo "</div>";
  136. //黑体字主显示区左侧结束
  137. //黑体字主显示区右侧开始
  138. echo "<div id=\"dict_bold_right\" style='flex:7;padding-left:1em;'>";
  139. //前20条记录
  140. $time_start = microtime_float();
  141. PDO_Connect(_FILE_DB_PALI_INDEX_);
  142. //TODO 在没有查到书的时候$strFirstBookList为 ( 需要修改
  143. $query = "SELECT book,paragraph FROM "._TABLE_WORD_." WHERE \"wordindex\" in $strQueryWordId and book in $strFirstBookList group by book,paragraph LIMIT 20";
  144. $Fetch = PDO_FetchAll($query);
  145. //echo "<div>$query</div>";
  146. $queryTime = (microtime_float() - $time_start) * 1000;
  147. $iFetch = count($Fetch);
  148. if ($iFetch > 0) {
  149. PDO_Connect(_FILE_DB_PALITEXT_);
  150. for ($i = 0; $i < $iFetch; $i++) {
  151. $paliword = array();
  152. foreach ($arrQueryId as $value) {
  153. # code...
  154. $paliword[] = $aQueryWordList["{$value}"];
  155. }
  156. $book = $Fetch[$i]["book"];
  157. $paragraph = $Fetch[$i]["paragraph"];
  158. $bookInfo = _get_book_info($book);
  159. $bookname = $bookInfo->title;
  160. $c1 = $bookInfo->c1;
  161. $c2 = $bookInfo->c2;
  162. $c3 = $bookInfo->c3;
  163. echo "<div class='dict_word' style='margin: 10px 0;padding: 5px;border-bottom: 1px solid var(--border-line-color);'>";
  164. echo "<div style='font-size: 130%;font-weight: 700;'>".$paliword[0]."</div>";
  165. //echo "<div class='dict_word'>";
  166. $path_1 = $c1 . ">";
  167. if ($c2 !== "") {
  168. $path_1 = $path_1 . $c2 . ">";
  169. }
  170. if ($c3 !== "") {
  171. $path_1 = $path_1 . $c3 . ">";
  172. }
  173. $path_1 = $path_1 . "《{$bookname}》>";
  174. $query = "SELECT * from "._TABLE_PALI_TEXT_." where book = ? and paragraph = ? limit 1";
  175. $FetchPaliText = PDO_FetchAll($query,array($book,$paragraph));
  176. $countPaliText = count($FetchPaliText);
  177. if ($countPaliText > 0) {
  178. $path = "";
  179. $parent = $FetchPaliText[0]["parent"];
  180. $deep = 0;
  181. $sFirstParentTitle = "";
  182. //循环查找父标题 得到整条路径
  183. while ($parent > -1) {
  184. $query = "SELECT * from "._TABLE_PALI_TEXT_." where book = ? and paragraph = ? limit 1";
  185. $FetParent = PDO_FetchAll($query,array($book,$parent));
  186. if($FetParent){
  187. $path = "{$FetParent[0]["toc"]}>{$path}";
  188. if ($sFirstParentTitle == "") {
  189. $sFirstParentTitle = $FetParent[0]["toc"];
  190. }
  191. $parent = $FetParent[0]["parent"];
  192. $deep++;
  193. if ($deep > 5) {
  194. break;
  195. }
  196. }else{
  197. break;
  198. }
  199. }
  200. $path = $path_1 . $path . "para. " . $paragraph;
  201. echo "<div class='mean' style='font-size:120%'><a href='../reader/?view=para&book={$book}&para={$paragraph}&display=para' target='_blank'>$path</a></div>";
  202. for ($iPali = 0; $iPali < $countPaliText; $iPali++) {
  203. foreach ($paliword as $qWord) {
  204. # code...
  205. if (substr($qWord, -1) == "n") {
  206. $qWord = substr($qWord, 0, -1);
  207. }
  208. $htmltext = $FetchPaliText[0]["html"];
  209. $light_text = $htmltext;
  210. $light_text = str_replace($qWord, "<hl>{$qWord}</hl>", $light_text);
  211. }
  212. echo "<div class='wizard_par_div'>{$light_text}</div>";
  213. }
  214. //echo "<div class='wizard_par_div'>{$light_text}</div>";
  215. echo "<div class='search_para_tools'></div>";
  216. }
  217. echo "</div>";
  218. }
  219. }
  220. $queryTime = (microtime_float() - $time_start) * 1000;
  221. echo "<div >搜索时间:$queryTime </div>";
  222. echo "</div>";
  223. //黑体字主显示区右侧结束
  224. echo "<div id=\"dict_bold_review\" style='flex:2;'>";
  225. echo "</div>";
  226. echo "</div>";
  227. //黑体字主显示区结束
  228. echo "</div>";
  229. //查黑体字结束
  230. echo "<div id='real_dict_tab'></div>";
  231. break;
  232. }
  233. case "update":
  234. $target = $_GET["target"];
  235. switch ($target) {
  236. case "bold";
  237. $wordlist = $_GET["wordlist"];
  238. $booklist = $_GET["booklist"];
  239. $aBookList = ltrim($booklist, "(");
  240. $aBookList = rtrim($aBookList, ")");
  241. $aBookList = str_replace("'", "", $aBookList);
  242. $aBookList = str_getcsv($aBookList);
  243. $arrBookType = json_decode(file_get_contents("../public/book_name/booktype.json"));
  244. //查找这些词出现在哪些书中
  245. $newBookList = render_book_list($wordlist, $aBookList);
  246. //前20条记录
  247. $time_start = microtime_float();
  248. PDO_Connect(_FILE_DB_PALI_INDEX_);
  249. $query = "SELECT * from "._TABLE_WORD_." where \"wordindex\" in $wordlist and \"book\" in $booklist group by book,paragraph limit 20";
  250. $Fetch = PDO_FetchAll($query);
  251. $queryTime = (microtime_float() - $time_start) * 1000;
  252. //echo "<div >搜索时间:$queryTime </div>";
  253. if ($booklist == "()") {
  254. echo "<div >请选择书名</div>";
  255. }
  256. $iFetch = count($Fetch);
  257. if ($iFetch > 0) {
  258. PDO_Connect(_FILE_DB_PALITEXT_);
  259. for ($i = 0; $i < $iFetch; $i++) {
  260. $paliword = $Fetch[$i]["wordindex"];
  261. //$paliword=$wordlist["{$paliwordid}"];
  262. $book = $Fetch[$i]["book"];
  263. $bookInfo = _get_book_info($book);
  264. $bookname = $bookInfo->title;
  265. $c1 = $bookInfo->c1;
  266. $c2 = $bookInfo->c2;
  267. $c3 = $bookInfo->c3;
  268. $paragraph = $Fetch[$i]["paragraph"];
  269. $path_1 = $c1 . ">";
  270. if ($c2 !== "") {
  271. $path_1 = $path_1 . $c2 . ">";
  272. }
  273. if ($c3 !== "") {
  274. $path_1 = $path_1 . $c3 . ">";
  275. }
  276. $path_1 = $path_1 . "《{$bookname}》>";
  277. echo "<div class='dict_word'>";
  278. echo "<div class='book' ><span style='font-size:110%;font-weight:700;'>《{$bookname}》</span> <tag>$c1</tag> <tag>$c2</tag> </div>";
  279. echo "<div class='mean'>$paliword</div>";
  280. $query = "SELECT * from "._TABLE_PALI_TEXT_." where book = ? and paragraph = ? limit 20";
  281. $FetchPaliText = PDO_FetchAll($query,array($book,$paragraph));
  282. $countPaliText = count($FetchPaliText);
  283. if ($countPaliText > 0) {
  284. for ($iPali = 0; $iPali < $countPaliText; $iPali++) {
  285. $path = "";
  286. $parent = $FetchPaliText[0]["parent"];
  287. $deep = 0;
  288. $sFirstParentTitle = "";
  289. while ($parent > -1) {
  290. $query = "select * from "._TABLE_PALI_TEXT_." where book = ? and paragraph = ? limit 1";
  291. $FetParent = PDO_FetchAll($query,array($book,$parent));
  292. if ($sFirstParentTitle == "") {
  293. $sFirstParentTitle = $FetParent[0]["toc"];
  294. }
  295. $path = "{$FetParent[0]["toc"]}>{$path}";
  296. $parent = $FetParent[0]["parent"];
  297. $deep++;
  298. if ($deep > 5) {
  299. break;
  300. }
  301. }
  302. $path = $path . "No. " . $paragraph;
  303. echo "<div class='mean' style='font-size:120%;'><a href='../reader/?view=para&book={$book}&para={$paragraph}&display=sent#para_{$paragraph}' target='_blank' >$path</a></div>";
  304. if (substr($paliword, -1) == "n") {
  305. $paliword = substr($paliword, 0, -1);
  306. }
  307. $light_text = str_replace($paliword, "<hl>{$paliword}</hl>", $FetchPaliText[$iPali]["html"]);
  308. echo "<div class='wizard_par_div'>{$light_text}</div>";
  309. echo "<div class='search_para_tools'></div>";
  310. }
  311. }
  312. echo "</div>";
  313. }
  314. }
  315. break;
  316. }
  317. break;
  318. }