mirror of
https://github.com/supabase/supabase.git
synced 2026-05-24 04:00:47 +08:00
234 lines
4.4 KiB
Plaintext
234 lines
4.4 KiB
Plaintext
---
|
|
id: textsearch
|
|
title: ".textSearch()"
|
|
slug: textsearch
|
|
custom_edit_url: https://github.com/supabase/supabase/edit/master/web/spec/supabase.yml
|
|
---
|
|
|
|
import Tabs from '@theme/Tabs';
|
|
import TabsPanel from '@theme/TabsPanel';
|
|
|
|
Finds all rows whose tsvector value on the stated `column` matches
|
|
to_tsquery(`query`).
|
|
|
|
|
|
|
|
## Parameters
|
|
|
|
|
|
<ul className="method-list-group">
|
|
|
|
<li className="method-list-item">
|
|
<h4 className="method-list-item-label">
|
|
<span className="method-list-item-label-name">
|
|
column
|
|
</span>
|
|
<span className="method-list-item-label-badge required">
|
|
required
|
|
</span>
|
|
<span className="method-list-item-validation">
|
|
<code>object</code>
|
|
</span>
|
|
</h4>
|
|
<div class="method-list-item-description">
|
|
|
|
The column to filter on.
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
|
|
<li className="method-list-item">
|
|
<h4 className="method-list-item-label">
|
|
<span className="method-list-item-label-name">
|
|
query
|
|
</span>
|
|
<span className="method-list-item-label-badge required">
|
|
required
|
|
</span>
|
|
<span className="method-list-item-validation">
|
|
<code>string</code>
|
|
</span>
|
|
</h4>
|
|
<div class="method-list-item-description">
|
|
|
|
The Postgres tsquery string to filter with.
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
|
|
<li className="method-list-item">
|
|
<h4 className="method-list-item-label">
|
|
<span className="method-list-item-label-name">
|
|
__namedParameters
|
|
</span>
|
|
<span className="method-list-item-label-badge required">
|
|
required
|
|
</span>
|
|
<span className="method-list-item-validation">
|
|
<code>object</code>
|
|
</span>
|
|
</h4>
|
|
<div class="method-list-item-description">
|
|
|
|
No description provided.
|
|
|
|
</div>
|
|
|
|
<ul className="method-list-group">
|
|
<h5 class="method-list-title method-list-title-isChild expanded">Properties</h5>
|
|
|
|
<li className="method-list-item">
|
|
<h4 className="method-list-item-label">
|
|
<span className="method-list-item-label-name">
|
|
config
|
|
</span>
|
|
<span className="method-list-item-label-badge required">
|
|
required
|
|
</span>
|
|
<span className="method-list-item-validation">
|
|
<code>undefined</code> | <code>string</code>
|
|
</span>
|
|
</h4>
|
|
<div class="method-list-item-description">
|
|
|
|
The text search configuration to use.
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
### Text search
|
|
|
|
|
|
|
|
<Tabs
|
|
defaultActiveId="js"
|
|
groupId="reference/supabase-js"
|
|
values={[{ label: 'JavaScript', value: 'js' }]}>
|
|
|
|
<TabsPanel id="js" label="js">
|
|
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('quotes')
|
|
.select('catchphrase')
|
|
.textSearch('catchphrase', `'fat' & 'cat'`, {
|
|
config: 'english'
|
|
})
|
|
```
|
|
|
|
|
|
</TabsPanel>
|
|
|
|
</Tabs>
|
|
|
|
### Basic normalization
|
|
|
|
Uses PostgreSQL's `plainto_tsquery` function.
|
|
|
|
<Tabs
|
|
defaultActiveId="js"
|
|
groupId="reference/supabase-js"
|
|
values={[{ label: 'JavaScript', value: 'js' }]}>
|
|
|
|
<TabsPanel id="js" label="js">
|
|
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('quotes')
|
|
.select('catchphrase')
|
|
.textSearch('catchphrase', `'fat' & 'cat'`, {
|
|
type: 'plain',
|
|
config: 'english'
|
|
})
|
|
```
|
|
|
|
|
|
</TabsPanel>
|
|
|
|
</Tabs>
|
|
|
|
### Full normalization
|
|
|
|
Uses PostgreSQL's `phraseto_tsquery` function.
|
|
|
|
<Tabs
|
|
defaultActiveId="js"
|
|
groupId="reference/supabase-js"
|
|
values={[{ label: 'JavaScript', value: 'js' }]}>
|
|
|
|
<TabsPanel id="js" label="js">
|
|
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('quotes')
|
|
.select('catchphrase')
|
|
.textSearch('catchphrase', `'fat' & 'cat'`, {
|
|
type: 'phrase',
|
|
config: 'english'
|
|
})
|
|
```
|
|
|
|
|
|
</TabsPanel>
|
|
|
|
</Tabs>
|
|
|
|
### Full normalization
|
|
|
|
Uses PostgreSQL's `websearch_to_tsquery` function.
|
|
This function will never raise syntax errors, which makes it possible to use raw user-supplied input for search, and can be used
|
|
with advanced operators.
|
|
|
|
- `unquoted text`: text not inside quote marks will be converted to terms separated by & operators, as if processed by plainto_tsquery.
|
|
- `"quoted text"`: text inside quote marks will be converted to terms separated by <-> operators, as if processed by phraseto_tsquery.
|
|
- `OR`: the word “or” will be converted to the | operator.
|
|
- `-`: a dash will be converted to the ! operator.
|
|
|
|
|
|
<Tabs
|
|
defaultActiveId="js"
|
|
groupId="reference/supabase-js"
|
|
values={[{ label: 'JavaScript', value: 'js' }]}>
|
|
|
|
<TabsPanel id="js" label="js">
|
|
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('quotes')
|
|
.select('catchphrase')
|
|
.textSearch('catchphrase', `'fat or cat'`, {
|
|
type: 'websearch',
|
|
config: 'english'
|
|
})
|
|
```
|
|
|
|
|
|
</TabsPanel>
|
|
|
|
</Tabs> |