eagle_search 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/eagle_search/field.rb +15 -0
- data/lib/eagle_search/index.rb +47 -1
- data/lib/eagle_search/interpreter.rb +24 -0
- data/lib/eagle_search/interpreter/query.rb +28 -4
- data/lib/eagle_search/response.rb +3 -0
- data/lib/eagle_search/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82100c3686ba2e322eab5ac86fb4a23c873461bf
|
4
|
+
data.tar.gz: 88ab75d5c91d735f651f3e60ba862a3e71001ffa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55d7926ec810c5139670e3bc9ea83b11e1fbae69ff42a653b6e0513c5cbeb751f10df6cf47e7bba79c03dad240eaa4118620c68b8b8677481b9998db3ca22020
|
7
|
+
data.tar.gz: a78979c0e9f6c4bd2afa383e47e87e6dd978c12cb15252c0a4f3d5f24cb5116406083bd94644127507c030b6b707c273a1c3ae24c26fe0a02c6a85df090a6ec9
|
data/lib/eagle_search/field.rb
CHANGED
@@ -18,12 +18,27 @@ module EagleSearch
|
|
18
18
|
else
|
19
19
|
mapping[:index] = "analyzed"
|
20
20
|
mapping[:analyzer] = index_settings[:language] || "english"
|
21
|
+
|
21
22
|
mapping[:fields] = {
|
22
23
|
shingle: {
|
23
24
|
type: "string",
|
24
25
|
analyzer: "eagle_search_shingle_analyzer"
|
26
|
+
},
|
27
|
+
autocomplete: {
|
28
|
+
type: "string",
|
29
|
+
index_analyzer: "eagle_search_autocomplete_analyzer",
|
30
|
+
search_analyzer: index_settings[:language] || "english"
|
25
31
|
}
|
26
32
|
}
|
33
|
+
|
34
|
+
mapping[:fields].merge!(
|
35
|
+
{
|
36
|
+
synonym: {
|
37
|
+
type: "string",
|
38
|
+
analyzer: "eagle_search_synonym_analyzer"
|
39
|
+
}
|
40
|
+
}
|
41
|
+
) if @index.has_synonyms?
|
27
42
|
end
|
28
43
|
end
|
29
44
|
end
|
data/lib/eagle_search/index.rb
CHANGED
@@ -78,6 +78,10 @@ module EagleSearch
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
+
def has_synonyms?
|
82
|
+
@settings[:synonyms]
|
83
|
+
end
|
84
|
+
|
81
85
|
private
|
82
86
|
def body
|
83
87
|
body = {
|
@@ -92,13 +96,18 @@ module EagleSearch
|
|
92
96
|
end
|
93
97
|
|
94
98
|
def analysis_settings
|
95
|
-
{
|
99
|
+
default_analysis = {
|
96
100
|
filter: {
|
97
101
|
eagle_search_shingle_filter: {
|
98
102
|
type: "shingle",
|
99
103
|
min_shingle_size: 2,
|
100
104
|
max_shingle_size: 2,
|
101
105
|
output_unigrams: false
|
106
|
+
},
|
107
|
+
eagle_search_autocomplete_filter: {
|
108
|
+
type: "edge_ngram",
|
109
|
+
min_gram: 1,
|
110
|
+
max_gram: 20
|
102
111
|
}
|
103
112
|
},
|
104
113
|
analyzer: {
|
@@ -109,9 +118,46 @@ module EagleSearch
|
|
109
118
|
"lowercase",
|
110
119
|
"eagle_search_shingle_filter"
|
111
120
|
]
|
121
|
+
},
|
122
|
+
eagle_search_autocomplete_analyzer: {
|
123
|
+
tokenizer: "standard",
|
124
|
+
filter: ["lowercase", "eagle_search_autocomplete_filter"]
|
112
125
|
}
|
113
126
|
}
|
114
127
|
}
|
128
|
+
merge_synonyms!(default_analysis)
|
129
|
+
default_analysis
|
130
|
+
end
|
131
|
+
|
132
|
+
def merge_synonyms!(default_analysis)
|
133
|
+
if has_synonyms?
|
134
|
+
default_analysis[:filter]["eagle_search_synonym_filter"] = {}
|
135
|
+
default_analysis[:analyzer].merge!(
|
136
|
+
{
|
137
|
+
eagle_search_synonym_analyzer: {
|
138
|
+
tokenizer: "standard",
|
139
|
+
filter: ["lowercase", "eagle_search_synonym_filter"]
|
140
|
+
}
|
141
|
+
}
|
142
|
+
)
|
143
|
+
|
144
|
+
default_analysis[:filter]["eagle_search_synonym_filter"].merge!(
|
145
|
+
synonym_payload(@settings[:synonyms])
|
146
|
+
)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def synonym_payload(synonyms)
|
151
|
+
if synonyms.is_a?(Array)
|
152
|
+
{
|
153
|
+
type: "synonym",
|
154
|
+
synonyms: synonyms
|
155
|
+
}
|
156
|
+
else
|
157
|
+
{
|
158
|
+
type: "synonym"
|
159
|
+
}.merge(synonyms)
|
160
|
+
end
|
115
161
|
end
|
116
162
|
|
117
163
|
def klass
|
@@ -32,9 +32,33 @@ module EagleSearch
|
|
32
32
|
#size
|
33
33
|
payload.merge!({ size: @options[:per_page] }) if @options[:per_page]
|
34
34
|
|
35
|
+
#highlight
|
36
|
+
if @options[:highlight] && @options[:highlight][:fields]
|
37
|
+
highlight = {
|
38
|
+
fields: {}
|
39
|
+
}
|
40
|
+
@options[:highlight][:fields].each do |field|
|
41
|
+
highlight[:fields][field] = {}
|
42
|
+
end
|
43
|
+
|
44
|
+
if @options[:highlight][:tags]
|
45
|
+
highlight[:pre_tags] = @options[:highlight][:tags]
|
46
|
+
highlight[:post_tags] = @options[:highlight][:tags].map { |tag| tag.gsub(/</, "</")}
|
47
|
+
end
|
48
|
+
|
49
|
+
payload.merge!(highlight: highlight)
|
50
|
+
end
|
51
|
+
|
35
52
|
payload
|
36
53
|
end
|
37
54
|
|
55
|
+
{
|
56
|
+
highlight: {
|
57
|
+
fields: [:a, :b, :c],
|
58
|
+
tags: ["<xpto>"]
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
38
62
|
private
|
39
63
|
def query_payload
|
40
64
|
if @options[:custom_query]
|
@@ -64,8 +64,32 @@ module EagleSearch
|
|
64
64
|
match_queries << {
|
65
65
|
match: {
|
66
66
|
"#{ field_name }.shingle" => {
|
67
|
+
query: @query
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
match_queries << {
|
73
|
+
match: {
|
74
|
+
"#{ field_name }.synonym" => {
|
75
|
+
query: @query
|
76
|
+
}
|
77
|
+
}
|
78
|
+
} if @index.has_synonyms?
|
79
|
+
|
80
|
+
match_queries << {
|
81
|
+
match: {
|
82
|
+
"#{ field_name }.autocomplete" => {
|
83
|
+
query: @query
|
84
|
+
}
|
85
|
+
}
|
86
|
+
} if @options[:autocomplete].nil? || @options[:autocomplete]
|
87
|
+
|
88
|
+
match_queries << {
|
89
|
+
match: {
|
90
|
+
"#{ field_name }" => {
|
67
91
|
query: @query,
|
68
|
-
|
92
|
+
fuzziness: "AUTO"
|
69
93
|
}
|
70
94
|
}
|
71
95
|
}
|
@@ -81,7 +105,7 @@ module EagleSearch
|
|
81
105
|
end
|
82
106
|
|
83
107
|
def build_term_queries
|
84
|
-
return
|
108
|
+
return if not_analyzed_properties.empty?
|
85
109
|
|
86
110
|
term_queries = []
|
87
111
|
not_analyzed_properties.keys.each do |field_name|
|
@@ -89,7 +113,7 @@ module EagleSearch
|
|
89
113
|
term: {
|
90
114
|
field_name => {
|
91
115
|
value: @query,
|
92
|
-
boost:
|
116
|
+
boost: 3
|
93
117
|
}
|
94
118
|
}
|
95
119
|
}
|
@@ -102,7 +126,7 @@ module EagleSearch
|
|
102
126
|
}
|
103
127
|
|
104
128
|
if @query_payload[:bool]
|
105
|
-
@query_payload[:bool][:should]
|
129
|
+
@query_payload[:bool][:should] << payload
|
106
130
|
else
|
107
131
|
@query_payload = payload
|
108
132
|
end
|
@@ -26,6 +26,9 @@ module EagleSearch
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def hits
|
29
|
+
@response["hits"]["hits"].each_with_index do |h, index|
|
30
|
+
@response["hits"]["hits"][index]["highlight"] = Hash[h["highlight"].map { |field, value| [field, value.first] }] if @response["hits"]["hits"][index]["highlight"]
|
31
|
+
end if @response["hits"]["hits"]
|
29
32
|
@response["hits"]["hits"]
|
30
33
|
end
|
31
34
|
|
data/lib/eagle_search/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eagle_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Belo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: elasticsearch
|