Guest User

Untitled

a guest
Jan 18th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. basic_query = %{
  2. "version" => true,
  3. "fields" => [
  4. "title",
  5. "type",
  6. "tags",
  7. "searchable",
  8. "searchable_from",
  9. "searchable_until",
  10. "created_at",
  11. "updated_at",
  12. ],
  13. }
  14. default_searchables_cond = %{
  15. searchable: %{
  16. "term" => %{"searchable" => true},
  17. },
  18. searchable_from: %{
  19. "range" => %{
  20. "searchable_from" => %{"lte" => "now"}
  21. }
  22. },
  23. searchable_until: %{
  24. "range" => %{
  25. "searchable_until" => %{"gte" => "now"}
  26. }
  27. },
  28. }
  29. default_boundary_chars_cond = "。.!!??  \n\t"
  30.  
  31.  
  32. content_id = 1
  33. body = %{
  34. filter: [
  35. %{term: %{tags: "category_id0"}},
  36. %{term: %{tags: "category_id1"}}
  37. ],
  38. query: [
  39. %{match: %{main_text: "雨"}},
  40. %{match: %{main_text: "雷"}}
  41. ],
  42. highlight: %{
  43. fields: %{
  44. main_text: %{}
  45. }
  46. },
  47. }
  48.  
  49.  
  50. id_filter_conds = [
  51. %{
  52. "term" => %{"_id" => content_id}
  53. }
  54. ]
  55.  
  56. searchables_filter_conds = default_searchables_cond
  57. |> Map.values
  58.  
  59. query = %{
  60. "query" => %{
  61. "bool" => %{
  62. "filter" => id_filter_conds ++ searchables_filter_conds ++ body.filter,
  63. "must" => body.query,
  64. }
  65. }
  66. }
  67.  
  68. basic_main_text_cond = %{
  69. "number_of_fragments" => 50,
  70. "boundary_chars" => default_boundary_chars_cond,
  71. }
  72.  
  73. highlight = %{
  74. "highlight" => %{
  75. "type" => "range",
  76. "encoder" => "html",
  77. "fields" => %{"main_text" => Map.merge(basic_main_text_cond, body.highlight.fields.main_text)}
  78. }
  79. }
  80.  
  81. query = basic_query
  82. |> Map.merge(query)
  83. |> Map.merge(highlight)
  84.  
  85.  
  86. IO.inspect query
Add Comment
Please, Sign In to add comment