{"id":1211,"date":"2024-12-23T15:41:47","date_gmt":"2024-12-23T08:41:47","guid":{"rendered":"https:\/\/www.pgtutorial.com\/?page_id=1211"},"modified":"2025-01-03T11:32:39","modified_gmt":"2025-01-03T04:32:39","slug":"postgresql-full-text-search","status":"publish","type":"page","link":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-full-text-search\/","title":{"rendered":"PostgreSQL Full-text Search"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you&#8217;ll explore the PostgreSQL full-text search feature and how to implement it in your databases.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='introduction-to-postgresql-full-text-search'>Introduction to PostgreSQL full-text search <a href=\"#introduction-to-postgresql-full-text-search\" class=\"anchor\" id=\"introduction-to-postgresql-full-text-search\" title=\"Anchor for Introduction to PostgreSQL full-text search\">#<\/a><\/h2>\n\n\n\n<p>So far, you&#8217;ve learned how to find the text exactly using the <code><a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-where\/\">WHERE<\/a><\/code> clause with the equal operator (<code>=<\/code>):<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  column1,\n  column2\n<span class=\"hljs-keyword\">FROM<\/span>\n  <span class=\"hljs-built_in\">table_name<\/span>\n<span class=\"hljs-keyword\">WHERE<\/span>\n  <span class=\"hljs-built_in\">column_name<\/span> = <span class=\"hljs-string\">'search_term'<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>And match the text based on a specified pattern using the <code><a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-like\/\">LIKE<\/a><\/code> operator:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  column1,\n  column2\n<span class=\"hljs-keyword\">FROM<\/span>\n  <span class=\"hljs-built_in\">table_name<\/span>\n<span class=\"hljs-keyword\">WHERE<\/span>\n  <span class=\"hljs-built_in\">column_name<\/span> <span class=\"hljs-keyword\">LIKE<\/span> pattern;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>If the exact match and pattern matching are not sufficient, you can go with <a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-regular-expressions\/\">regular expressions<\/a> or using the <code><a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-similar-to\/\">SIMILAR TO<\/a><\/code> operator:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  column1,\n  column2\n<span class=\"hljs-keyword\">FROM<\/span>\n  <span class=\"hljs-built_in\">table_name<\/span>\n<span class=\"hljs-keyword\">WHERE<\/span>\n  column1 <span class=\"hljs-keyword\">SIMILAR<\/span> <span class=\"hljs-keyword\">TO<\/span> pattern;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>You can use the full-text search if these options do not meet your requirements.<\/p>\n\n\n\n<p>In PostgreSQL, full-text search is a powerful feature that allows you to carry complex searches on text. It efficiently searches and ranks text-based data by indexing their words and phrases.<\/p>\n\n\n\n<p>For example, if you find <em>documents<\/em> that contain the word &#8220;advance,&#8221; the full-text search will return the documents with the words <code>\"advance\"<\/code> , <code>\"advancing\"<\/code> , and <code>\"advanced\"<\/code>.<\/p>\n\n\n\n<p>A document is the basic unit of text you want to search through in a full-text search. It can be a column of a table or a combination of columns from multiple tables.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='postgresql-full-text-search-data-types'>PostgreSQL full-text search data types <a href=\"#postgresql-full-text-search-data-types\" class=\"anchor\" id=\"postgresql-full-text-search-data-types\" title=\"Anchor for PostgreSQL full-text search data types\">#<\/a><\/h2>\n\n\n\n<p>PostgreSQL provides two specific data types to support full-text searches: <code>tsvector<\/code>and <code>tsquery<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='tsvector-data-type'>tsvector data type <a href=\"#tsvector-data-type\" class=\"anchor\" id=\"tsvector-data-type\" title=\"Anchor for tsvector data type\">#<\/a><\/h3>\n\n\n\n<p>The <code>tsvector<\/code> is a data type that supports full-text search. It represents a document optimized for text search by storing a sorted list of distinct normalized words.<\/p>\n\n\n\n<p>The technical terms of the normalized words are <em>lexemes<\/em>. Lexemes are words without variations, such as <code>teaches<\/code> and <code>teaching<\/code> words have the lexeme <code>teach<\/code>.<\/p>\n\n\n\n<p>To convert a regular string to a tsvector, you use the to_tsvector function. For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  to_tsvector(<span class=\"hljs-string\">'teaches'<\/span>),\n  to_tsvector(<span class=\"hljs-string\">'teaching'<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=U0VMRUNUIHRvX3RzdmVjdG9yKCd0ZWFjaGVzJyksIHRvX3RzdmVjdG9yKCd0ZWFjaGluZycpOw%3D%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"> to_tsvector | to_tsvector\n<span class=\"hljs-comment\">-------------+-------------<\/span>\n <span class=\"hljs-string\">'teach'<\/span>:<span class=\"hljs-number\">1<\/span>   | <span class=\"hljs-string\">'teach'<\/span>:<span class=\"hljs-number\">1<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this example, the <code>to_tsvector<\/code> function converts the words teaches and teaching to the word teach.<\/p>\n\n\n\n<p>The <code>tsvector<\/code> data type has the following features:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Lexemes<\/strong>: normalizes the words to merge their variants into the same word.<\/li>\n\n\n\n<li><strong>Sorting and deduplication<\/strong>: automatically sorts the lexemes and removes duplicates before storing them in the table.<\/li>\n\n\n\n<li><strong>Positional information<\/strong>: adds positions of the lexemes in the document and then uses them for proximity ranking.<\/li>\n\n\n\n<li><strong>Weights<\/strong>: PostgreSQL allows you to label lexemes with weights (<code>A<\/code>, <code>B<\/code>, <code>C<\/code>, or <code>D<\/code>) to emphasize their importance.<\/li>\n<\/ul>\n\n\n\n<p>For example, the following statement uses the <code>to_tsvector<\/code> to parse the text into tokens, reduces them to lexemes, and returns a <code>tsvector<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  to_tsvector(\n    <span class=\"hljs-string\">'The big blue elephant jumps over the lazy dog. The big blue elephant is very big'<\/span>\n  );<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=U0VMRUNUIHRvX3RzdmVjdG9yKCAnVGhlIGJpZyBibHVlIGVsZXBoYW50IGp1bXBzIG92ZXIgdGhlIGxhenkgZG9nLiBUaGUgYmlnIGJsdWUgZWxlcGhhbnQgaXMgdmVyeSBiaWcnICk7\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">                           to_tsvector\n<span class=\"hljs-comment\">------------------------------------------------------------------<\/span>\n <span class=\"hljs-string\">'big'<\/span>:<span class=\"hljs-number\">2<\/span>,<span class=\"hljs-number\">11<\/span>,<span class=\"hljs-number\">16<\/span> <span class=\"hljs-string\">'blue'<\/span>:<span class=\"hljs-number\">3<\/span>,<span class=\"hljs-number\">12<\/span> <span class=\"hljs-string\">'dog'<\/span>:<span class=\"hljs-number\">9<\/span> <span class=\"hljs-string\">'eleph'<\/span>:<span class=\"hljs-number\">4<\/span>,<span class=\"hljs-number\">13<\/span> <span class=\"hljs-string\">'jump'<\/span>:<span class=\"hljs-number\">5<\/span> <span class=\"hljs-string\">'lazi'<\/span>:<span class=\"hljs-number\">8<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Explanation:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Lexemes<\/strong>: The function normalizes the words such as <code>\"elephant\"<\/code>becomes <code>\"eleph\"<\/code>, <code>\"jumps\"<\/code> becomes <code>\"jump\"<\/code> and removes the stop words like <code>\"The\"<\/code> and <code>\"is\"<\/code>.<\/li>\n\n\n\n<li><strong>Sorting and deduplication<\/strong>: The function sorts the lexemes alphabetically.<\/li>\n\n\n\n<li><strong>Positional information<\/strong>: The function adds the position of each lexeme in the document. For example, the word <code>\"big\"<\/code> appears at positions <code>2<\/code>, <code>11<\/code> and <code>16<\/code>.<\/li>\n<\/ul>\n\n\n\n<p class=\"note\">To set the weights to lexemes, you can use the <code>setweight<\/code> function, which is in the scope of this tutorial.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='tsquery-data-type'>tsquery data type <a href=\"#tsquery-data-type\" class=\"anchor\" id=\"tsquery-data-type\" title=\"Anchor for tsquery data type\">#<\/a><\/h3>\n\n\n\n<p>PostgreSQL uses the <code>tsquery<\/code> data type to represent full-text search queries.<\/p>\n\n\n\n<p>The <code>tsquery<\/code> supports the following main features:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Boolean operators<\/strong>: a <code>tsquery<\/code> supports the logical operator AND (<code>&amp;<\/code>), OR (<code>|<\/code>), and NOT (<code>!<\/code>). For example, you can use the boolean operators to search for documents that contain the word <code>\"elephant\"<\/code> and the word <code>\"blue\"<\/code> but not the word <code>\"dolphin\"<\/code>.<\/li>\n\n\n\n<li><strong>Phrase search<\/strong>: Use double quotes (<code>\"<\/code>) to ensure that the enclosing words must appear together in the document in the same order. For example, the search term <code>\"big elephant\"<\/code>, the phrase <code>\"big elephant\"<\/code> must appear as a whole within the document.<\/li>\n\n\n\n<li><strong>Grouping<\/strong>: <code>tsquery<\/code> uses the parentheses <code>()<\/code> to group terms and operators, allowing you to form flexible search conditions.<\/li>\n<\/ul>\n\n\n\n<p>For example, the following shows a text string that a <code>tsquery<\/code> represents:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">\"blue\" &amp; \"elephant\" |\"dolphin\"<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This&nbsp;<code>tsquery<\/code>&nbsp;forms a query that searches for the documents containing the words <code>\"blue\"<\/code> and <code>\"elephant\"<\/code> or the word <code>\"dolphin\"<\/code>.<\/p>\n\n\n\n<p>To convert a string to a <code>tsquery<\/code> value, you use the <code>to_tsquery<\/code> function. For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span> to_tsquery(<span class=\"hljs-string\">'\"blue\" &amp; \"elephant\" |\"dolphin\"'<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=U0VMRUNUIHRvX3RzcXVlcnkoJyJibHVlIiAmICJlbGVwaGFudCIgfCJkb2xwaGluIicpOw%3D%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">          to_tsquery\n<span class=\"hljs-comment\">------------------------------<\/span>\n <span class=\"hljs-string\">'blue'<\/span> &amp; <span class=\"hljs-string\">'eleph'<\/span> | <span class=\"hljs-string\">'dolphin'<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id='match-operator'>Match operator (@@) <a href=\"#match-operator\" class=\"anchor\" id=\"match-operator\" title=\"Anchor for Match operator (@@)\">#<\/a><\/h3>\n\n\n\n<p>PostgreSQL uses the match operator <code>(@@<\/code>) to match a <code>tsvector<\/code> against a <code>tsquery<\/code> to determine if the text the <code>tsvector<\/code> represents contains the terms specified in the <code>tsquery<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-type\">tsvector<\/span> @@ <span class=\"hljs-type\">tsquery<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  to_tsvector(<span class=\"hljs-string\">'The big blue elephant jumps over the lazy dog.'<\/span>) @@ to_tsquery(<span class=\"hljs-string\">'elephant'<\/span>) result;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=U0VMRUNUIHRvX3RzdmVjdG9yKCdUaGUgYmlnIGJsdWUgZWxlcGhhbnQganVtcHMgb3ZlciB0aGUgbGF6eSBkb2cuJykgQEAgdG9fdHNxdWVyeSgnZWxlcGhhbnQnKSByZXN1bHQ7\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"> result\n<span class=\"hljs-comment\">--------<\/span>\n t<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>It&#8217;s possible to use a value of <code><a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-char\/\">CHAR<\/a><\/code>, <code><a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-varchar\/\">VARCHAR<\/a><\/code>, and <code><a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-text\/\">TEXT<\/a><\/code> with the match operator:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-14\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-type\">text<\/span> @@ <span class=\"hljs-type\">tsquery<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-14\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this case, PostgreSQL will <em>implicitly convert<\/em> the text to the <code>tsvector<\/code> before matching with the <code>tsquery<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='postgresql-full-text-search-examples'>PostgreSQL full-text search examples <a href=\"#postgresql-full-text-search-examples\" class=\"anchor\" id=\"postgresql-full-text-search-examples\" title=\"Anchor for PostgreSQL full-text search examples\">#<\/a><\/h2>\n\n\n\n<p>Let&#8217;s explore some examples of using PostgreSQL full-text searches with <code>description<\/code> column of the <code>products<\/code> table:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"159\" height=\"254\" src=\"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2024\/12\/products.png\" alt=\"PostgreSQL Full-text Search - The products Table\" class=\"wp-image-1051\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id='0-creating-gin-indexes'>0) Creating GIN indexes <a href=\"#0-creating-gin-indexes\" class=\"anchor\" id=\"0-creating-gin-indexes\" title=\"Anchor for 0) Creating GIN indexes\">#<\/a><\/h3>\n\n\n\n<p>PostgreSQL provides the GIN index explicitly designed for full-text search. GIN stands for Generalized Inverted Index.<\/p>\n\n\n\n<p>We&#8217;ll create a GIN index for the <code>description<\/code> column of the <code>products<\/code> table to enable full-text search.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-15\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">INDEX<\/span> fts_products_description\n<span class=\"hljs-keyword\">ON<\/span> products\n<span class=\"hljs-keyword\">USING<\/span> GIN ((to_tsvector(<span class=\"hljs-string\">'english'<\/span>, description)));<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-15\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=Q1JFQVRFIElOREVYIGZ0c19wcm9kdWN0c19kZXNjcmlwdGlvbiBPTiBwcm9kdWN0cyBVU0lORyBHSU4gKCh0b190c3ZlY3RvcignZW5nbGlzaCcsIGRlc2NyaXB0aW9uKSkpOw%3D%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='1-performing-a-basic-full-text-search'>1) Performing a basic full-text search <a href=\"#1-performing-a-basic-full-text-search\" class=\"anchor\" id=\"1-performing-a-basic-full-text-search\" title=\"Anchor for 1) Performing a basic full-text search\">#<\/a><\/h3>\n\n\n\n<p>The following example searches for products whose description contains the word power and its variations such as powerful:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-16\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  product_name,\n  description\n<span class=\"hljs-keyword\">FROM<\/span>\n  products\n<span class=\"hljs-keyword\">WHERE<\/span>\n  description @@ to_tsquery(<span class=\"hljs-string\">'power'<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-16\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=U0VMRUNUIHByb2R1Y3RfbmFtZSwgZGVzY3JpcHRpb24gRlJPTSBwcm9kdWN0cyBXSEVSRSBkZXNjcmlwdGlvbiBAQCB0b190c3F1ZXJ5KCdwb3dlcicpOw%3D%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='2-performing-full-text-searches-with-the-and-operator'>2) Performing full-text searches with the AND operator <a href=\"#2-performing-full-text-searches-with-the-and-operator\" class=\"anchor\" id=\"2-performing-full-text-searches-with-the-and-operator\" title=\"Anchor for 2) Performing full-text searches with the AND operator\">#<\/a><\/h3>\n\n\n\n<p>The following statement uses the AND operator (&amp;) to search for products whose descriptions contain both words &#8220;powerful&#8221; and &#8220;advanced&#8221;:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-17\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  product_name,\n  description\n<span class=\"hljs-keyword\">FROM<\/span>\n  products\n<span class=\"hljs-keyword\">WHERE<\/span>\n  description @@ to_tsquery(<span class=\"hljs-string\">'power &amp; large'<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-17\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=U0VMRUNUIHByb2R1Y3RfbmFtZSwgZGVzY3JpcHRpb24gRlJPTSBwcm9kdWN0cyBXSEVSRSBkZXNjcmlwdGlvbiBAQCB0b190c3F1ZXJ5KCdwb3dlciAmIGxhcmdlJyk7\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='3-performing-full-text-searches-with-or-operator'>3) Performing full-text searches with OR operator <a href=\"#3-performing-full-text-searches-with-or-operator\" class=\"anchor\" id=\"3-performing-full-text-searches-with-or-operator\" title=\"Anchor for 3) Performing full-text searches with OR operator\">#<\/a><\/h3>\n\n\n\n<p>The following statement uses the OR operator (|) to search for products with a description containing either the word&nbsp;&#8220;large&#8221;&nbsp;or&nbsp;&#8220;great&#8221;:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-18\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  product_name,\n  description\n<span class=\"hljs-keyword\">FROM<\/span>\n  products\n<span class=\"hljs-keyword\">WHERE<\/span>\n  description @@ to_tsquery(<span class=\"hljs-string\">'large| great'<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-18\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=U0VMRUNUIHByb2R1Y3RfbmFtZSwgZGVzY3JpcHRpb24gRlJPTSBwcm9kdWN0cyBXSEVSRSBkZXNjcmlwdGlvbiBAQCB0b190c3F1ZXJ5KCdsYXJnZXwgZ3JlYXQnKTs%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='4-performing-phrase-searches'>4) Performing phrase searches <a href=\"#4-performing-phrase-searches\" class=\"anchor\" id=\"4-performing-phrase-searches\" title=\"Anchor for 4) Performing phrase searches\">#<\/a><\/h3>\n\n\n\n<p>The following statement searches for products with a description containing the phrase &#8220;sleek design&#8221;:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-19\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  product_name,\n  description\n<span class=\"hljs-keyword\">FROM<\/span>\n  products\n<span class=\"hljs-keyword\">WHERE<\/span>\n  description @@ to_tsquery(<span class=\"hljs-string\">'''sleek design'''<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-19\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=U0VMRUNUIHByb2R1Y3RfbmFtZSwgZGVzY3JpcHRpb24gRlJPTSBwcm9kdWN0cyBXSEVSRSBkZXNjcmlwdGlvbiBAQCB0b190c3F1ZXJ5KCcnJ3NsZWVrIGRlc2lnbicnJyk7\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='5-performing-full-text-searches-with-the-not-operator'>5) Performing full-text searches with the NOT operator <a href=\"#5-performing-full-text-searches-with-the-not-operator\" class=\"anchor\" id=\"5-performing-full-text-searches-with-the-not-operator\" title=\"Anchor for 5) Performing full-text searches with the NOT operator\">#<\/a><\/h3>\n\n\n\n<p>The following statement uses the NOT operator (!) to search for products with descriptions that do not contain the word &#8220;features&#8221;:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-20\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  product_name,\n  description\n<span class=\"hljs-keyword\">FROM<\/span>\n  products\n<span class=\"hljs-keyword\">WHERE<\/span>\n  description @@ to_tsquery(<span class=\"hljs-string\">'!features'<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-20\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=U0VMRUNUIHByb2R1Y3RfbmFtZSwgZGVzY3JpcHRpb24gRlJPTSBwcm9kdWN0cyBXSEVSRSBkZXNjcmlwdGlvbiBAQCB0b190c3F1ZXJ5KCchZmVhdHVyZXMnKTs%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='summary'>Summary <a href=\"#summary\" class=\"anchor\" id=\"summary\" title=\"Anchor for Summary\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use PostgreSQL full-text search to perform complex searches on text stored in the database.<\/li>\n\n\n\n<li>Use <code>tsvector<\/code> data type to store documents for full-text search.<\/li>\n\n\n\n<li>Use <code>tsquery<\/code> data type to store full-text search queries.<\/li>\n\n\n\n<li>Use the match operator (<code>@@<\/code>) to match a <code>tsquery<\/code> against to check if the text the <code>tsvector<\/code> represents contains the terms specified in the <code>tsquery<\/code>.<\/li>\n\n\n\n<li>Use&nbsp;GIN&nbsp;indexes to index columns for full-text searches.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id='quiz'>Quiz <a href=\"#quiz\" class=\"anchor\" id=\"quiz\" title=\"Anchor for Quiz\">#<\/a><\/h2>\n\n\n\n<iframe loading=\"lazy\"\n  name=\"quiz\"\n  src=\"\/quiz\/?quiz=fts\"\n  height=\"700\"\n  width=\"600\"\n  class=\"iframe\"\n><\/iframe>\n\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful ?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"1211\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-full-text-search\/\"\n\t\t\t\tdata-post-title=\"PostgreSQL Full-text Search\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"1211\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-full-text-search\/\"\n\t\t\t\tdata-post-title=\"PostgreSQL Full-text Search\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you&#8217;ll explore the PostgreSQL full-text search feature and how to implement it in your databases.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":13,"menu_order":77,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1211","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PostgreSQL Full-text Search<\/title>\n<meta name=\"description\" content=\"In this tutorial, you&#039;ll explore the PostgreSQL full-text search feature and how to implement it in your databases.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-full-text-search\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PostgreSQL Full-text Search\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, you&#039;ll explore the PostgreSQL full-text search feature and how to implement it in your databases.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-full-text-search\/\" \/>\n<meta property=\"og:site_name\" content=\"PostgreSQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-03T04:32:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2024\/12\/products.png\" \/>\n\t<meta property=\"og:image:width\" content=\"159\" \/>\n\t<meta property=\"og:image:height\" content=\"254\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-full-text-search\\\/\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-full-text-search\\\/\",\"name\":\"PostgreSQL Full-text Search\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-full-text-search\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-full-text-search\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pgtutorial.com\\\/wp-content\\\/uploads\\\/2024\\\/12\\\/products.png\",\"datePublished\":\"2024-12-23T08:41:47+00:00\",\"dateModified\":\"2025-01-03T04:32:39+00:00\",\"description\":\"In this tutorial, you'll explore the PostgreSQL full-text search feature and how to implement it in your databases.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-full-text-search\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-full-text-search\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-full-text-search\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/wp-content\\\/uploads\\\/2024\\\/12\\\/products.png\",\"contentUrl\":\"https:\\\/\\\/www.pgtutorial.com\\\/wp-content\\\/uploads\\\/2024\\\/12\\\/products.png\",\"width\":159,\"height\":254,\"caption\":\"PostgreSQL Expression Index\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-full-text-search\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pgtutorial.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PostgreSQL Tutorial\",\"item\":\"https:\\\/\\\/www.pgtutorial.com\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"PostgreSQL Full-text Search\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/#website\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/\",\"name\":\"PostgreSQL Tutorial\",\"description\":\"Learn PostgreSQL from Scratch\",\"alternateName\":\"PostgreSQL\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pgtutorial.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PostgreSQL Full-text Search","description":"In this tutorial, you'll explore the PostgreSQL full-text search feature and how to implement it in your databases.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-full-text-search\/","og_locale":"en_US","og_type":"article","og_title":"PostgreSQL Full-text Search","og_description":"In this tutorial, you'll explore the PostgreSQL full-text search feature and how to implement it in your databases.","og_url":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-full-text-search\/","og_site_name":"PostgreSQL Tutorial","article_modified_time":"2025-01-03T04:32:39+00:00","og_image":[{"width":159,"height":254,"url":"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2024\/12\/products.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-full-text-search\/","url":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-full-text-search\/","name":"PostgreSQL Full-text Search","isPartOf":{"@id":"https:\/\/www.pgtutorial.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-full-text-search\/#primaryimage"},"image":{"@id":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-full-text-search\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2024\/12\/products.png","datePublished":"2024-12-23T08:41:47+00:00","dateModified":"2025-01-03T04:32:39+00:00","description":"In this tutorial, you'll explore the PostgreSQL full-text search feature and how to implement it in your databases.","breadcrumb":{"@id":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-full-text-search\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-full-text-search\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-full-text-search\/#primaryimage","url":"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2024\/12\/products.png","contentUrl":"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2024\/12\/products.png","width":159,"height":254,"caption":"PostgreSQL Expression Index"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-full-text-search\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pgtutorial.com\/"},{"@type":"ListItem","position":2,"name":"PostgreSQL Tutorial","item":"https:\/\/www.pgtutorial.com\/"},{"@type":"ListItem","position":3,"name":"PostgreSQL Full-text Search"}]},{"@type":"WebSite","@id":"https:\/\/www.pgtutorial.com\/#website","url":"https:\/\/www.pgtutorial.com\/","name":"PostgreSQL Tutorial","description":"Learn PostgreSQL from Scratch","alternateName":"PostgreSQL","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pgtutorial.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/1211","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/comments?post=1211"}],"version-history":[{"count":6,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/1211\/revisions"}],"predecessor-version":[{"id":1399,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/1211\/revisions\/1399"}],"up":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/13"}],"wp:attachment":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/media?parent=1211"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}