假设我们有一个食品项目数据库,例如:
item1 = {name: 'item1', tags: ['mexican', 'spicy']};
item2 = {name: 'item2', tags: ['sweet', 'chocolate', 'nuts']};
item3 = {name: 'item3', tags: ['sweet', 'vanilla', 'cold']};
Run Code Online (Sandbox Code Playgroud)
我们有一个用户正在寻找食物推荐,他们在那里指出他们对某些标签的偏好权重:
foodPref = {sweet: 4, chocolate: 11}
Run Code Online (Sandbox Code Playgroud)
现在我们需要计算每个项目得分的好坏并推荐最佳项目:
item1 score = 0 (doesn't contain any of the tags user is looking for)
item2 score = 4 (contains the tag 'sweet')
item3 score = 15 (contains the tag 'sweet' and 'chocolate')
Run Code Online (Sandbox Code Playgroud)
获取建议的正确方法是什么 - 自定义遍历对象或仅使用AQL过滤和计数或仅在Foxx(javascript层)中实现它?
另外,您可以帮助您建议使用方法的示例实现吗?
提前致谢!