Skip to content

Instantly share code, notes, and snippets.

@elixirplayground
Created January 10, 2018 04:08
Show Gist options
  • Save elixirplayground/072109ad8851ae9c3669327aae2824cf to your computer and use it in GitHub Desktop.
Save elixirplayground/072109ad8851ae9c3669327aae2824cf to your computer and use it in GitHub Desktop.
elixirplayground.com code share
basic_query = %{
"version" => true,
"fields" => [
"title",
"type",
"tags",
"searchable",
"searchable_from",
"searchable_until",
"created_at",
"updated_at",
],
}
default_searchables_cond = %{
searchable: %{
"term" => %{"searchable" => true},
},
searchable_from: %{
"range" => %{
"searchable_from" => %{"lte" => "now"}
}
},
searchable_until: %{
"range" => %{
"searchable_until" => %{"gte" => "now"}
}
},
}
default_boundary_chars_cond = "。.!!??  \n\t"
content_id = 1
body = %{
filter: [
%{term: %{tags: "category_id0"}},
%{term: %{tags: "category_id1"}}
],
query: [
%{match: %{main_text: "雨"}},
%{match: %{main_text: "雷"}}
],
highlight: %{
fields: %{
main_text: %{}
}
},
}
id_filter_conds = [
%{
"term" => %{"_id" => content_id}
}
]
searchables_filter_conds = default_searchables_cond
|> Map.values
query = %{
"query" => %{
"bool" => %{
"filter" => id_filter_conds ++ searchables_filter_conds ++ body.filter,
"must" => body.query,
}
}
}
basic_main_text_cond = %{
"number_of_fragments" => 50,
"boundary_chars" => default_boundary_chars_cond,
}
highlight = %{
"highlight" => %{
"type" => "range",
"encoder" => "html",
"fields" => %{"main_text" => Map.merge(basic_main_text_cond, body.highlight.fields.main_text)}
}
}
query = basic_query
|> Map.merge(query)
|> Map.merge(highlight)
IO.inspect query
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment