[英]How to return two different search results in one in searchkick (ElasticSearch)
我有這兩個搜索
foods = Food.search name, fields: [:name], where: {
or: [
[{nutritionist_id: nil}, {nutritionist_id: current_nutritionist_id}]
]
}, order: {_score: :desc}
recipes = Recipe.search name, fields: [:recipe_name], where: {
or: [
[{nutritionist_id: nil}, {nutritionist_id: current_nutritionist_id}]
]
}, order: {_score: :desc}
我希望foods
和recipes
以相同的結果退回。 像合並它們一樣,類似上面的方法或其他更好的方法。
return foods + reciples
我用Searchkick.search
解決了這個問題,而不是:
foods = Food.search name, fields: [:name], where: {
or: [
[{nutritionist_id: nil}, {nutritionist_id: current_nutritionist_id}]
]
}, order: {_score: :desc}
和
recipes = Recipe.search name, fields: [:recipe_name], where: {
or: [
[{nutritionist_id: nil}, {nutritionist_id: current_nutritionist_id}]
]
}, order: {_score: :desc}
我用了。
result = Searchkick.search(name, index_name: [Food, Recipe], fields: [:name, :recipe_name],
where: {
_or: [ {nutritionist_id: nil}, {nutritionist_id: current_nutritionist_id} ]
}, order: {_score: :desc})
result
這樣,Searchkick在這兩個模型Food
和Recipe
搜索,並返回包含兩個結果的數組。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.