2
0

sentence.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. var dict_pre_searching = false;
  2. var dict_pre_search_curr_word = "";
  3. var dict_search_xml_http = null;
  4. var _key_word = "";
  5. var _page = 0;
  6. var _filter_word = new Array();
  7. var _bookId = new Array();
  8. $(document).ready(function () {
  9. paliword_search(_key_word);
  10. });
  11. function paliword_search(keyword, words = new Array(), book = new Array()) {
  12. $.getJSON(
  13. "/api/v2/sentence",
  14. {
  15. view: "fulltext",
  16. key: keyword,
  17. page: _page,
  18. },
  19. function (data) {
  20. let result = data;
  21. console.log(result.time);
  22. let html = "";
  23. html += "<div>查询到 "+result.data.rows.length+" 条结果 "+"</div>";
  24. for (const iterator of result.data.rows) {
  25. html += render_word_result(iterator);
  26. }
  27. $("#contents").html(html);
  28. }
  29. );
  30. }
  31. function highlightWords(line, word) {
  32. if (line && line.length > 0) {
  33. let output = line;
  34. for (const iterator of word) {
  35. let regex = new RegExp("(" + iterator + ")", "gi");
  36. output = output.replace(regex, "<highlight>$1</highlight>");
  37. }
  38. return output;
  39. } else {
  40. return "";
  41. }
  42. }
  43. function render_word_result(worddata) {
  44. let html = "";
  45. html += "<div class='search_result'>";
  46. html += "<div class='title'>";
  47. html +=
  48. "<a href='../article/index.php?view=sent&book=" +
  49. worddata.book_id +
  50. "&par=" +
  51. worddata.paragraph +
  52. "&start=" +
  53. worddata.word_start +
  54. "&end=" +
  55. worddata.word_end +
  56. "' target='_blank'>";
  57. html += "Open" + "</a></div>";
  58. let highlightStr;
  59. highlightStr= highlightWords(worddata.content, _key_word);
  60. html += "<div class='wizard_par_div'>" + highlightStr + "</div>";
  61. html += "<div class='path'>" + worddata.book_id + "-" + worddata.paragraph + "-" + worddata.word_start + "-" + worddata.word_end + "</div>";
  62. html += "</div>";
  63. return html;
  64. }
  65. function gotoPage(index) {
  66. _page = index;
  67. paliword_search(_key_word, _filter_word, _bookId);
  68. }
  69. function dict_input_change(obj) {
  70. search_pre_search(obj.value);
  71. }
  72. function search_input_onfocus() {
  73. if ($("#dict_ref_search_input").val() == "") {
  74. //search_show_history();
  75. }
  76. }
  77. function search_input_keyup(e, obj) {
  78. var keynum;
  79. var keychar;
  80. var numcheck;
  81. if (window.event) {
  82. // IE
  83. keynum = e.keyCode;
  84. } else if (e.which) {
  85. // Netscape/Firefox/Opera
  86. keynum = e.which;
  87. }
  88. var keychar = String.fromCharCode(keynum);
  89. if (keynum == 13) {
  90. //search_search(obj.value);
  91. window.location.assign("../search/sentence.php?key=" + obj.value);
  92. }
  93. }