Current section

39 Versions

Jump to

Compare versions

3 files changed
+12 additions
-16 deletions
  @@ -54,4 +54,4 @@
54 54 {<<"optional">>,false},
55 55 {<<"repository">>,<<"hexpm">>},
56 56 {<<"requirement">>,<<"~> 1.0">>}]]}.
57 - {<<"version">>,<<"1.2.2">>}.
57 + {<<"version">>,<<"1.2.3">>}.
  @@ -122,25 +122,21 @@ defmodule ExlasticSearch.Query do
122 122 Converts a query to a function score query and adds the given `script` for scoring
123 123 """
124 124 @spec script_score(t, binary) :: t
125 - def script_score(%__MODULE__{} = q, script, opts \\ []) do
126 - %{q | type: :function_score, options: %{script: opts |> Enum.into(%{source: script})}}
125 + def script_score(%__MODULE__{options: options} = q, script, opts \\ []) do
126 + script = Enum.into(opts, %{source: script})
127 + %{q | type: :function_score, options: Map.put(options, :script, script)}
127 128 end
128 129
129 130 @doc """
130 - Converts a `Query` struct into an ES compliant bool compound query
131 + Converts a `Query` struct into an ES compliant bool or function score compound query
131 132 """
132 133 @spec realize(t) :: map
133 - def realize(%__MODULE__{type: :function_score, options: %{script: script}} = query) do
134 - %{
135 - query: %{
136 - function_score: %{
137 - query: query_clause(%{query | type: :bool}),
138 - script_score: %{
139 - script: script
140 - }
141 - }
142 - }
143 - }
134 + def realize(%__MODULE__{type: :function_score, options: %{script: script} = opts} = query) do
135 + query =
136 + realize(%{query | type: :bool, options: Map.delete(opts, :script)})
137 + |> Map.put(:script_score, %{script: script})
138 +
139 + %{query: %{function_score: query}}
144 140 end
145 141 def realize(%__MODULE__{type: :bool} = query),
146 142 do: %{query: query_clause(query)} |> add_sort(query)
  @@ -1,7 +1,7 @@
1 1 defmodule Exlasticsearch.MixProject do
2 2 use Mix.Project
3 3
4 - @version "1.2.2"
4 + @version "1.2.3"
5 5
6 6 def project do
7 7 [