정의
참고
span 연산자 더 이상 사용되지 않습니다. 대신 이 구문을 사용하세요.
spanspan연산자는 텍스트 필드의 리전 내에서 Atlas Search가 일치하는 텍스트를 찾습니다. 이 기능을 사용하여 지정된 정밀도까지 서로 가까이 있는 문자열을 찾을 수 있습니다.span연산자는 쿼리가 위치 정보를 추적해야 하기 때문에 다른 연산자보다 계산 집약적입니다.span는 텀 수준 연산자이므로query필드는 분석되지 않습니다.query필드가 특수 문자가 포함된 단일 용어로 처리되기 때문에 용어 수준 연산자는 키워드 분석기 에서 잘 작동합니다.span쿼리는 점수별로 순위가 매겨지지 않습니다.
구문
span 의 구문은 다음과 같습니다:
{ $search: { "index": <index name>, // optional, defaults to "default" "span": { "term" | <positional-operator>": { <operator-specification> } } } }
참고
span 검색 쿼리는 복합 연산자 를 사용할 수 없습니다.
용어 연산자
You can use the term operator to specify the terms to search. The term operator is required and when you use it with span positional operators, it must be the innermost child of the positional operators.
구문
term 연산자의 구문은 다음과 같습니다.
"term": { "path": "<path-to-field>", "query": "<terms-to-search>" }
필드
term 연산자는 다음 필드를 사용합니다.
옵션 | 유형 | 필수 사항입니다. | 설명 |
|---|---|---|---|
| 문자열 | 네 | 검색할 인덱싱된 필드입니다. |
| 문자열 | 네 | Atlas Search에 사용할 용어 또는 구문. |
위치 연산자
You can use the positional operators to specify the position of the terms that you want to search with the term operator. The positional operators are of type document. You must specify at least one positional operator in your span operator query. The positional operators can take other span positional operators, recursively.
참고
예시 정보
The examples on this page use the sample_mflix.movies collection. If you load the sample data and create a dynamic index named default on the movies collection , you can run the following $search sample queries against the collection. The sample queries use the $limit stage to limit the results to 5 documents and the $project stage to exclude all fields except the title field in the results.
span 다음과 같은 선택적 위치 연산자를 사용합니다.
contains
The contains positional operator matches terms that are contained within other terms. You can use positional operators recursively or just the term operator within contains to specify the search terms.
구문
contains 위치 연산자의 구문은 다음과 같습니다.
{ "$search": { "span": { "contains": { "spanToReturn": "inner"|"outer", "little": { <positional-or-term-operator-specification> }, "big": { <positional-or-term-operator-specification> } } } } }
필드
contains 위치 연산자는 다음 필드를 사용합니다.
필드 | 유형 | 필수 사항입니다. | 설명 |
|---|---|---|---|
| 문서 | 네 | |
| 문서 | 네 | |
| 문서 | no | 이 Atlas Search의 결과에 적용할 점수입니다. |
| 문자열 | 네 | 실행할 쿼리 유형과 반환할 일치하는 결과입니다. 값은 다음 중 하나일 수 있습니다.
|
예시
다음 예제 쿼리는 span.contains 을 사용하여 train 용어가 great 및 robbery 용어와 함께 나타나는 문서를 찾습니다. 여기서 great 와 robbery 5 title 필드입니다.
1 db.movies.aggregate([ 2 { 3 "$search": { 4 "span": { 5 "contains": { 6 "spanToReturn": "outer", 7 "little": { 8 "term": { 9 "path": "title", 10 "query": "train" 11 } 12 }, 13 "big": { 14 "near": { 15 "clauses": [ 16 { 17 "term": { 18 "path": "title", 19 "query": "great" 20 } 21 }, 22 { 23 "term": { 24 "path": "title", 25 "query": "robbery" 26 } 27 } 28 ], 29 "slop": 5 30 } 31 } 32 } 33 } 34 } 35 }, 36 { 37 "$limit": 5 38 }, 39 { 40 "$project": { 41 "_id": 0, 42 "title": 1 43 } 44 } 45 ])
[ { title: 'The Great Train Robbery' }, { title: 'The Great Train Robbery' }, { title: "The Great St. Trinian's Train Robbery" } ]
MongoDB Search는 텀 train little great 및( 를 사용하여 지정) robbery big안에 텀 ( 을 사용하여 지정)이 포함된 문서를 반환합니다. spanToReturn 6 줄에서 를 로 inner 설정하다 MongoDB Search는(train 를 사용하여 little 지정됨)이라는 텀 great 이 robbery big및 텀().
first
The first positional operator identifies the position of the search term by using a specified number. You can specify the search terms using positional operators recursively, or just the term operator. span matches documents where the position of the search term is less than or equal to the specified number.
구문
first 위치 연산자의 구문은 다음과 같습니다.
{ "$search": { "span": { "first": { "endPositionLte": <term-position>, "operator": { <span-positional-or-term-operator-specification> }, "score": { <score-options> } } } } }
필드
first 위치 연산자는 다음 필드를 사용합니다.
예시
다음 예제 쿼리에서는 span.first 을 사용하여 지정된 string 이 title 필드에 나타나는 문서를 찾습니다. endPositionLte 매개변수의 값은 2 이며, 이는 term 연산자를 사용하여 지정된 Atlas Search 용어가 필드의 첫 번째 또는 두 번째 단어여야 함을 의미합니다.
1 db.movies.aggregate([ 2 { 3 "$search": { 4 "span": { 5 "first": { 6 "endPositionLte": 2, 7 "operator": { 8 "term": { 9 "path": "title", 10 "query": "dance" 11 } 12 } 13 } 14 } 15 } 16 }, 17 { 18 "$limit": 5 19 }, 20 { 21 "$project": { 22 "_id": 0, 23 "title": 1 24 } 25 } 26 ])
[ { title: 'Dance Program' }, { title: 'Slam Dance' }, { title: 'Last Dance' }, { title: 'War Dance' }, { title: 'Delhi Dance' } ]
MongoDB Search는 title 필드 의 첫 번째 또는 두 번째 위치에 검색 dance 가 포함된 문서를 반환합니다.
1 db.movies.aggregate([ 2 { 3 "$search": { 4 "span": { 5 "first": { 6 "endPositionLte": 2, 7 "operator": { 8 "or": { 9 "clauses": [ 10 { "term": { "path": "title", "query": "man" } }, 11 { "term": { "path": "title", "query": "woman" } } 12 ] 13 } 14 } 15 } 16 } 17 } 18 }, 19 { 20 "$limit": 5 21 }, 22 { 23 "$project": { 24 "_id": 0, 25 "title": 1 26 } 27 } 28 ])
[ { title: "Everybody's Woman" }, { title: 'Marked Woman' }, { title: 'Wonder Man' }, { title: 'Designing Woman' }, { title: 'Watermelon Man' } ]
MongoDB Search는 title 필드 의 첫 번째 또는 두 번째 위치에 검색 man 또는 woman 가 포함된 문서를 반환합니다. 예시 검색 를 지정하는 or 연산자 clauses 가 포함되어 있기 때문에 MongoDB Search는 동일한 title 에서 두 검색 를 모두 반환하지 않습니다.
near
The near positional operator matches two or more clauses that contain the search term near each other. You can specify the search terms using a list of positional operators recursively or just the term operator.
구문
near 위치 연산자의 구문은 다음과 같습니다.
{ "$search": { "span": { "near": { "clauses": [ { <span-positional-or-term-operator-specification> }, ... ], "slop": <distance-number>, "inOrder": true|false } } } }
필드
near 위치 연산자는 다음 필드를 사용합니다.
필드 | 유형 | 필수 사항입니다. | 설명 |
|---|---|---|---|
| 문서 배열 | 네 | |
| 부울 | no | 절의 용어에 대한 Atlas Search가 지정된 순서대로 이루어져야 하고 겹치지 않아야 하는지 여부를 지정하는 플래그입니다. 값은 다음 중 하나일 수 있습니다.
생략하는 경우 기본값은 |
| 문서 | no | 이 Atlas Search의 결과에 적용할 점수입니다. |
| integer | no | 절의 용어 사이의 허용 거리입니다. 값이 낮을수록 용어 간의 위치 거리가 줄어들고 값이 클수록 쿼리를 충족하기 위해 단어 사이의 거리가 길어집니다. 기본값은 |
예시
다음 예제 쿼리는 span.near 를 사용하여 Atlas Search에서 문자열 prince 와 pauper 가 서로 가까이 있는 문서를 검색합니다. inOrder 매개 변수가 false 로 설정되어 있으므로 Atlas Search 용어의 순서는 상관 없습니다. slop 매개변수가 4 로 설정되어 있으므로 Atlas Search 용어는 최대 4단어까지 구분할 수 있습니다.
1 db.movies.aggregate([ 2 { 3 "$search" : { 4 "span": { 5 "near": { 6 "clauses": [ 7 { "term": { "path": "title", "query": "prince" } }, 8 { "term": { "path": "title", "query": "pauper" } } 9 ], 10 "slop": 4, 11 "inOrder": false 12 } 13 } 14 } 15 }, 16 { 17 "$limit": 5 18 }, 19 { 20 "$project": { 21 "_id": 0, 22 "title": 1 23 } 24 } 25 ])
[ { title: 'The Prince and the Pauper' } ]
MongoDB Search는 title 필드 에서 검색 prince 및 pauper가 4단어 미만으로 구분되어 포함된 문서 반환합니다.
or
The or positional operator matches any of two or more clauses. You can specify the search terms using a list of positional operators recursively or just the term operator.
구문
or 위치 연산자의 구문은 다음과 같습니다.
{ "$search": { "span": { "or": { "clauses": [ { <span-positional-or-term-operator-specification> }, ... ], "score": { <scoring-options> } } } } }
필드
or 위치 연산자는 다음 필드를 사용합니다.
옵션 | 유형 | 필수 사항입니다. | 설명 |
|---|---|---|---|
| 문서 배열 | 네 | 검색 를 지정하는 Span 절입니다. 절 중 하나가 일치해야 하며 절은 비워 둘 수 없습니다. 각 문서 재귀적으로 |
| 문서 | no | 이 Atlas Search의 결과에 적용할 점수입니다. |
예시
The following example query uses span.or clauses to specify two term operator queries that search for documents in which the title field has either city or country.
1 db.movies.aggregate([ 2 { 3 "$search" : { 4 "span": { 5 "or": { 6 "clauses": [ 7 { "term": { "path": "title", "query": "city" } }, 8 { "term": { "path": "title", "query": "country" } } 9 ], 10 } 11 } 12 } 13 }, 14 { 15 "$limit": 5 16 }, 17 { 18 "$project": { 19 "_id": 0, 20 "title": 1 21 } 22 } 23 ])
[ { title: 'Country' }, { title: 'City Lights' }, { title: 'King & Country' }, { title: 'Fat City' }, { title: 'Atlantic City' } ]
MongoDB Search는 title 필드 에 city 또는 country 검색 가 포함된 문서를 반환하지만 동일한 title에는 둘 다 반환하지 않습니다.
subtract
The subtract positional operator removes matches that overlap with another match. You can specify the search terms using a list of positional operators recursively or just the term operator. The subtract clause can be used to exclude certain strings from your search results.
구문
subtract 위치 연산자의 구문은 다음과 같습니다.
{ "$search": { "span": { "subtract": { "include": { <span-positional-or-term-operator-specification> }, "exclude": { <span-positional-or-term-operator-specification> } } } } }
필드
subtract 위치 연산자는 다음 필드를 사용합니다.
옵션 | 유형 | 필수 사항입니다. | 설명 |
|---|---|---|---|
| 문서 | 네 | |
| 문서 | 네 | 위치 연산자를 사용하거나 연산자 텀 만 사용하여 포함할 텀 용어를 지정하는 문서입니다. |
| 문서 | no | 이 Atlas Search의 결과에 적용할 점수입니다. |
예시
다음 예제 쿼리에서는 span.subtract title father 를 사용하여 필드에 및 son 단어가 3 서로 단어 내에 순서에 관계없이 포함된 문서를 Atlas Search에 검색합니다. father 과 son 사이에 like 라는 단어가 있는 문서는 제외됩니다.
1 db.movies.aggregate([ 2 { 3 "$search" : { 4 "span": { 5 "subtract": { 6 "include": { 7 "near": { 8 "clauses": [ 9 { "term": { "path": "title", "query": "father" } }, 10 { "term": { "path": "title", "query": "son" } } 11 ], 12 "inOrder": false, 13 "slop": 3 14 } 15 }, 16 "exclude": { "term": { "path": "title", "query": "like" } } 17 } 18 } 19 } 20 }, 21 { 22 "$limit": 5 23 }, 24 { 25 "$project": { 26 "_id": 0, 27 "title": 1 28 } 29 } 30 ])
[ { title: 'Father, Son & Holy Cow' }, { title: 'My Father and My Son' }, { title: 'Jimmy Rosenberg: The Father, the Son & the Talent' } ]
MongoDB Search는 제목이 Like Father Like Son 인 문서 반환하지 않는데, 이는 title 필드 father 및 son 단어가 포함되어 있지만 그 사이에 like 도 포함되어 있으며, 이는 exclude 기준에 속하기 때문입니다. 쿼리.