Search code examples
djangopostgresqlfull-text-search

Django: How to do full-text search for Japanese (multibyte strings) in Postgresql


It is possible to create an index for searching using SearchVector, but However, Japanese words are not separated by spaces, and the full-text search does not work properly. How can I perform full-text search in Japanese (multi-byte character strings)?

I thought about implementing a search engine such as ElasticSearch, but other problems came up. If possible, I would like to do FTS with Postgres.

# models.py
class Post(models.Model):
    title = models.CharField(max_length=300)
    search = SearchVectorField(null=True)

    class Meta:
        indexes = [GinIndex(fields=["search"])]

# update search column
Post.objects.update(search=SearchVector('title'))

Solution

  • Look at the Pgroonga Postgres extension for fulltext search in all languages. It is used by the Zulip project with amazing results.