Skip to content

Commit 1afab11

Browse files
Updated search function
1 parent 4a99a5b commit 1afab11

2 files changed

Lines changed: 7 additions & 15 deletions

File tree

test/integration/skill_controller_search_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ defmodule SkillControllerSearchIntegrationTest do
1414
end
1515

1616
test "search partial word" do
17-
results = ElasticSearchHelper.search(@test_url, @test_index, "ru")
17+
results = ElasticSearchHelper.search(@test_url, @test_index, "title", "ru")
1818
assert results == ["Ruby"]
1919
end
2020

2121
test "search whole word" do
22-
results = ElasticSearchHelper.search(@test_url, @test_index, "css")
22+
results = ElasticSearchHelper.search(@test_url, @test_index, "title", "css")
2323
assert results == ["CSS"]
2424
end
2525

2626
test "search no matches" do
27-
results = ElasticSearchHelper.search(@test_url, @test_index, "foo")
27+
results = ElasticSearchHelper.search(@test_url, @test_index, "title", "foo")
2828
assert results == []
2929
end
3030

web/helpers/elastic_search_helper.ex

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ defmodule CodeCorps.ElasticSearchHelper do
1616
Document.index_new(url, index, type, data, query)
1717
end
1818

19-
def search(url, index, search_query) do
19+
def search(url, index, type, search_query) do
2020
data = %{
2121
query: %{
22-
match: %{ title: search_query }
22+
match: to_map(type, search_query)
2323
}
2424
}
2525

@@ -32,6 +32,8 @@ defmodule CodeCorps.ElasticSearchHelper do
3232
Enum.map(hits, fn(x) -> x["_source"]["title"] end)
3333
end
3434

35+
def to_map(foo, bar), do: %{ String.to_atom(foo) => bar}
36+
3537
defp settings_map do
3638
%{
3739
settings: %{
@@ -72,13 +74,3 @@ defmodule CodeCorps.ElasticSearchHelper do
7274
}
7375
end
7476
end
75-
76-
# elastix index.ex gets:
77-
# custom method
78-
# @doc false
79-
# def settings(elastic_url, name, data) do
80-
# elastic_url <> make_path(name)
81-
# |> HTTP.put(Poison.encode!(data))
82-
# |> process_response
83-
# end
84-

0 commit comments

Comments
 (0)