TOKENIZE_SUBSTRING은 각 토큰에 대해 N-그램을 생성하고 이러한 N-그램을 검색 색인에 저장합니다. 생성할 N-그램의 최소 및 최대 길이는 선택적인 인수를 통해 구성됩니다.
하위 문자열 검색 색인은 토큰화로 훨씬 더 많은 토큰이 생성되기 때문에 동일한 데이터에 대해 10~30배 더 많은 스토리지를 전체 텍스트 색인으로 사용합니다. 이는 ngram_size_min과 ngram_size_max 사이의 차이가 커질 때 특히 그렇습니다. 하위 문자열 쿼리는 또한 실행을 위해 더 많은 리소스를 사용합니다.
TOKENIZE_FULLTEXT와 같이 특정 유형의 콘텐츠를 사용하도록 TOKENIZE_SUBSTRING을 구성할 수 있습니다.
상대적 하위 문자열 검색 사용 설정
기본 하위 문자열 검색 외에도 SEARCH_SUBSTRING은 상대적 검색 모드를 지원합니다. 상대적 검색은 하위 문자열 검색 결과를 미세 조정합니다.
상대적 검색 모드를 사용 설정하려면 TOKENIZE_SUBSTRING의 relative_search_types 파라미터를 지원되는 상대적 검색 유형 요소가 포함된 비어 있지 않은 배열로 설정합니다.
상대적 검색이 토큰화에 사용 설정되었으면 SEARCH_SUBSTRING이 다음 상대적 검색 유형으로 쿼리를 수행할 수 있습니다.
phrase: 연속 하위 문자열 일치
예시
저장된 텍스트
하위 문자열 쿼리.
일치
Bridge over Troubled Water
bridge over
예
Bridge over Troubled Water
Bridge bridge bridge
아니요
Bridge over Troubled Water
brid over
아니요
Bridge over Troubled Water
ridge over trouble
예
Bridge over Troubled Water
bridge ove troubled
아니요
Bridge over Troubled Water
idge ove
예
Bridge over Troubled Water
idge , ove
예
Bridge over Troubled Water
RIDGE OVE
예
Bridge over Troubled Water
bridge water
아니요
value_prefix: 연속 하위 문자열 매칭을 수행하고 이러한 매칭은 값의 처음 위치에서 시작되어야 합니다. 이는 대소문자 및 공백 정규화 문자열에 대한 STARTS_WITH 함수와 개념적으로 비슷합니다.
예시
저장된 텍스트
하위 문자열 쿼리
일치
Bridge over Troubled Water
bridge over
예
Bridge over Troubled Water
bridge , over
예
Bridge over Troubled Water
ridge over
아니요
Bridge over Troubled Water
troubled water
아니요
value_suffix: 연속 하위 문자열 매칭을 수행하고 값 끝에서 매칭을 수행해야 합니다. 이는 대소문자 및 공백 정규화 문자열에 대한 ENDS_WITH 함수와 개념적으로 비슷합니다.
예시
저장된 텍스트
하위 문자열 쿼리.
일치
Bridge over Troubled Water
troubled water
예
Bridge over Troubled Water
troubled ; water
예
Bridge over Troubled Water
roubled water
예
Bridge over Troubled Water
troubled wate
아니요
Bridge over Troubled Water
trouble water
아니요
Bridge over Troubled Water
bridge over
아니요
word_prefix:value_prefix와 비슷하지만 문자열이 용어 경계(값 경계가 아닌)에서 매칭되어야 합니다.
예시
저장된 텍스트
하위 문자열 쿼리
일치
Bridge over Troubled Water
over trouble
예
Bridge over Troubled Water
Over , trouble
예
Bridge over Troubled Water
troub water
아니요
Bridge over Troubled Water
over water
아니요
Bridge over Troubled Water
ove troubled
아니요
Bridge over Troubled Water
ver troubled
예
word_suffix: value_suffix와 비슷하지만 문자열이 용어 경계 끝에서 매칭되어야 합니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-05(UTC)"],[],[],null,["# Perform a substring search\n\n| **Note:** This feature is available with the Spanner Enterprise edition and Enterprise Plus edition. For more information, see the [Spanner editions overview](/spanner/docs/editions-overview).\n\n\u003cbr /\u003e\n\nIn addition to full token matching, Spanner\n[search indexes](/spanner/docs/full-text-search/search-indexes)\nsupport substring searches. This page describes how to perform a substring\nsearch as part of a [full-text search](/spanner/docs/full-text-search) in\nSpanner.\n\nSubstring searches have the following characteristics:\n\n- Case insensitive, discards most punctuation, and normalizes whitespace.\n- No Chinese, Japanese, Korean (CJK) segmentation, since partial CJK queries often segment incorrectly.\n- For multiple search terms, the result must contain a substring from each term. For example, `'happ momen'` matches `\"happy moment\"`, because both substrings are found in the text. It doesn't match `\"happy day\"`.\n\n**Examples**\n\nFor a substring search, use the [`TOKENIZE_SUBSTRING`](/spanner/docs/reference/standard-sql/search_functions#tokenize_substring)\nfunction in the `TOKENLIST` column definition, as shown in the following DDL\nexample: \n\n### GoogleSQL\n\n CREATE TABLE Albums (\n AlbumId STRING(MAX) NOT NULL,\n AlbumTitle STRING(MAX),\n AlbumTitle_Tokens TOKENLIST AS (TOKENIZE_SUBSTRING(AlbumTitle)) HIDDEN\n ) PRIMARY KEY(AlbumId);\n\n### PostgreSQL\n\nThis example uses\n[`spanner.tokenize_substring`](/spanner/docs/reference/postgresql/search_functions#tokenize_substring). \n\n CREATE TABLE albums (\n albumid character varying NOT NULL,\n albumtitle character varying,\n albumtitle_tokens spanner.tokenlist\n GENERATED ALWAYS AS (spanner.tokenize_substring(albumtitle)) VIRTUAL HIDDEN,\n PRIMARY KEY(albumid));\n\nIn the SQL query, use the [`SEARCH_SUBSTRING`](/spanner/docs/reference/standard-sql/search_functions#search_substring) function in the `WHERE` clause. For\nexample, the following query matches an album with title \"happy\" from the table\ncreated in the previous example: \n\n### GoogleSQL\n\n SELECT Album\n FROM Albums\n WHERE SEARCH_SUBSTRING(AlbumTitle_Tokens, 'happ');\n\n### PostgreSQL\n\nThis example uses\n[`spanner.search_substring`](/spanner/docs/reference/postgresql/functions-and-operators#search_functions). \n\n SELECT album\n FROM albums\n WHERE spanner.search_substring(albumtitle_tokens, 'happ');\n\n`TOKENIZE_SUBSTRING` generates *[n-grams](https://en.wikipedia.org/wiki/N-gram)*\nfor each token and stores these n-grams in the search index. The minimum and\nmaximum length of n-grams to generate are configured through optional arguments.\n\nSubstring search indexes can use 10-30x more storage as full-text indexes over\nthe same data, because the tokenization produces a lot more tokens. This is\nespecially true if as the difference between `ngram_size_min` and\n`ngram_size_max` grows. Substring queries also use more resources to execute.\n\nLike [`TOKENIZE_FULLTEXT`](/spanner/docs/reference/standard-sql/search_functions#tokenize_fulltext),\nyou can configure `TOKENIZE_SUBSTRING` to use specific types of content.\n\nEnable a relative substring search\n----------------------------------\n\nIn addition to the basic substring search,\n[`SEARCH_SUBSTRING`](/spanner/docs/reference/standard-sql/search_functions#search_substring)\nsupports the relative search mode. A relative search refines substring search\nresults.\n\nTo enable the relative search mode, set the `relative_search_types` parameter of\n[`TOKENIZE_SUBSTRING`](/spanner/docs/reference/standard-sql/search_functions#tokenize_substring)\nto a non-empty array with elements of supported relative search types.\n\nWhen relative search is enabled in tokenization, `SEARCH_SUBSTRING` can perform\nqueries with the following relative search types:\n\n- `phrase`: matches contiguous substrings\n\n **Examples**\n\n- `value_prefix`: matches contiguous substrings and the match has to\n start at the beginning of the value. This is conceptually similar to the\n `STARTS_WITH` function for case and whitespace normalized strings.\n\n **Examples**\n\n- `value_suffix`: matches contiguous substrings and the match has to match at\n the end of the value. This is conceptually similar to the `ENDS_WITH`\n function for case and whitespace normalized strings.\n\n **Examples**\n\n- `word_prefix:` like `value_prefix`, but the string has to match at a term\n boundary (rather than a value boundary).\n\n **Examples**\n\n- `word_suffix`: like `value_suffix`, but the string has to match at the end\n of a term boundary.\n\n **Examples**\n\nWhat's next\n-----------\n\n- Learn about [full-text search queries](/spanner/docs/full-text-search/query-overview).\n- Learn how to [rank search results](/spanner/docs/full-text-search/ranked-search).\n- Learn how to [paginate search results](/spanner/docs/full-text-search/paginate-search-results).\n- Learn how to [mix full-text and non-text queries](/spanner/docs/full-text-search/mix-full-text-and-non-text-queries).\n- Learn how to [search multiple columns](/spanner/docs/full-text-search/search-multiple-columns)."]]