---
title: "Pencarian khusus PostgreSQL"
version: 6.1
locale: id
source: https://docs.djangoproject.com/id/6.1/ref/contrib/postgres/lookups/
canonical: https://djangodocs.dev/id/6.1/ref/contrib/postgres/lookups/
---
# Pencarian khusus PostgreSQL

## Kemiripan trigram

### `trigram_similar`

Pencarian `trigram_similar` mengizinkan anda melakukan pencarian triagram, mengukur angka dari triagram (tiga karakter berurutan) dibagi, menggunakan tambahan PostgreSQL keseluruhan. Sebuah pencarian triagram diberikan sebuah pernyataan dan mengembalikan hasil bahwa mempunyai pengukuran kemiripan lebih besar dari ambang kemiripan saat ini.

To use it, add `'django.contrib.postgres'` in your [`INSTALLED_APPS`](/id/6.1/ref/settings/#std-setting-INSTALLED_APPS)
and activate the [pg\_trgm extension](https://www.postgresql.org/docs/current/pgtrgm.html) on PostgreSQL. You can install the
extension using the
[`TrigramExtension`](/id/6.1/ref/contrib/postgres/operations/#django.contrib.postgres.operations.TrigramExtension) migration
operation.

The `trigram_similar` lookup can be used on
[`CharField`](/id/6.1/ref/models/fields/#django.db.models.CharField) and [`TextField`](/id/6.1/ref/models/fields/#django.db.models.TextField):

```pycon
>>> City.objects.filter(name__trigram_similar="Middlesborough")
<QuerySet [<City: Middlesbrough>]>
```

### `trigram_word_similar`

The `trigram_word_similar` lookup allows you to perform trigram word
similarity lookups using a dedicated PostgreSQL extension. It can be
approximately understood as measuring the greatest number of trigrams shared
between the parameter and any substring of the field. A trigram word lookup is
given an expression and returns results that have a word similarity measurement
greater than the current similarity threshold.

To use it, add `'django.contrib.postgres'` in your [`INSTALLED_APPS`](/id/6.1/ref/settings/#std-setting-INSTALLED_APPS)
and activate the [pg\_trgm extension](https://www.postgresql.org/docs/current/pgtrgm.html) on PostgreSQL. You can install the
extension using the
[`TrigramExtension`](/id/6.1/ref/contrib/postgres/operations/#django.contrib.postgres.operations.TrigramExtension) migration
operation.

The `trigram_word_similar` lookup can be used on
[`CharField`](/id/6.1/ref/models/fields/#django.db.models.CharField) and [`TextField`](/id/6.1/ref/models/fields/#django.db.models.TextField):

```pycon
>>> Sentence.objects.filter(name__trigram_word_similar="Middlesborough")
<QuerySet [<Sentence: Gumby rides on the path of Middlesbrough>]>
```

### `trigram_strict_word_similar`

Similar to [`trigram_word_similar`](#std-fieldlookup-trigram_word_similar), except that it forces extent
boundaries to match word boundaries.

To use it, add `'django.contrib.postgres'` in your [`INSTALLED_APPS`](/id/6.1/ref/settings/#std-setting-INSTALLED_APPS)
and activate the [pg\_trgm extension](https://www.postgresql.org/docs/current/pgtrgm.html) on PostgreSQL. You can install the
extension using the
[`TrigramExtension`](/id/6.1/ref/contrib/postgres/operations/#django.contrib.postgres.operations.TrigramExtension) migration
operation.

The `trigram_strict_word_similar` lookup can be used on
[`CharField`](/id/6.1/ref/models/fields/#django.db.models.CharField) and [`TextField`](/id/6.1/ref/models/fields/#django.db.models.TextField).

## `Unaccent`

Pencarian `unaccent` mengizinkan anda melakukan pencarian aksen-peka menggunakan tambahan PostgreSQL khusus.

This lookup is implemented using [`Transform`](/id/6.1/ref/models/lookups/#django.db.models.Transform), so it
can be chained with other lookup functions. To use it, you need to add
`'django.contrib.postgres'` in your [`INSTALLED_APPS`](/id/6.1/ref/settings/#std-setting-INSTALLED_APPS) and activate
the [unaccent extension on PostgreSQL](https://www.postgresql.org/docs/current/unaccent.html). The
[`UnaccentExtension`](/id/6.1/ref/contrib/postgres/operations/#django.contrib.postgres.operations.UnaccentExtension) migration
operation is available if you want to perform this activation using
migrations.

The `unaccent` lookup can be used on
[`CharField`](/id/6.1/ref/models/fields/#django.db.models.CharField) and [`TextField`](/id/6.1/ref/models/fields/#django.db.models.TextField):

```pycon
>>> City.objects.filter(name__unaccent="México")
<QuerySet [<City: Mexico>]>

>>> User.objects.filter(first_name__unaccent__startswith="Jerem")
<QuerySet [<User: Jeremy>, <User: Jérémy>, <User: Jérémie>, <User: Jeremie>]>
```

> **Warning**
>
> Pencarian `unaccent` harus tampil baik dalam kebanyakan pengunaan kasus. Bagaimanapun, permintaan menggunakan penyaring ini akan umumnya melakukan pemindaian tabel penuh, yang dapat melambatkan pada tabel-tabel besar. Dalam kasus-kasus tersebut, menggunakan alat-alat pengindeksan teks penuh yang berdedikasi mungkin sesuai.
