Parse platform 解析-按成分搜索配方

Parse platform 解析-按成分搜索配方,parse-platform,Parse Platform,我的解析中有以下两个类,在查询它们以获得我想要的结果时遇到了一些问题。我正在尝试按配料搜索食谱 这是我的课程:配料 +---------------+---------+ | ingredientId | name | +---------------+---------+ | 1 | tomato | | 2 | garlic | | 3 | banana | | 4 | chicke

我的解析中有以下两个类,在查询它们以获得我想要的结果时遇到了一些问题。我正在尝试按配料搜索食谱

这是我的课程:配料

+---------------+---------+
| ingredientId  | name    |
+---------------+---------+
|             1 | tomato  |
|             2 | garlic  |
|             3 | banana  |
|             4 | chicken |
|             5 | beef    |
|             6 | onion   |
|             7 | salt    |
+---------------+---------+
食谱

+-----------+------------------+----------------------+
| recipeId  | name             | Ingredients (array)  |
+-----------+------------------+----------------------+
|         1 | hamburger        | {5,7,2}              |
|         2 | salad            | {1,2,6}              |
|         3 | garlic chicken   | {2,4}                |
+-----------+------------------+----------------------+
我正在尝试查询,以找到我可以用给定的配料制作哪些食谱

示例:配料1、2、4将与大蒜鸡肉配方一起响应,因为我有这个配方中的所有配料


任何帮助都将不胜感激

这里使用数组而不是关系有什么具体原因吗?我相信关系会解开你的手

我建议将Recipes.Components转换为关系数据类型,并继续将成分指定为单个关系

然后查询会更容易,因为您没有指定语言,所以我将继续使用objective-c:

// for demonstration purposes these are the ingredients I have and am looking for 
// suitable recipe
NSArray *_arrIngredients = @[@"water", @"butter", @"meat", @"bread", @"salt"];

// get objectId for all ingredients I'm searching for
PFQuery *_query = [PFQuery queryWithClassName:@"Ingredients"];
[_query whereKey:@"name" containedIn:_arrIngredients];

// query existing relations
PFQuery *mainQuery = [PFQuery queryWithClassName:@"Recipes"];
[mainQuery whereKey:@"Ingredients" matchesQuery:_query];
[mainQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {

    if(error)
    {
        NSLog(@"%@", [error localizedDescription]);
    }
    else
    {
        // print out matching objects
        // your code here
        for(PFObject *object in objects)
        {
            NSLog(@"%@: %@", [object objectForKey:@"name"], [object objectId]);
        }
    }
}];

希望有帮助

查询以两个数组保存第一个表的所有数据。一个用于配料名称,另一个用于配料id

然后再次移动到第二个表apply query,用于获取特定receipe的数组,并将它们保存在android中的列表中,然后

当输入任何配料以搜索任何配方时..您必须检查从第一个表中制作的配料数组中的配料..然后将相应的配料id传递到第二个表中的列表以获得receipe名称


如果您使用android操作系统进行编码,那么请使用entity。或者让我知道我将为此添加代码。

嗨,David,因为我想做的只是解析还不够,10倍的解释