Skip to content

Instantly share code, notes, and snippets.

@miry
Created February 20, 2013 07:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miry/4993652 to your computer and use it in GitHub Desktop.
Save miry/4993652 to your computer and use it in GitHub Desktop.
Elasticsearch settings for models with one index
module TireSearch
class Setup
class << self
def settings_options
{
number_of_shards: 1,
number_of_replicas: 0,
analysis: {
char_filter: {
char_apersand_mapping: {
type: "mapping",
mappings: ["&=>And"]
}
},
filter: {
filter_ngram: {
type: "nGram",
min_gram: 2,
max_gram: 5
},
filter_synonym: {
type: "synonym",
expand: "true",
synonyms: [
"west, wst, w",
"world, w",
"east, est, e",
"and, &",
"2, second, two",
"3, third, 3rd, three",
"1, first, one, 1st",
"4, fourth, four, 4th",
"5, five, fifth, 5th",
"6, six, sixth, 6th",
"7, seven, seventh, 7th",
"8, eight, eighth, 8th",
"9, nine, nineth, 9th"
]
}
},
analyzer: {
analyzer_synonym: {
type: "custom",
tokenizer: "standard",
char_filter: ["char_apersand_mapping"],
filter: ["standard", "word_delimiter", "lowercase", "filter_synonym", "stop", "kstem", "filter_ngram"]
}
}}}
end
def mappings_options
{
company: {_all: {analyzer: "analyzer_synonym"},
properties: {name: {analyzer: "analyzer_synonym", boost: 95, type: "string"}}},
profile: {_all: {analyzer: "analyzer_synonym"},
properties: {name: {analyzer: "analyzer_synonym", boost: 100, type: "string", search_analyzer: "analyzer_synonym"},
bio: {analyzer: "analyzer_synonym", boost: 99, type: "string"},
web_address: {analyzer: "analyzer_synonym", type: "string"}
}},
property: {_all: {analyzer: "analyzer_synonym"},
properties: {name: {analyzer: "analyzer_synonym", boost: 92, type: "string"},
address: {analyzer: "analyzer_synonym", boost: 91, type: "string"},
rank: {analyzer: "snowball", boost: 90, type: "string"}
}}
}
end
def create_index
index = Tire.index Settings.elasticsearch.index_name
unless index.exists?
index.create(
settings: settings_options,
mappings: mappings_options
)
index.refresh
end
end
def reindex
index = Tire.index Settings.elasticsearch.index_name
index.delete
index.create(
settings: settings_options,
mappings: mappings_options
)
Profile.import
Company.import
Property.import
index.refresh
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment