Common grams token filter
출처: 문서
본문
Common grams 토큰 필터
common_grams 토큰 필터는 텍스트에서 자주 발생하는 구문(common grams)을 유지하여 검색 관련성을 향상시켜요. 이는 특정 단어 조합이 자주 하나의 단위로 발생하고, 개별 토큰으로 처리될 경우 검색 관련성에 영향을 줄 수 있는 언어나 데이터셋을 다룰 때 유용해요. 입력 문자열에 일반 단어가 있으면 이 토큰 필터는 해당 단어의 유니그램과 바이그램을 모두 생성해요.
이 토큰 필터를 사용하면 일반 구문을 그대로 유지하여 검색 관련성을 향상시켜요. 이는 특히 자주 사용되는 단어 조합에 대해 쿼리를 더 정확하게 일치시키는 데 도움이 돼요. 또한 관련 없는 일치 항목을 줄여 검색 정밀도를 향상시켜요.
이 필터를 사용할 때는 common_words 목록을 신중하게 선택하고 유지 관리해야 해요.
{: .warning}
매개변수
common_grams 토큰 필터는 다음 매개변수로 구성할 수 있어요.
| 매개변수 | 필수/선택 | 데이터 유형 | 설명 |
|---|---|---|---|
common_words |
필수 | 문자열 목록 | 함께 자주 나타나는 단어로 처리되어야 하는 단어 목록이에요. 이 단어들은 일반 그램을 생성하는 데 사용돼요. common_words 매개변수가 빈 목록이면 common_grams 토큰 필터는 아무 작업도 수행하지 않는 필터가 되어 입력 토큰을 전혀 수정하지 않아요. |
ignore_case |
선택 | 불리언 | 필터가 일반 단어를 일치시킬 때 대소문자 차이를 무시할지 여부를 나타내요. 기본값은 false예요. |
query_mode |
선택 | 불리언 | true로 설정하면 다음 규칙이 적용돼요:- common_words에서 생성된 유니그램은 출력에 포함되지 않아요.- 일반 단어가 아닌 단어 뒤에 일반 단어가 오는 바이그램은 출력에 유지돼요. - 일반 단어가 아닌 단어의 유니그램은 바로 뒤에 일반 단어가 오면 제외돼요. - 일반 단어가 아닌 단어가 텍스트 끝에 나타나고 앞에 일반 단어가 있으면 해당 유니그램은 출력에 포함되지 않아요. |
예제
다음 예제 요청은 my_common_grams_index라는 새 인덱스를 생성하고 common_grams 필터를 사용하여 분석기를 구성해요:
PUT /my_common_grams_index
{
"settings": {
"analysis": {
"filter": {
"my_common_grams_filter": {
"type": "common_grams",
"common_words": ["a", "in", "for"],
"ignore_case": true,
"query_mode": true
}
},
"analyzer": {
"my_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"my_common_grams_filter"
]
}
}
}
}
}
{% include copy-curl.html %}
생성된 토큰
다음 요청을 사용하여 분석기로 생성된 토큰을 확인해요:
GET /my_common_grams_index/_analyze
{
"analyzer": "my_analyzer",
"text": "A quick black cat jumps over the lazy dog in the park"
}
{% include copy-curl.html %}
응답에는 생성된 토큰이 포함되어 있어요:
{
"tokens": [
{"token": "a_quick","start_offset": 0,"end_offset": 7,"type": "gram","position": 0},
{"token": "quick","start_offset": 2,"end_offset": 7,"type": "<ALPHANUM>","position": 1},
{"token": "black","start_offset": 8,"end_offset": 13,"type": "<ALPHANUM>","position": 2},
{"token": "cat","start_offset": 14,"end_offset": 17,"type": "<ALPHANUM>","position": 3},
{"token": "jumps","start_offset": 18,"end_offset": 23,"type": "<ALPHANUM>","position": 4},
{"token": "over","start_offset": 24,"end_offset": 28,"type": "<ALPHANUM>","position": 5},
{"token": "the","start_offset": 29,"end_offset": 32,"type": "<ALPHANUM>","position": 6},
{"token": "lazy","start_offset": 33,"end_offset": 37,"type": "<ALPHANUM>","position": 7},
{"token": "dog_in","start_offset": 38,"end_offset": 44,"type": "gram","position": 8},
{"token": "in_the","start_offset": 42,"end_offset": 48,"type": "gram","position": 9},
{"token": "the","start_offset": 45,"end_offset": 48,"type": "<ALPHANUM>","position": 10},
{"token": "park","start_offset": 49,"end_offset": 53,"type": "<ALPHANUM>","position": 11}
]
}