Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Cette page décrit ce qu'est la recherche en texte intégral et comment elle fonctionne.
La recherche en texte intégral vous permet de créer une application capable de rechercher des mots, des expressions ou des nombres dans un tableau, au lieu de se limiter à la recherche de correspondances exactes dans des champs structurés. Les recherches en texte intégral renvoient les dernières données validées transactionnellement cohérentes à votre application. Les fonctionnalités de recherche en texte intégral de Spanner incluent également la correction orthographique, la détection automatique de la langue de la requête de recherche et le classement des résultats de recherche.
Spanner étend automatiquement les recherches de texte pour inclure les correspondances approximatives de mots.
Vous devez créer un index de recherche sur toutes les colonnes que vous souhaitez rendre disponibles pour les recherches en texte intégral. Spanner analyse les données de ces colonnes pour identifier les mots individuels à ajouter à l'index de recherche.
Spanner met à jour l'index de recherche avec les données nouvelles ou modifiées dès qu'elles sont validées dans la base de données.
Types de recherche en texte intégral
Recherche de texte de base : recherche du contenu à l'aide de tout ou partie d'un mot ou d'une expression pour obtenir des résultats fiables. Exemples de prédicats de requête :
Tous les mots [terrier tricolore]
Mot ou expression exacts ["rat terrier"]
L'un des mots suivants : [miniature OR standard]
Mot à proximité [world AROUND(3) cup]
Sous-chaîne [start*]
Recherche numérique : effectue des recherches d'égalité et d'inégalité numériques.
Les recherches d'égalité correspondent à un nombre. Les recherches par plage et par inégalité correspondent à un nombre dans une plage spécifique.
Recherche basée sur les n-grammes : met en correspondance les mots présentant des variantes orthographiques, y compris les noms propres. Ce type de recherche permet également de faire correspondre le texte de la requête avec des noms mal orthographiés, des noms avec des orthographes alternatives et du texte avec d'autres variantes orthographiques.
Recherches Soundex : elles permettent de trouver les mots qui ont une prononciation similaire.
Fonctionnalités de recherche en texte intégral
La recherche en texte intégral de Spanner présente les caractéristiques suivantes :
Résultats de recherche classés : calcule un score pour évaluer la pertinence d'une requête par rapport à un document (par exemple, en accordant un poids plus important à column_A). Utilisez des expressions SQL pour personnaliser le classement.
Extraits : met en évidence le texte correspondant dans le résultat de recherche.
Compatibilité mondiale : la tokenisation est automatiquement compatible avec différentes langues, y compris la segmentation CJK. La spécification manuelle de la langue vous permet d'effectuer des ajustements supplémentaires.
Gouvernance : trouve chaque occurrence de mots spécifiques.
Correction orthographique : corrige automatiquement les mots mal orthographiés dans les requêtes pour qu'ils correspondent aux mots correctement orthographiés stockés. Par exemple, si l'utilisateur recherche "girafe", la recherche trouve les documents contenant "girafe".
Ajout de synonymes contextuels, y compris de mots vides : ajoute automatiquement des synonymes contextuellement pertinents pour augmenter le rappel. Par exemple, "la maison"
correspond à "cette maison" et "photo de chat" correspond à "photo de chaton".
Traduction contextuelle des nombres vers et depuis le texte : fait correspondre la version textuelle d'un nombre à sa représentation numérique et inversement. Par exemple, "cinq chats" correspond à "5 chats".
Conversion automatique au pluriel : la requête "chat" correspond à "chats".
Concepts de recherche en texte intégral
La recherche en texte intégral repose sur les concepts clés suivants :
Un document fait référence aux données pouvant faire l'objet d'une recherche dans une ligne donnée.
Un jeton fait référence à chaque mot d'un document stocké dans un index de recherche.
Le processus de tokenisation divise un document en jetons.
Un tokeniseur est une fonction SQL utilisée pour la tokenisation.
Un index inversé stocke les jetons. Utilisez des requêtes SQL pour effectuer des recherches dans l'index inversé.
Exemple de cas d'utilisation pour la recherche en texte intégral
Pour comprendre la recherche en texte intégral, examinons une application qui utilise une base de données pour stocker les titres de chaque chanteur. Chaque ligne correspond à un titre. Chaque chanson contient des colonnes telles que le titre, les paroles, l'artiste et l'album. L'application utilise la recherche en texte intégral pour permettre à un utilisateur de rechercher un titre à l'aide de requêtes en langage naturel :
La recherche est compatible avec les requêtes qui utilisent l'opérateur OR, comme Prince OR
Camille. Les applications peuvent directement insérer l'entrée de l'utilisateur final dans le champ de recherche dans la fonction SQL SEARCH (à l'aide de la syntaxe rquery). Pour en savoir plus, consultez Interroger un index de recherche.
Spanner utilise des index de recherche pour rechercher des documents correspondants dans différents champs. Par exemple, une application peut émettre une requête pour rechercher "cry" dans le titre, "so cold" dans les paroles et "Prince" comme chanteur.
Autres utilisations des index de recherche
Les index de recherche ont de nombreux usages en plus de la recherche en texte intégral, comme les suivants :
Indexation des éléments dans les colonnes de tableau. Prenons l'exemple d'une application qui utilise une colonne de tableau pour stocker les tags associés à un élément. Grâce aux index de recherche, l'application peut rechercher efficacement les lignes contenant un tag spécifique. Pour en savoir plus, consultez Tokenisation de tableaux.
Rechercher des données qui se trouvent à l'intersection d'un ensemble de conditions de requête. Par exemple, vous pouvez utiliser un ensemble arbitraire d'attributs (couleur, taille, marque, note, etc.) pour rechercher un produit dans un catalogue.
Utiliser des conditions de recherche numériques, seules ou en combinaison avec des conditions de texte intégral. Voici quelques exemples de cas où un index de recherche est utile pour les recherches numériques :
lorsqu'il est associé à une application de texte intégral. Par exemple, pour trouver un e-mail dont l'objet est Image et dont la taille est supérieure à 1 Mo.
Lorsqu'il fait partie d'une intersection de conditions décrites précédemment.
Par exemple, pour trouver les produits où color = "yellow" AND size = 14 AND
rating >= 4.5.
Lorsque vous recherchez l'intersection de colonnes numériques. Par exemple, considérons une table stockant les heures de début et de fin des événements. Les index de recherche peuvent implémenter efficacement une requête qui recherche des événements ayant eu lieu à un moment précis : start_time <= @p AND
end_time > @p.
Dans Spanner, la recherche en texte intégral nécessite les étapes suivantes :
Tokenisez un document à l'aide des fonctions de tokenisation Spanner, telles que TOKENIZE_SUBSTRING.
Pour en savoir plus, consultez Tokenization.
Créez un index de recherche pour contenir les jetons à l'aide de l'instruction LDD CREATE SEARCH
INDEX. Pour en savoir plus, consultez Index de recherche.
Interrogez les documents de l'index de recherche à l'aide de la fonction SEARCH de Spanner. Pour en savoir plus, consultez la section Présentation des requêtes.
La recherche en texte intégral n'est pas compatible avec Assured Workloads.
Tarifs
Spanner ne facture pas de frais supplémentaires lorsque vous utilisez la recherche en texte intégral. Toutefois, l'implémentation de la recherche en texte intégral augmente les coûts en raison du besoin de ressources de calcul et de stockage supplémentaires.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/05 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/05 (UTC)."],[],[],null,["# Full-text search overview\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 what full-text search is and how it works.\n\nA full-text search lets you build an application that can search a table to find\nwords, phrases, or numbers, instead of just searching for exact matches in\nstructured fields. Full-text searches return the latest\ntransactionally-consistent committed data to your application. Spanner\nfull-text search capabilities also include making spelling corrections,\nautomating language detection of search input, and ranking search results.\nSpanner automatically expands text searches to include\napproximate word matching.\n\nYou need to create a search index on any columns that you want to make available\nfor full-text searches. Spanner analyzes the\ndata in those columns to identify individual words to add to the search index.\nSpanner updates the search index with new or modified data as soon as\nit's committed in the database.\n\nTypes of full-text search\n-------------------------\n\n- **Basic text search** : Searches for content using the entire or part of a word or phrase to reliably receive results. Example query predicates:\n - Matching all words \\[tricolor rat terrier\\]\n - Exact word or phrases \\[\"rat terrier\"\\]\n - Any of these words \\[miniature OR standard\\]\n - Word within close proximity \\[world AROUND(3) cup\\]\n - Substring \\[start\\*\\]\n- **Numeric search**: Performs numeric equality and inequality searches. Equality searches match a number. Range and inequality searches match a number within a specific range.\n- **n-gram-based search**: Matches words with spelling variations, including proper nouns and names. This type of search also helps to match query text with misspelled names, names with alternate spellings, and text with other spelling variations.\n- **Soundex searches**: Matches similar-sounding words.\n\nFull-text search features\n-------------------------\n\nSpanner full-text search has the following features:\n\n- **Ranked search results**: Computes a score to gauge how well a query matches a document (for example, giving a heavier weight for column_A). Use SQL expressions to customize ranking.\n- **Snippets**: Highlights the matching text in the search result.\n- **Global support** : Automatically supports tokenization in different languages, including [CJK](https://en.wikipedia.org/wiki/CJK_characters) segmentation. Manual specification of language lets you perform additional fine-tuning.\n- **Governance**: Finds every occurrence of specific words.\n- **Spelling correction**: Automatically corrects misspelled words in queries to match the correctly-spelled word in storage. For example, if the user searches for \"girafe\", the search finds documents with \"giraffe\".\n- **Contextual synonym addition, including stop words**: Automatically adds contextually-relevant synonyms to increase recall. For example, \"the house\" matches \"this house\" and \"cat picture\" matches \"kitty picture\".\n- **Contextual number translation to and from text**: Matches the textual version of a number to the numeric representation and vice-versa. For example, \"five cats\" matches \"5 cats\".\n- **Automatic plural conversion**: Matches \"cat\" to \"cats\".\n\nFull-text search concepts\n-------------------------\n\nFull-text search has the following key concepts:\n\n- A *document* refers to the searchable data in a given row.\n- A *token* refers to each word of a document that's stored in a search index.\n- A *tokenization* process splits a document into tokens.\n- A *tokenizer* is a SQL function used for tokenization.\n- An *inverted index* stores tokens. Use SQL queries to search the inverted index.\n\nUse case example for full-text search\n-------------------------------------\n\nTo understand full-text search, let's take a look at an application that\nuses a database to store songs for each singer. Each row is a single song. Each\nsong contains columns like title, lyrics, singer, and album. The application\nuses full-text search to let a user search for a song using natural language\nqueries:\n\n- The search supports queries that use the `OR` operator, like `Prince OR\n Camille`. Applications can directly feed the end user input from the search box into the SQL [`SEARCH`](/spanner/docs/full-text-search/query-overview#query_a_search_index) function (using the rquery syntax). For more information, see [Query a\n search\n index](/spanner/docs/full-text-search/query-overview#query_a_search_index).\n- Spanner uses search indexes to look for matching documents across different fields. For example, an application can issue a query to search for \"cry\" in the title, with \"so cold\" in the lyrics, and \"Prince\" as the singer.\n\nOther uses for search indexes\n-----------------------------\n\nSearch indexes have a variety of uses in addition to full-text search, such as\nthe following:\n\n- Indexing elements in array columns. Consider an application that uses an\n array column to store tags associated with an item. With search indexes, the\n application can efficiently look up rows containing a specific tag. For more\n information, see\n [Array tokenization](/spanner/docs/full-text-search/numeric-indexes#array-tokenization).\n\n \u003cbr /\u003e\n\n- Finding data that resides in the intersection of a set\n of query conditions. For example, you can use an arbitrary set of attributes\n (color, size, brand, rating, and so on) to search for a product in a\n catalog.\n\n- Using numeric search conditions, alone or in combination with full-text\n conditions. Some examples for when a search index is useful for numeric\n searches:\n\n - When it's combined with a full-text application. For example, to find an email with the subject **Picture** and size greater than 1 MB.\n - When it's part of an intersection of conditions described previously. For example, to find products where `color = \"yellow\" AND size = 14 AND\n rating \u003e= 4.5`.\n - When searching for the intersection of numeric columns. For example, consider a table storing event start and end times. Search indexes can efficiently implement a query that looks for events that took place at a particular point in time: `start_time \u003c= @p AND\n end_time \u003e @p`.\n\n For more information, see\n [Numeric indexes](/spanner/docs/full-text-search/numeric-indexes).\n\nFull-text search steps\n----------------------\n\nIn Spanner, full-text search requires the following steps:\n\n1. Tokenize a document using the Spanner tokenizer functions, such as [`TOKENIZE_SUBSTRING`](/spanner/docs/reference/standard-sql/search_functions#tokenize_substring). For more information, see [Tokenization](/spanner/docs/full-text-search/tokenization).\n2. Create a search index to hold the tokens using the [`CREATE SEARCH\n INDEX`](/spanner/docs/reference/standard-sql/data-definition-language#create-search-index) DDL statement. For more information, see [Search\n indexes](/spanner/docs/full-text-search/search-indexes).\n3. Query documents in the search index using the Spanner [`SEARCH`](/spanner/docs/reference/standard-sql/search_functions#search_fulltext) function. For more information, see [Query\n overview](/spanner/docs/full-text-search/query-overview).\n4. Rank the results of the query using the Spanner [`SCORE`](/spanner/docs/reference/standard-sql/search_functions#score) function. For more information, see [Rank search\n results](/spanner/docs/full-text-search/ranked-search).\n\nLimitations\n-----------\n\n- Full-text search doesn't support [Assured Workloads](/assured-workloads/docs/overview).\n\nPricing\n-------\n\nThere are no additional charges from Spanner when you use\nfull-text search, although the implementation of full-text search\nincreases costs due to the need for additional compute and storage resources.\n\nFor more information, see [Spanner pricing](/spanner/pricing).\n\nWhat's next\n-----------\n\n- Learn about [tokenization and Spanner tokenizers](/spanner/docs/full-text-search/tokenization).\n- Learn about [search indexes](/spanner/docs/full-text-search/search-indexes).\n- Learn about [full-text search queries](/spanner/docs/full-text-search/query-overview)."]]