Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment