{"title":"PostgreSQL specific lookups","version":"2.1","locale":"ja","docname":"ref/contrib/postgres/lookups","url":"/ja/2.1/ref/contrib/postgres/lookups/","canonical":"https://djangodocs.dev/ja/2.1/ref/contrib/postgres/lookups/","summary":"The trigram_similar lookup allows you to perform trigram lookups, measuring the number of trigrams (three consecutive characters) shared, using a dedicated…","html":"<h1>PostgreSQL specific lookups<a class=\"heading-anchor\" href=\"#postgresql-specific-lookups\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<section id=\"trigram-similarity\">\n<h2>Trigram similarity<a class=\"heading-anchor\" href=\"#trigram-similarity\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p id=\"std-fieldlookup-trigram_similar\">The <code class=\"docutils literal notranslate\">trigram_similar</code> lookup allows you to perform trigram lookups,\nmeasuring the number of trigrams (three consecutive characters) shared, using a\ndedicated PostgreSQL extension. A trigram lookup is given an expression and\nreturns results that have a similarity measurement greater than the current\nsimilarity threshold.</p>\n<p>To use it, add <code class=\"docutils literal notranslate\">'django.contrib.postgres'</code> in your <a class=\"reference internal\" href=\"/ja/2.1/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\">INSTALLED_APPS</code></a>\nand activate the <a class=\"reference external\" href=\"https://www.postgresql.org/docs/current/static/pgtrgm.html\">pg_trgm extension</a> on\nPostgreSQL. You can install the extension using the\n<a class=\"reference internal\" href=\"/ja/2.1/ref/contrib/postgres/operations/#django.contrib.postgres.operations.TrigramExtension\" title=\"django.contrib.postgres.operations.TrigramExtension\"><code class=\"xref py py-class docutils literal notranslate\">TrigramExtension</code></a> migration\noperation.</p>\n<p>The <code class=\"docutils literal notranslate\">trigram_similar</code> lookup can be used on\n<a class=\"reference internal\" href=\"/ja/2.1/ref/models/fields/#django.db.models.CharField\" title=\"django.db.models.CharField\"><code class=\"xref py py-class docutils literal notranslate\">CharField</code></a> and <a class=\"reference internal\" href=\"/ja/2.1/ref/models/fields/#django.db.models.TextField\" title=\"django.db.models.TextField\"><code class=\"xref py py-class docutils literal notranslate\">TextField</code></a>:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"gp\">&gt;&gt;&gt; </span>City<span class=\"o\">.</span>objects<span class=\"o\">.</span>filter<span class=\"p\">(</span>name__trigram_similar<span class=\"o\">=</span><span class=\"s2\">&quot;Middlesborough&quot;</span><span class=\"p\">)</span>\n<span class=\"go\">[&#39;&lt;City: Middlesbrough&gt;&#39;]</span>\n</code></pre></div>\n</section>\n<section id=\"unaccent\">\n<h2><code class=\"docutils literal notranslate\">Unaccent</code><a class=\"heading-anchor\" href=\"#unaccent\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p id=\"std-fieldlookup-unaccent\">The <code class=\"docutils literal notranslate\">unaccent</code> lookup allows you to perform accent-insensitive lookups using\na dedicated PostgreSQL extension.</p>\n<p>This lookup is implemented using <a class=\"reference internal\" href=\"/ja/2.1/ref/models/lookups/#django.db.models.Transform\" title=\"django.db.models.Transform\"><code class=\"xref py py-class docutils literal notranslate\">Transform</code></a>, so it\ncan be chained with other lookup functions. To use it, you need to add\n<code class=\"docutils literal notranslate\">'django.contrib.postgres'</code> in your <a class=\"reference internal\" href=\"/ja/2.1/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\">INSTALLED_APPS</code></a> and activate\nthe <a class=\"reference external\" href=\"https://www.postgresql.org/docs/current/static/unaccent.html\">unaccent extension on PostgreSQL</a>. The\n<a class=\"reference internal\" href=\"/ja/2.1/ref/contrib/postgres/operations/#django.contrib.postgres.operations.UnaccentExtension\" title=\"django.contrib.postgres.operations.UnaccentExtension\"><code class=\"xref py py-class docutils literal notranslate\">UnaccentExtension</code></a> migration\noperation is available if you want to perform this activation using migrations).</p>\n<p>The <code class=\"docutils literal notranslate\">unaccent</code> lookup can be used on\n<a class=\"reference internal\" href=\"/ja/2.1/ref/models/fields/#django.db.models.CharField\" title=\"django.db.models.CharField\"><code class=\"xref py py-class docutils literal notranslate\">CharField</code></a> and <a class=\"reference internal\" href=\"/ja/2.1/ref/models/fields/#django.db.models.TextField\" title=\"django.db.models.TextField\"><code class=\"xref py py-class docutils literal notranslate\">TextField</code></a>:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"gp\">&gt;&gt;&gt; </span>City<span class=\"o\">.</span>objects<span class=\"o\">.</span>filter<span class=\"p\">(</span>name__unaccent<span class=\"o\">=</span><span class=\"s2\">&quot;México&quot;</span><span class=\"p\">)</span>\n<span class=\"go\">[&#39;&lt;City: Mexico&gt;&#39;]</span>\n\n<span class=\"gp\">&gt;&gt;&gt; </span>User<span class=\"o\">.</span>objects<span class=\"o\">.</span>filter<span class=\"p\">(</span>first_name__unaccent__startswith<span class=\"o\">=</span><span class=\"s2\">&quot;Jerem&quot;</span><span class=\"p\">)</span>\n<span class=\"go\">[&#39;&lt;User: Jeremy&gt;&#39;, &#39;&lt;User: Jérémy&gt;&#39;, &#39;&lt;User: Jérémie&gt;&#39;, &#39;&lt;User: Jeremie&gt;&#39;]</span>\n</code></pre></div>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">警告</p>\n<p><code class=\"docutils literal notranslate\">unaccent</code> lookups should perform fine in most use cases. However, queries\nusing this filter will generally perform full table scans, which can be slow\non large tables. In those cases, using dedicated full text indexing tools\nmight be appropriate.</p>\n</aside>\n</section>","rootId":"postgresql-specific-lookups","toc":[{"title":"Trigram similarity","anchor":"trigram-similarity","children":[]},{"title":"Unaccent","anchor":"unaccent","children":[]}],"breadcrumbs":[{"docname":"ref/index","title":"API Reference","url":"/ja/2.1/ref/"},{"docname":"ref/contrib/index","title":"contrib packages","url":"/ja/2.1/ref/contrib/"},{"docname":"ref/contrib/postgres/index","title":"django.contrib.postgres","url":"/ja/2.1/ref/contrib/postgres/"}],"prev":{"docname":"ref/contrib/postgres/indexes","title":"PostgreSQL specific model indexes","url":"/ja/2.1/ref/contrib/postgres/indexes/"},"next":{"docname":"ref/contrib/postgres/operations","title":"Database migration operations","url":"/ja/2.1/ref/contrib/postgres/operations/"},"formats":{"html":"/ja/2.1/ref/contrib/postgres/lookups/","markdown":"/ja/2.1/ref/contrib/postgres/lookups.md","json":"/ja/2.1/ref/contrib/postgres/lookups.json"},"source":"https://github.com/django/django/blob/stable/2.1.x/docs/ref/contrib/postgres/lookups.txt","official":"https://docs.djangoproject.com/ja/2.1/ref/contrib/postgres/lookups/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0","1.11","1.10","1.9"],"inLocales":["en","zh-hans","fr","ja","id","pt-br","ko","es","el","pl"]}