2.X/2. Search in Depth

2-4-2. Mixing It Up

drscg 2017. 9. 24. 21:56

Requiring exact-phrase matches may be too strict a constraint. Perhaps we do want documents that contain "quick brown fox" to be considered a match for the query "quick fox", even though the positions aren’t exactly equivalent.

정확한 구문 일치를 요구하는 것은 너무 엄격한 제약사항이 될 수 있다. 아마도 "quick brown fox" 를 포함하는 document는 query "quick fox" 에 일치하는 것으로 간주하길 원할 것이다. 비록 그 위치가 정확히 일치하지 않더라도 말이다.

We can introduce a degree of flexibility into phrase matching by using the slop parameter:

slop 매개변수를 사용해, 구문 일치에 유연성의 정도를 지정할 수 있다.

GET /my_index/my_type/_search
{
    "query": {
        "match_phrase": {
            "title": {
                "query": "quick fox",
                "slop":  1
            }
        }
    }
}

The slop parameter tells the match_phrase query how far apart terms are allowed to be while still considering the document a match. By how far apart we mean how many times do you need to move a term in order to make the query and document match?

단어들이 얼마나 떨어져 있어야 일치하는 document로 간주할 것인가를, match_phrase 에서 slop 매개변수로 지정한다. 얼마나 떨어져 있는가(how far apart) 는 query와 document를 일치하도록 만들기 위해, 단어를 몇 번이나 이동시켜야 하는가 를 의미한다.

We’ll start with a simple example. To make the query quick fox match a document containing quick brown fox we need a slop of just 1:

간단한 예제를 시작해 보자. query quick fox 에 quick brown fox 를 포함하는 document를 일치하도록 만들기 위해서는, slop 을 1 로 하면 된다.

            Pos 1         Pos 2         Pos 3
-----------------------------------------------
Doc:        quick         brown         fox
-----------------------------------------------
Query:      quick         fox
Slop 1:     quick                 ↳     fox

Although all words need to be present in phrase matching, even when using slop, the words don’t necessarily need to be in the same sequence in order to match. With a high enough slop value, words can be arranged in any order.

구문 일치에서는, slop 을 사용한다 하더라도, 모든 단어가 존재해야 하지만, 일치하기 위해, 단어들이 동일한 순서로 존재해야 할 필요는 없다. 충분히 높은 slop 값으로, 단어들은 어떤 순서로도 배치될 수 있다.

To make the query fox quick match our document, we need a slop of 3:

query fox quick 에 document를 일치하도록 만들기 위해서는, slop 을 3 으로 하면 된다.

            Pos 1         Pos 2         Pos 3
-----------------------------------------------
Doc:        quick         brown         fox
-----------------------------------------------
Query:      fox           quick
Slop 1:     fox|quick  ↵  
Slop 2:     quick      ↳  fox
Slop 3:     quick                 ↳     fox

이번 단계에서, fox 와 quick 은 동일한 위치를 차지한다는 것을 유심히 보자. 단어의 순서를 fox quick 에서 quick fox 로 바꾸기 위해서는, 두 단계 또는 slop 2 가 필요하다.


'2.X > 2. Search in Depth' 카테고리의 다른 글

2-4. Proximity Matching  (0) 2017.09.24
2-4-1. Phrase Matching  (0) 2017.09.24
2-4-3. Multivalue Fields  (0) 2017.09.24
2-4-4. Closer Is Better  (0) 2017.09.24
2-4-5. Proximity for Relevance  (0) 2017.09.24