我正在经历 django-sphinx文档 http://code.google.com/p/django-sphinx/,看起来它允许您使用过滤搜索结果属性,
queryset = MyModel.search.query('query')
results1 = queryset.order_by('@weight', '@id', 'my_attribute')
results2 = queryset.filter(my_attribute=5)
results3 = queryset.filter(my_other_attribute=[5, 3,4])
results4 = queryset.exclude(my_attribute=5)[0:10]
从一些示例来看,这些属性似乎是您在 sphinx 配置文件中指定的内容,而不是表中的实际列值。配置文件允许这样的事情,
# ForeignKey's
# Apparently sql_group_column is now replaced by sql_attr_uint
sql_group_column = country_id
sql_group_column = state_id
sql_group_column = listings
# DateField's and DateTimeField's
sql_date_column = date_added
但事实证明你只能指定外键作为这个值。如图所示另一个例子 http://www.davidcramer.net/code/django/433/setting-up-django-and-sphinx-full-text-search-django-sphinx.html,
Class City(models.Model):
...
# Comment: The below should probly be country_id and state_id
country_id = models.ForeignKey(Country)
state_id = models.ForeignKey(State, blank=True, null=True)
listings = models.PositiveIntegerField(editable=False, default=0)
当打印搜索结果时,您会得到,
print results[0]._sphinx
{'id': u'5246', 'weight': 200, 'attrs': {'state_id': 3, 'country_id': 0}}
正如您所看到的,在 attrs 中 - state_id 和 Country_id - 是 FK,显示出来。但列表却没有。
这就是我的问题。如果我想在模型中使用任意列 foo 来过滤 sphinx 搜索结果 - 我该怎么做?
Thanks!
Edit
在回答范·盖尔时,
我实际上在这里使用 sql_attr_uint 而不是 sql_group_column .. 正如我在上面的示例中提到的.. 即使 Django Sphinx 作者的示例(上面给出的链接)也不会显示 _Sphinx 字典中的属性,如果它不是FK..(请参阅上面的“如您所见”声明)。另外,我也已经有了 SQL_Query 字符串..它选择我表中的所有列..(单独,不是 *)