Filtering Recipes using Custom Labels

This topic comprehensively describes how you can use the Custom Labels filter to search recipes.

The custom labels filter is available while searching recipes, reading your feed, and generating a meal plan.

Custom Labels Filter Object

Here is how a custom_labels filter object looks in JSON format:

"custom_labels":{
   "everywhere":{
      "in":[
         {
            "group":"string",
            "label":"string"
         }
      ],
      "boost_in":[
         {
            "group":"string",
            "label":"string"
         }
      ],
      "all":[
         {
            "group":"string",
            "label":"string"
         }
      ],
      "not":[
         {
            "group":"string",
            "label":"string"
         }
      ]
   },
   "in_recipe":{
      "in":[
         {
            "group":"string",
            "label":"string"
         }
      ],
      "boost_in":[
         {
            "group":"string",
            "label":"string"
         }
      ],
      "all":[
         {
            "group":"string",
            "label":"string"
         }
      ],
      "not":[
         {
            "group":"string",
            "label":"string"
         }
      ]
   },
   "in_ingredients":{
      "in":[
         {
            "group":"string",
            "label":"string"
         }
      ],
      "boost_in":[
         {
            "group":"string",
            "label":"string"
         }
      ],
      "all":[
         {
            "group":"string",
            "label":"string"
         }
      ],
      "not":[
         {
            "group":"string",
            "label":"string"
         }
      ]
   },
   "in_instruction_steps":{
      "in":[
         {
            "group":"string",
            "label":"string"
         }
      ],
      "boost_in":[
         {
            "group":"string",
            "label":"string"
         }
      ],
      "all":[
         {
            "group":"string",
            "label":"string"
         }
      ],
      "not":[
         {
            "group":"string",
            "label":"string"
         }
      ]
   }
}

Search Locations

You can filter recipes by matching custom labels:

in_recipe

   "in_recipe":{
      ...
   },

The in_recipe filter allows you to logically match the specified custom labels with the labels in recipe's custom label object.

in_ingredients

 "in_ingredients":{
      ...
   },

The in_ingredients filter allows you to logically match the specified custom labels with the labels in recipe's ingredients.

in_instruction_steps

"in_instruction_steps":{
      ...
   }

The in_instruction_steps filter allows you to logically match the specified custom labels with the labels in recipe's instructions.

everywhere

   "everywhere":{
     ...
   },

The everywhere filter allows you to logically match the specified custom labels in all three locations inside a recipe definition -in_recipe, in_ingredients, and in_instruction_steps.

Conditional Operators

Inside each filter you can use the following operators to define an array of custom labels to logically match data:

You can also combine multiple conditions within a single search if needed. Here is an example of how you can combine the conditions:

"custom_labels":{
   "everywhere":{
      "in":[
         {
            "group":"Custom Label Group 1",
            "label":"Custom Label 1"
         },
         {
            "group":"Custom Label Group 2",
            "label":"Custom Label 2"
         }
      ],
      "boost_in":[
         {
            "group":"Custom Label Group 3",
            "label":"Custom Label 3"
         }
      ],
      "all":[
         {
            "group":"Custom Label Group 3",
            "label":"Custom Label 3"
         },
         {
            "group":"Custom Label Group 4",
            "label":"Custom Label 4"
         }
      ],
      "not":[
         {
            "group":"Custom Label Group 5",
            "label":"Custom Label 5"
         },
         {
            "group":"Custom Label Group 6",
            "label":"Custom Label 6"
         }
      ]
   }
}

In this example, the search is going to implement the following logic while filtering recipes:

  • Find recipes with Custom Label 1 or Custom Label 2 added either on the recipe level or inside its ingredients or instructions.

  • Find recipes with Custom Label 3 and Custom Label 4 added either on the recipe level or inside its ingredients or instructions.

  • Exclude recipes with Custom Label 5 and Custom Label 6 added either on the recipe level or inside its ingredients or instructions.

  • Boost ranking of recipes matched with Custom Label 3 in the search results.

Custom Label Definition

Each custom label is specified using the following parameters:

{
  "group":"string",            
  "label":"string"
}

For example, here is how the custom label filter is defined when you want to find recipes that have any of the custom labels that exist in Custom Label Group 1 added to their ingredients:

"custom_labels":{
   "in_ingredients":{
      "in":[
         {
            "group":"Custom Label Group 1"
      ]
   }
}

Example 1 - Filter sponsored recipes for translation

As a publisher, you publish sponsored recipe content in multiple languages and maintain and use custom labels on the recipe level related to the targeted languages for translation and to indicate the translation status. You also keep and use custom labels to indicate sponsored and unsponsored recipes. Now let's assume that you want to filter sponsored recipes that require translation in Korean and Japanese languages and exclude already translated recipes. Here is how your custom label filter query would look:

{
  "custom_labels": {
    "in_instruction_steps": {
      "in":[
         {
            "group":"Sponsorship",
            "label":"Sponsored"
         }
      ],
      "all":[
         {
            "group":"Target language for Translation",
            "label":"Korean"
         },
         {
            "group":"Target language for Translation",
            "label":"Japanese"
         },
      ],
      "not":[
         {
            "group":"Translation Status",
            "label":"Translated"
         }
      ]
    }
  }
}

Example 2 - Filter Recipes created for a specific age group by certified members of one particular group of recipe authors

As a publisher, you have grouped your recipe authors into various clubs, and you publish recipe content for different age groups. To organize and distinguish your recipe content, you use custom labels for authors' clubs, certified authors, and age groups, but you don't follow a consistent approach for adding custom labels. Your authors sometimes add custom labels on a recipe level, and they also sometimes add them in ingredients or instructions. Now, let's assume that you want to filter recipes created for children aged 1-3 or 3-9 by certified Mom's Cooking Club members and boost the ranking of recipes matched with age group 1-3 in search results. Here is how your custom label filter query would look:

{
  "custom_labels": {
    "everywhere": {
      "in": [
        {
          "group": "Age Group",
          "label": "1-3"
        },
        {
          "group": "Age Group",
          "label": "3-9"
        }
      ],
      "boost_in":[
         {
            "group":"Age Group",
            "label":"1-3"
         }
      ],
      "all": [
        {
          "group": "Mom's Cooking Club"
        },
        {
          "group": "Certified Authors"
        }
      ]
    }   
  }
}

Last updated