word_list.php 4.0 KB

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