私は最近searchkickを設定しました。私は索引付けしたモデルの属性をすばらしく使用しています。searchkick has_manyとHABTM associationが機能しないのはなぜですか?
しかし、アソシエーションに関しては、それはひどく失敗します。
これは団体& search_data
方法と私のモデルである:私はProfile.reindex
を実行することを確認しましたが、私はposition
の名前ですCenter Back
のクエリを実行するとき、それは空のクエリを返す
class Profile < ActiveRecord::Base
searchkick
has_and_belongs_to_many :positions
belongs_to :school
def search_data
{
name: name,
bib_color: bib_color,
height: height,
weight: weight,
player_type: player_type,
school_name: school.name,
age: age,
position_name: positions.map(&:name)
}
end
end
私は結果があることを知っているときに設定します。しかし、ここで
> Profile.search("center back").to_a
Profile Search (27.5ms) curl http://localhost:9200/profiles_development/_search?pretty -d '{"query":{"dis_max":{"queries":[{"match":{"_all":{"query":"center back","boost":10,"operator":"and","analyzer":"searchkick_search"}}},{"match":{"_all":{"query":"center back","boost":10,"operator":"and","analyzer":"searchkick_search2"}}},{"match":{"_all":{"query":"center back","boost":1,"operator":"and","analyzer":"searchkick_search","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}},{"match":{"_all":{"query":"center back","boost":1,"operator":"and","analyzer":"searchkick_search2","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}}]}},"size":1000,"from":0,"timeout":"11s","_source":false}'
=> []
は、結果はそうでない場合は、次のとおりです。
> p
=> #<Position:0x007fa881566310 id: 1, created_at: Sun, 04 Sep 2016 06:49:45 UTC +00:00, updated_at: Wed, 14 Sep 2016 06:17:02 UTC +00:00, name: "Center Back">
> p.profiles.count
(4.1ms) SELECT COUNT(*) FROM "profiles" INNER JOIN "positions_profiles" ON "profiles"."id" = "positions_profiles"."profile_id" WHERE "positions_profiles"."position_id" = $1 [["position_id", 1]]
=> 5
あり、少なくとも5 profiles
も、まだ結果が空として返す必要があります。
私がそうであっても同じように私search_data
をフォーマットしようとしている:
def search_data
attrs = attributes.dup
relational = {
school_name: school.name,
grade_name: grades.map(&:subject),
position_names: positions.map(&:name)
}
attrs.merge! relational
end
私は定期的にhas_many
関連付けをしようとし、それに応じてそれを宣言した場合、同じことが起こります。
これを引き起こしている可能性があり、修正するにはどうすればよいですか?