我在django项目中使用django-sphinxql进行搜索。 我想在我的应用程序中使用两个模型进行一些查询搜索。模型如下所示
Class Model1(models.Model):
name = models.CharField(max_length=50)
model2 = models.ForeignKey(Model2, on_delete=models.CASCADE)
Class Model2(models.Model):
caption = models.CharField(max_length=50)
我想启用搜索上面的名称和标题字段,以便为任何匹配返回Model1,例如if query =" abc"匹配标题响应应为Model1, 我如何实现我为Model1创建的索引,但也不知道如何在Model2中添加标题。我对Model1的索引如下
class Model1Index(indexes.Index):
name = fields.Text(model_attr='name')
class Meta:
model = Model1
settings.INDEXES['source_params'] = {'sql_field_string': ['name'],}
快速帮助表示赞赏。
答案 0 :(得分:0)
对于Sphinx中的外键字段,我们可以使用双下划线(__)指向特定字段以进行索引。此用户/* Minification failed. Returning unminified contents.
(180,448-455): run-time error JS1019: Can't have 'break' outside of loop: break a
*/
在上面的例子中
model_attr
可以定义。
参考http://django-sphinxql.readthedocs.io/en/latest/indexes.html