Skip to content

Instantly share code, notes, and snippets.

@Narazaka
Created August 23, 2019 07:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Narazaka/a58cdc0ae1b687c5ca8248dc99a62a7f to your computer and use it in GitHub Desktop.
Save Narazaka/a58cdc0ae1b687c5ca8248dc99a62a7f to your computer and use it in GitHub Desktop.
// https://qiita.com/shin_hayata/items/41c07923dbf58f13eec4
// http://319ring.net/blog/archives/2906/
// https://medium.com/hello-elasticsearch/elasticsearch-833a0704e44b
// http://blog.shibayu36.org/entry/2016/08/31/110000
// https://gist.github.com/karmi/4526141
export const settings = {
index: {
analysis: {
tokenizer: {
ja_text_tokenizer: {
type: "kuromoji_tokenizer",
mode: "search",
},
roman_text_tokenizer: {
type: "ngram",
min_gram: 2,
max_gram: 3,
},
},
analyzer: {
original_form_analyzer: {
type: "custom",
tokenizer: "ja_text_tokenizer",
filter: ["kuromoji_stemmer"],
},
normalize_form_analyzer: {
type: "custom",
tokenizer: "ja_text_tokenizer",
char_filter: ["icu_normalizer", "kuromoji_iteration_mark"],
filter: ["kuromoji_baseform", "kuromoji_part_of_speech", "ja_stop", "kuromoji_number", "kuromoji_stemmer"],
},
reading_form_analyzer: {
type: "custom",
tokenizer: "ja_text_tokenizer",
char_filter: ["icu_normalizer", "kuromoji_iteration_mark"],
filter: ["kuromoji_part_of_speech", "ja_stop", "kuromoji_readingform", "kuromoji_stemmer"],
},
roman_analyzer: {
tokenizer: "roman_text_tokenizer",
},
},
},
},
};
export const integer = { type: "integer" };
export const float = { type: "float" };
export const boolean = { type: "boolean" };
export const date = { type: "date" };
export const keyword = { type: "keyword" };
export const nested = { type: "nested" };
export const text = {
type: "text",
analyzer: "original_form_analyzer",
fields: {
strict: {
type: "keyword",
},
normalized: {
type: "text",
analyzer: "normalize_form_analyzer",
},
kana: {
type: "text",
analyzer: "reading_form_analyzer",
},
},
};
export const idtext = {
type: "keyword",
fields: {
fuzzy: {
type: "text",
analyzer: "roman_analyzer",
},
},
};
export const extractCharRefs = (str: string) =>
str
.replace(/"/g, '"')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&amp;/g, '&')
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment