class Search CarIndex Chewy Index settings analysis analyzer city toke

 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
class Search::CarIndex < Chewy::Index
settings analysis: {
analyzer: {
city: {
tokenizer: 'keyword',
filter: ['lowercase']
}
}
}
define_type Car.active.with_online_dealer do
field :id, type: 'integer'
field :type, value: ->(c) { 'car' }
field :car_number, type: 'long', value: ->(c) { c.random_bigint }
field :brand do
field :id, type: 'integer'
field :name
end
field :model do
field :id, type: 'integer'
field :name
end
field :location, type: 'object', value: ->(c) { c } do
field :city, analyzer: 'city', value: ->(c) { c.owner ? c.owner.city : nil }
end
end
end
scope = Search::CarIndex.filter { (brand.id(:or) == [76, 6]) & (location.city == 'bonn')}.facets(brands: {terms: 'brand.id'})
scope.count