Last active
September 7, 2020 18:10
-
-
Save osw4l/dc210edd8dfab1a080cb428548e94da4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db.models import Transform | |
class Trigram(Transform): | |
bilateral = True | |
lookup_name = 'trigram' | |
def as_postgresql(self, compiler, connection): | |
lhs, params = compiler.compile(self.lhs) | |
return "TRIAGRAM(%s)" % lhs, params | |
class Unaccent(Transform): | |
bilateral = True | |
lookup_name = 'unaccent' | |
def as_postgresql(self, compiler, connection): | |
lhs, params = compiler.compile(self.lhs) | |
return "UNACCENT(%s)" % lhs, params | |
models.CharField.register_lookup(Unaccent) | |
models.TextField.register_lookup(Unaccent) | |
models.CharField.register_lookup(Trigram) | |
models.TextField.register_lookup(Trigram) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib.postgres.operations import TrigramExtension | |
from django.contrib.postgres.operations import UnaccentExtension | |
class Migration(migrations.Migration): | |
operations = [ | |
TrigramExtension(), | |
UnaccentExtension() | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE EXTENSION unaccent; | |
CREATE EXTENSION pg_trgm; | |
CREATE EXTENSION postgis; | |
CREATE TEXT SEARCH CONFIGURATION unaccent ( COPY = spanish ); | |
ALTER TEXT SEARCH CONFIGURATION unaccent ALTER MAPPING FOR hword, hword_part, word WITH unaccent, simple; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment