'동의어'에 해당되는 글 3건

  1. 2017.07.31 [Lucene] SynonymFilter -> SynonymGraphFilter + FlattenGraphFilter
  2. 2016.04.22 [Elasticsearch] Elasticsearch에서 synonyms 사용 시 고려사항.
  3. 2012.12.18 Elasticsearch 동의어/유의어 사전 활용

[Lucene] SynonymFilter -> SynonymGraphFilter + FlattenGraphFilter

ITWeb/검색일반 2017. 7. 31. 18:37

오늘 뭐 좀 보다가 그냥 공유해 봅니다.
https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-synonym-tokenfilter.html


lucene 6.6 에서는 SynonymFilter@Deprecated 되어 있습니다.

대체 filter 는 글에도 나와 있지만 SynonymGraphFilter 인데요.

재밌는건 이넘은 search time 에서 동작 하는 거라 index time 에는 여전히 SynonymFilter 또는 FlattenGraphFilter 를 사용해야 한다는 점입니다.

아직 깊게 분석해보지 않아서 ^^; 


간만에 lucene 코드 까서 이것 저것 테스트 해보니 재밌내요.

그냥 참고 하시라고 올려봤습니다.


:

[Elasticsearch] Elasticsearch에서 synonyms 사용 시 고려사항.

Elastic/Elasticsearch 2016. 4. 22. 17:59

뭐 이런게 고려 사항 일까 싶지만 그냥 머리 식히기 위해서 작성해 봅니다.


synonyms 는 기본적으로 search 시와 index 시에 다 사용이 가능 합니다.

이 둘 사이에 장단점은 아래 링크를 참고해 주시면 좋겠습니다.


참고링크)

https://www.elastic.co/guide/en/elasticsearch/guide/2.x/synonyms-expand-or-contract.html


search 시 synonyms 를 적용하기 위해서는 match query 종류를 사용하셔야 합니다.

간혹 term query 종류를 사용하시면서 왜 안되지 하시는 분들도 있는데 주의 하셔야 합니다.


index 시 synonyms 를 적용하기 위해서는 synonyms filter 우선순위를 잘 확인 하셔야 합니다.

제일 앞에 있는 filter 때문에 적용이 안될 수도 있으니 주의 하셔야 합니다.

이 경우 search 시 term query 류를 사용하면 안되던 것이 지원이 되기 때문에 요건에 따라 선택해서 사용하시면 좋을 것 같습니다.


:

Elasticsearch 동의어/유의어 사전 활용

Elastic/Elasticsearch 2012. 12. 18. 22:22

[title=Elasticsearch 동의어/유의어 설정]

- 색인 파일 생성 시 설정을 해줘야 함

- 기본 kr_analysis 가 적용되어 있어야 함

  - 없을 경우 한국어 처리가 안됨

- synonym.txt 파일을 적절한 위치에 생성

  - http://www.elasticsearch.org/guide/reference/index-modules/analysis/synonym-tokenfilter.html


[title=synonym.txt 샘플]

Solr synonyms


The following is a sample format of the file:


# blank lines and lines starting with pound are comments.


#Explicit mappings match any token sequence on the LHS of "=>"

#and replace with all alternatives on the RHS.  These types of mappings

#ignore the expand parameter in the schema.

#Examples:

i-pod, i pod => ipod,

sea biscuit, sea biscit => seabiscuit


#Equivalent synonyms may be separated with commas and give

#no explicit mapping.  In this case the mapping behavior will

#be taken from the expand parameter in the schema.  This allows

#the same synonym file to be used in different synonym handling strategies.

#Examples:

ipod, i-pod, i pod

foozball , foosball

universe , cosmos


# If expand==true, "ipod, i-pod, i pod" is equivalent to the explicit mapping:

ipod, i-pod, i pod => ipod, i-pod, i pod

# If expand==false, "ipod, i-pod, i pod" is equivalent to the explicit mapping:

ipod, i-pod, i pod => ipod


#multiple synonym mapping entries are merged.

foo => foo bar

foo => baz

#is equivalent to

foo => foo bar, baz


[색인파일 생성 샘플코드 - synonym 적용]

curl -XPUT 'http://localhost:9200/test' -d '{

    "settings" : {

        "number_of_shards" : 5,

        "number_of_replicas" : 1,

        "index" : {

            "analysis" : {

                "analyzer" : {

                    "kr_analyzer" : {

                        "type" : "custom",

                        "tokenizer" : "kr_tokenizer",

                        "filter" : ["trim", "kr_filter", "kr_synonym"]

                    },

                    "kr_analyzer" : {

                        "type" : "custom",

                        "tokenizer" : "kr_tokenizer",

                        "filter" : ["trim", "kr_filter", "kr_synonym"]

                    }

                },

                "filter" : {

                    "kr_synonym" : {

                        "type" : "synonym",

                        "synonyms_path" : "analysis/synonym.txt"

                    }

                }

            }

        }

    }'


[title=색인파일 생성 샘플코드]

curl -XPUT 'http://10.101.254.223:9200/test' -d '{

    "settings" : {

        "number_of_shards" : 5,

        "number_of_replicas" : 1

    },

    "index" : {

        "analysis" : {

            "analyzer" : {

                "synonym" : {

                    "tokenizer" : "kr_analyzer",

                    "filter" : ["synonym"]

                }

            },

            "filter" : {

                "synonym" : {

                    "type" : "synonym",

                    "synonyms_path" : "/home/계정/apps/elasticsearch/plugins/analysis-korean/analysis/synonym.txt"

                }

            }

        }

    },

    "mappings" : {

        "docs" : {

            "properties" : {

 ...................................(요기 부분은 다른 문서들 참고 하시면 됩니다.)

                    }

                }

            }

        }

    }

}'

: