aboutsummaryrefslogtreecommitdiff
blob: 150a64f5512ccc637934ce39db10f29f30a90e20 (plain)
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
module Kkuleomi::Store
  def self.refresh_index
    Category.gateway.refresh_index!
  end

  def self.create_index(force = false)
		types = [
			Category,
			Package,
			Version,
			Change,
			Useflag,
		]

    base_settings = {
        analysis: {
            filter: {
                autocomplete_filter: {
                    type: 'edge_ngram',
                    min_gram: 1,
                    max_gram: 20,
                }
            },
            analyzer: {
                autocomplete: {
                    type: 'custom',
                    tokenizer: 'standard',
                    filter: %w(lowercase autocomplete_filter)
                }
            }
        },
				mapping: { total_fields: { limit: 25000 } }
    }

		# In ES 1.5, we could use 1 mega-index. But in ES6, each model needs its own.
		types.each { |type|
						client = type.gateway.client
						client.indices.delete(index: type.index_name) rescue nil if force
						body = {
							settings: type.settings.to_hash.merge(base_settings),
						 	mappings: type.mappings.to_hash
						}
						client.indices.create(index: type.index_name, body: body)
		}
  end
end