-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulti_match.rb
54 lines (38 loc) · 1.23 KB
/
multi_match.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'tire'
Tire.configure { logger STDERR }
Tire.index 'index' do
delete
create mappings: {
document: {
properties: {
firstname: { type: 'string' },
middlename: { type: 'string' },
lastname: { type: 'string' }
}
}
}
store id: 1, firstname: 'john', middlename: 'clark', lastname: 'smith'
store id: 2, firstname: 'john', middlename: 'paladini', lastname: 'miranda'
refresh
end
s = Tire.search 'index', per_page: 10 do
query do
# method 1 - does not work
#match :firstname, 'john smith'
#match :middlename, 'john smith'
#match :lastname, 'john smith'
# method 2 - does not work
#match [:firstname, :lastname, :middlename], 'john smith', operator: "OR"
# method 3 - does not work
#boolean do
# should { terms(:firstname, ['john', 'smith']) }
# should { terms(:middlename, ['john', 'smith']) }
# should { terms(:lastname, ['john', 'smith']) }
#end
# method 4 - works but no control over the fiels
# string 'john smith', default_operator: 'AND'
# method 5
string 'john smith', default_operator: 'AND', fields: [:firstname, :lastname, :middlename]
end
end
s.results.to_a.select {|x| puts "RESULT: #{x.id}: #{x._score}"}