Django Haystack精确过滤

2024-10-01 07:15:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个干草堆搜索,它有以下搜索索引:

class GrantIndex(indexes.SearchIndex):
    """
    This provides the search index for the Grant application.
    """
    text = indexes.CharField(document=True, use_template=True)
    year = indexes.IntegerField(model_attr='year__year')
    date = indexes.DateField(model_attr='date')
    program = indexes.CharField(model_attr='program__area')
    grantee = indexes.CharField(model_attr='grantee')
    amount = indexes.IntegerField(model_attr='amount')
site.register(Grant, GrantIndex)

如果我要搜索筛选出任何不“Health”的程序,我运行以下查询:

^{pr2}$

不幸的是,这也会从程序“Health\Other”和“Health\cardional”生成对象。如何阻止搜索允许其他程序进入?在

我运行Ubuntu9.10,Xapian作为我的搜索后端。在


Tags: the程序truedatemodelprogramyearattr
3条回答

你可能已经解决了这个问题,但是我刚刚在Whoosh后端遇到了同样的问题。也许Xapian和Whoosh后端的行为是一样的?似乎Whoosh在默认情况下对所有CharFields加词干,并使用某种contains查询在它们内部进行搜索。切换到自定义后端,没有在CharFields上启用词干,为我修复了这个问题。在

希望这能把别人推向正确的方向。在

在程序字段中使用“prepare_data”并清除health\blablabla的东西

您可以按照here所述使用字段查找。在

sqs = sqs.filter(program__exact='Health')

相关问题 更多 >