搜索引擎 thinking sphinx 嵌入关联 建立索引的问题

davidqhr · 2012年03月16日 · 最后由 davidqhr 回复于 2012年03月19日 · 8025 次阅读

问题如下

有三个模型 Bill ,LineItem and product

Bill has_many :line_items
LineItem belongs_to  :product


Product 有两个属性:number and name

例子:

假设 a_bill.line_items.first.product.number = "a_product_number"

我现在想在搜索矿中输入"a_product_number",找到包含这个 product 的 bill

应该如何定义 index 呢?

这是当前的定义,可是找不到我想要的那个 bill 记录

define_index do
    ...
    indexes line_items.product(:number)
    ...

    set_property :delta => true  
end


number 必须是数据库字段名 可以看一下生成的 sphinx config 文件里面的 sql

#1 楼 @allenwei number 的确是字段名字,我试过修改 index,去看 config,对比了一下没什么变化。这是什么原因呢

#2 楼 @davidqhr 有时候建立 config 文件会有 bug 的,尝试删除文件重新 index 一下

#3 楼 @sunzheng91 哦,谢谢,我试试

直接给 Bill, line_items, product 建个 log 表,最简单粗暴!

#5 楼 @mvj3 :-),问题已经解决,索引建立没有问题,其他地方的疏忽导致的。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号