-
Notifications
You must be signed in to change notification settings - Fork 0
/
index_boost.rb
43 lines (33 loc) · 879 Bytes
/
index_boost.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
require 'tire'
Tire.configure { logger STDERR }
1.upto(2) do
Tire.index 'search' do
delete
create mappings: {
document: {
properties: {
first: { type: 'string' },
last: { type: 'string', boost: 2.0 }
}
}
},
settings: { number_of_shards: 1 }
store first: 'Kimberly', last: 'Leighton'
store first: 'Barbara', last: 'Leighton'
store first: 'John', last: 'Leighton'
store first: 'Nancy', last: 'Mark'
store first: 'Lawrence', last: 'Mark'
store first: 'Louis', last: 'Mark'
store first: 'Leighton', last: 'Mark'
store first: 'Leighton', last: 'Sweet'
refresh
end
search = 'mark leighton'
s = Tire.search 'search' do
query do
#string search
match [:last, :first], search
end
end
p s.results.to_a.collect {|x| [x.first, x.last].join(" ")}
end