Django MySQL全文搜索 [英] Django MySQL full text search
问题描述
我需要实现我的Django应用程序的全文搜索,运行MySQL作为后端。
假设我有一个模型如下:
class MyItem(models.Model):
title = models.CharField()
short_description = models.TextField()
description = models.TextField()
我想先搜索搜索结果发生在标题,然后在短描述和结束在描述领域。如果我不必为此任务使用额外的模块/应用程序,我将会更快乐。
文本搜索django
MyItem.objects.filter(title__search =some search text)
$ c有一件事 - 你不能从Django模型定义一个全文索引,你需要直接在一个数据库中(使用PHPMyAdmin或SQL查询)
有关字段查找的Django文档,请参阅 search
I need to implement full text search for my Django application, running MySQL as backend.
Let's say I've got a model as follows:
class MyItem(models.Model):
title = models.CharField()
short_description = models.TextField()
description = models.TextField()
I would like to have results first for search term occurences in title, then in short_description and at the end in description field. I'll be happier if I don't have to use additional modules/applications for this task.
解决方案 You can use full text search in django
MyItem.objects.filter(title__search="some search text")
One thing is - you can't define a fulltext index from a Django model, you need to do in directly in a database (using PHPMyAdmin or SQL query)
See Django documentation for field lookup called search
这篇关于Django MySQL全文搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!