简体   繁体   English

如何在Django中为Haystack + Whoosh编写正确的查询

[英]How to write correct query for Haystack + Whoosh in Django

I have model: 我有模特:

class Article(models.Model):
    title = models.CharField(max_length=250)
    slug = models.SlugField(max_length=250)
    text = models.TextField()
    date = models.DateTimeField(auto_now_add=True)

And file search_indexes.py: 和文件search_indexes.py:

from haystack import indexes
from haystack import site
from models import Article

class ArticleIndex(indexes.SearchIndex):
    text_q = indexes.CharField(document=True, use_template=True)
    text = indexes.CharField(model_attr='text')

    # what I must add here ???

site.register(Article, ArticleIndex)

When I execute query it can find only than words which I have in TITLE field. 当我执行查询时,只能找到TITLE字段中没有的单词。 When I use word combination from TEXT field I got "No results found" 当我从TEXT字段中使用单词组合时,出现“未找到结果”

What I must add for executing queries with words from TEXT field? 使用TEXT字段中的单词执行查询时,我必须添加什么?

The query only looks in the field marked document=True (the other fields can only be used for later filtering) 该查询仅在标记为document=True的字段中查找(其他字段只能用于以后的过滤)

The documentation recommends naming that 'text'. 文档建议命名该“文本”。

As you have use_template=True you should have a template that specifies what object fields are in the document. 当您具有use_template=True您应该具有一个模板,该模板指定文档中的对象字段。

eg templates/search/indexes/main/article_text.txt could contain 例如template / search / indexes / main / article_text.txt可能包含

{{ object.title }}
{{ object.text }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM