Django MySQL全文搜索 [英] Django MySQL full text search

查看:178
本文介绍了Django MySQL全文搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要实现我的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)


有关字段查找的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆