0

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:

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. When I use word combination from TEXT field I got "No results found"

What I must add for executing queries with words from TEXT field?

4

1 回答 1

0

查询只在标记的字段中查找document=True(其他字段只能用于以后过滤)

文档建议命名该“文本”。

正如您所拥有use_template=True的,您应该有一个模板来指定文档中的对象字段。

例如 templates/search/indexes/main/article_text.txt 可以包含

{{ object.title }}
{{ object.text }}
于 2013-04-10T09:05:48.727 回答