Skip to content

Commit 066900b

Browse files
Moved some code and a couple small refactors of the helper module
1 parent f85ac20 commit 066900b

2 files changed

Lines changed: 28 additions & 33 deletions

File tree

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,50 @@
11
defmodule SkillControllerSearchIntegrationTest do
22
use ExUnit.Case, async: true
33
alias CodeCorps.ElasticSearchHelper
4+
alias Elastix.Document
45

56
@test_url Application.get_env(:code_corps, :elasticsearch_url)
67
@test_index Application.get_env(:code_corps, :elasticsearch_index)
8+
@type_value "title"
79

810
setup do
9-
Elastix.Index.delete(Application.get_env(:code_corps, :elasticsearch_url),
10-
Application.get_env(:code_corps, :elasticsearch_index))
11+
ElasticSearchHelper.delete(@test_url, @test_index)
12+
ElasticSearchHelper.create_index(@test_url, @test_index, @type_value)
13+
init()
1114
:ok
1215
end
1316

1417
test "search partial word" do
15-
results = ElasticSearchHelper.search("ru")
18+
results = ElasticSearchHelper.search(@test_url, @test_index, "ru")
1619
assert results == ["Ruby"]
1720
end
1821

1922
test "search whole word" do
20-
results = ElasticSearchHelper.search("css")
23+
results = ElasticSearchHelper.search(@test_url, @test_index, "css")
2124
assert results == ["CSS"]
2225
end
2326

2427
test "search no matches" do
25-
results = ElasticSearchHelper.search("foo")
28+
results = ElasticSearchHelper.search(@test_url, @test_index, "foo")
2629
assert results == []
2730
end
2831

32+
def init do
33+
data = %{
34+
title: "Elixir"
35+
}
36+
Document.index @test_url, @test_index, @type_value, 1, data, [refresh: true]
37+
data = %{
38+
title: "Ruby"
39+
}
40+
Document.index @test_url, @test_index, @type_value, 2, data, [refresh: true]
41+
data = %{
42+
title: "Rails"
43+
}
44+
Document.index @test_url, @test_index, @type_value, 3, data, [refresh: true]
45+
data = %{
46+
title: "CSS"
47+
}
48+
Document.index @test_url, @test_index, @type_value, 4, data, [refresh: true]
49+
end
2950
end

web/helpers/elastic_search_helper.ex

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
defmodule CodeCorps.ElasticSearchHelper do
22
alias Elastix.Search
33
alias Elastix.Index
4-
alias Elastix.Document
54

65
@test_url Application.get_env(:code_corps, :elasticsearch_url)
76
@test_index Application.get_env(:code_corps, :elasticsearch_index)
@@ -15,39 +14,14 @@ defmodule CodeCorps.ElasticSearchHelper do
1514
Index.settings(url, "#{index}/_mapping/#{type}", field_filter)
1615
end
1716

18-
def init do
19-
Index.settings(@test_url, @test_index, settings_map)
20-
Index.settings(@test_url, "skills/_mapping/title", field_filter)
21-
22-
data = %{
23-
title: "CSS"
24-
}
25-
Document.index @test_url, @test_index, "title", 1, data, [refresh: true]
26-
data = %{
27-
title: "Elixir"
28-
}
29-
Document.index @test_url, @test_index, "title", 2, data, [refresh: true]
30-
data = %{
31-
title: "Ruby"
32-
}
33-
Document.index @test_url, @test_index, "title", 3, data, [refresh: true]
34-
35-
data = %{
36-
title: "Rails"
37-
}
38-
Document.index @test_url, @test_index, "title", 4, data, [refresh: true]
39-
end
40-
41-
def search(search_query) do
42-
init
43-
17+
def search(url, index, search_query) do
4418
data = %{
4519
query: %{
4620
match: %{ title: search_query }
4721
}
4822
}
4923

50-
response = Search.search @test_url, @test_index, [], data
24+
response = Search.search url, index, [], data
5125

5226
#response.status_code == 200 do
5327
#count = response.body["hits"]["total"]

0 commit comments

Comments
 (0)