word_list.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. //全文搜索
  3. require_once '../path.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. define("word_limit", 12); //最大单词数量
  11. $resulte = array();
  12. if (isset($_GET["word"])) {
  13. $word = mb_strtolower($_GET["word"], 'UTF-8');
  14. } else {
  15. echo json_encode($resulte, JSON_UNESCAPED_UNICODE);
  16. exit;
  17. }
  18. _load_book_index();
  19. $count_return = 0;
  20. $dict_list = array();
  21. //计算某词在三藏中出现的次数
  22. $arrRealWordList = countWordInPali($word, true, word_limit);
  23. $countWord = count($arrRealWordList);
  24. if ($countWord == 0) {
  25. echo "<p>没有查到。可能是拼写有问题。</p>";
  26. exit;
  27. }
  28. $strQueryWordId = "("; //实际出现的单词id查询字串
  29. $aQueryWordList = array(); //id 为键 拼写为值的数组
  30. $aShowWordList = array(); //拼写为键 个数为值的数组
  31. $aShowWordIdList = array(); //拼写为键 值Id的数组
  32. for ($i = 0; $i < $countWord; $i++) {
  33. $value = $arrRealWordList[$i];
  34. $strQueryWordId .= "'{$value["id"]}',";
  35. $aQueryWordList[$value["id"]] = $value["word"];
  36. $aShowWordList[$value["word"]] = $value["count"];
  37. $aShowWordIdList[$value["word"]] = $value["id"];
  38. }
  39. $strQueryWordId = mb_substr($strQueryWordId, 0, mb_strlen($strQueryWordId, "UTF-8") - 1, "UTF-8");
  40. $strQueryWordId .= ")";
  41. //显示单词列表
  42. arsort($aShowWordList);
  43. $i = 0;
  44. $wordlist = array();
  45. $wordlist_index = array();
  46. $sutta = array();
  47. $vinaya = array();
  48. $abhidhamma = array();
  49. $anna = array();
  50. foreach ($aShowWordList as $x => $x_value) {
  51. $wordid = $aShowWordIdList[$x];
  52. $wordlist[] = $x;
  53. $wordlist_index[$x] = $i;
  54. $sutta[] = 0;
  55. $vinaya[] = 0;
  56. $abhidhamma[] = 0;
  57. $anna[] = 0;
  58. //echo $x.":".$x_value."<br />";
  59. $i++;
  60. }
  61. $resulte["wordlist"] = $wordlist;
  62. //查找这些词出现在哪些书中
  63. $arrBookType = json_decode(file_get_contents("../public/book_name/booktype.json"));
  64. PDO_Connect(_FILE_DB_BOOK_WORD_);
  65. if (isset($booklist)) {
  66. foreach ($booklist as $oneBook) {
  67. $aInputBook["{$oneBook}"] = 1;
  68. }
  69. }
  70. $query = "SELECT book, wordindex,count from "._TABLE_BOOK_WORD_." where \"wordindex\" in $strQueryWordId ";
  71. $Fetch = PDO_FetchAll($query);
  72. $iFetch = count($Fetch);
  73. $newBookList = array();
  74. $worddata = array();
  75. if ($iFetch > 0) {
  76. for ($i = 0; $i < $iFetch; $i++) {
  77. $book = $Fetch[$i]["book"];
  78. array_push($newBookList, array($book, $sum));
  79. $t1 = $arrBookType[$book - 1]->c1;
  80. $t2 = $arrBookType[$book - 1]->c2;
  81. switch ($t1) {
  82. case "sutta":
  83. $x = $aQueryWordList[$Fetch[$i]["wordindex"]];
  84. $sutta[$wordlist_index[$x]] += $Fetch[$i]["count"];
  85. break;
  86. case "vinaya":
  87. $x = $aQueryWordList[$Fetch[$i]["wordindex"]];
  88. $vinaya[$wordlist_index[$x]] += $Fetch[$i]["count"];
  89. break;
  90. case "abhidhamma":
  91. $x = $aQueryWordList[$Fetch[$i]["wordindex"]];
  92. $abhidhamma[$wordlist_index[$x]] += $Fetch[$i]["count"];
  93. break;
  94. case "anna":
  95. $x = $aQueryWordList[$Fetch[$i]["wordindex"]];
  96. $anna[$wordlist_index[$x]] += $Fetch[$i]["count"];
  97. break;
  98. }
  99. }
  100. }
  101. $worddata[] = array("name" => "anna", "data" => $anna);
  102. $worddata[] = array("name" => "abhidhamma", "data" => $abhidhamma);
  103. $worddata[] = array("name" => "vinaya", "data" => $vinaya);
  104. $worddata[] = array("name" => "sutta", "data" => $sutta);
  105. $resulte["data"] = $worddata;
  106. echo json_encode($resulte, JSON_UNESCAPED_UNICODE);