UPDATEAccountSETnick_name="Fund for vacation at the north pole"WHEREid=7;UPDATEAccountSETnick_name="Fund -- thrill rides!"WHEREid=16;UPDATEAccountSETnick_name="Rainy day fund for the things I still want to do"WHEREid=20;
SEARCH 함수를 사용하여 그래프에서 nick_name에 'rainy day' 또는 'vacation'이 포함된 Account 노드를 찾습니다. 그래프 탐색을 사용하여 해당 계정으로 송금된 금액을 찾습니다. 검색 관련성을 기준으로 일치 항목에 점수를 매깁니다. 관련성 내림차순으로 결과를 정렬하고 반환합니다. 동일한 검색 함수 호출에서 토큰의 논리합을 찾을 수 있습니다.
[[["이해하기 쉬움","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,["# Use full-text search with Spanner Graph\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\nThis page describes how to use [full-text search](/spanner/docs/full-text-search)\nin Spanner Graph.\n\nSpanner Graph combines graph and full-text search in one system. This\ncombination lets you derive insights from unstructured data in conjunction with\nrelationships in the graph.\n\nBefore you begin\n----------------\n\nTo run the examples on this page, you need to perform the\n[set up and query Spanner Graph using the Google Cloud console](/spanner/docs/graph/set-up)\nprocedures. These procedures do the following:\n\n1. [Create an instance](/spanner/docs/graph/set-up#create-instance).\n2. [Create a database](/spanner/docs/graph/set-up#create-database).\n3. [Create a schema for your Spanner Graph database](/docs/graph/set-up#create-schema).\n4. [Insert graph data](/spanner/docs/graph/set-up#insert-graph-data).\n\nCreate tokens and search indexes\n--------------------------------\n\nThe first [step to using full-text search](/spanner/docs/full-text-search#full-text_search_steps)\nis to tokenize the content you want to search against and create a search index.\nFull-text search runs queries against the search index.\n\nThe following example adds the `nick_name_token` column and uses the\n[TOKENIZE_FULLTEXT](/spanner/docs/reference/standard-sql/search_functions#tokenize_fulltext)\nfunction to tokenize the text in the `Account.nick_name` column. Next, the\nsearch index is created on the `nick_name_token` column. \n\n ALTER TABLE Account\n ADD COLUMN nick_name_token TOKENLIST\n AS (TOKENIZE_FULLTEXT(nick_name)) STORED HIDDEN;\n\n CREATE SEARCH INDEX AccountTextSearchIndex\n ON Account(nick_name_token) STORING (nick_name);\n\nThe following example uses the\n[TOKENIZE_FULLTEXT](/spanner/docs/reference/standard-sql/search_functions#tokenize_fulltext)\nfunction to tokenize the text in `Account.nick_name` and creates a search index\non the `nick_name_token` column that contains the tokens. \n\n ALTER TABLE AccountTransferAccount\n ADD COLUMN notes STRING(MAX);\n ALTER TABLE AccountTransferAccount\n ADD COLUMN notes_token TOKENLIST AS (TOKENIZE_FULLTEXT(notes)) STORED HIDDEN;\n\n CREATE SEARCH INDEX TransferTextSearchIndex\n ON AccountTransferAccount(notes_token) STORING (notes);\n\nSince some new columns were added to `Account` and `AccountTransferAccount` and\nyou access them as new graph properties in search functions, you need\nto update the property graph definition using the following statement (more\nexplained in\n[update existing node or edge definitions](/spanner/docs/graph/create-update-drop-schema#update-existing-node-or-edge)). \n\n CREATE OR REPLACE PROPERTY GRAPH FinGraph\n NODE TABLES (Account, Person)\n EDGE TABLES (\n PersonOwnAccount\n SOURCE KEY (id) REFERENCES Person (id)\n DESTINATION KEY (account_id) REFERENCES Account (id)\n LABEL Owns,\n AccountTransferAccount\n SOURCE KEY (id) REFERENCES Account (id)\n DESTINATION KEY (to_id) REFERENCES Account (id)\n LABEL Transfers\n );\n\nYou can now use full-text search on your graph data.\n\nSearch graph node property\n--------------------------\n\nThis example shows you how to search for nodes in the graph and explore their\nrelationships.\n\n1. Update `Account.nick_name` with some text messages.\n\n UPDATE Account SET nick_name = \"Fund for vacation at the north pole\" WHERE id = 7;\n UPDATE Account SET nick_name = \"Fund -- thrill rides!\" WHERE id = 16;\n UPDATE Account SET nick_name = \"Rainy day fund for the things I still want to do\" WHERE id = 20;\n\n2. Use the [`SEARCH`](/spanner/docs/reference/standard-sql/search_functions#search_fulltext)\n function to find `Account` nodes in the graph that have either\n \"rainy day\" OR \"vacation\" in their `nick_name`. Use graph traversal to find\n the amount of money that was transferred into those Accounts. Score the\n matches by search relevance. Sort and return the results in descending\n relevance order. Note that you can look for the disjunction of tokens in the\n same search function call.\n\n GRAPH FinGraph\n MATCH (n:Account)\u003c-[e:Transfers]-(:Account)\n WHERE SEARCH(n.nick_name_token, '\"rainy day\" | vacation')\n RETURN n.nick_name, e.amount AS amount_added\n ORDER BY SCORE(n.nick_name_token, '\"rainy day\" | vacation') DESC\n\n Result: \n\n nick_name amount_added\n Rainy day fund for the things I still want to do 300\n Fund for vacation at the north pole 500\n\nSearch graph edge property\n--------------------------\n\nThis example shows you how to search for specific edges in the graph\n\n1. Update `AccountTransferAccount.notes` with a text message.\n\n UPDATE AccountTransferAccount SET notes = 'for trip fund'\n WHERE id = 16 AND to_id = 20;\n UPDATE AccountTransferAccount SET notes = '<trip's very fun!>'\n WHERE id = 20 AND to_id = 7;\n UPDATE AccountTransferAccount SET notes = 'book fee'\n WHERE id = 20 AND to_id = 16;\n\n2. Use full-text search to find Transfers edges that contain \"trip\". Use graph\n traversal to find the source and destination nodes of those transfers.\n\n GRAPH FinGraph\n MATCH (a:Account)-[e:Transfers WHERE SEARCH(e.notes_token, 'trip')]-\u003e(b:Account)\n RETURN a.id AS src_id, b.id AS dst_id, e.notes\n\n Result: \n\n src_id dst_id notes\n\n 20 7 <trip's very fun!>\n 16 20 for trip fund\n\nThe search function correctly recalled the first result despite the\nHTML tags in the text.\n\nWhat's next\n-----------\n\n- [Learn about Spanner Graph queries](/spanner/docs/graph/queries-overview).\n- [Learn about full-text search](/spanner/docs/reference/standard-sql/search_functions#search_fulltext).\n- [Learn about full-text search queries](/spanner/docs/full-text-search/query-overview)."]]