# Food Filter

The filter object refines food results based on various criteria. It supports logical operators: must (AND) and should (OR). Additionally, the mustNot operator is available to exclude foods that match specific ingredients or tags.

## How to use logical operators

Use the following syntaxis ask to filter `fieldName1` **and** `FieldName2`

`filter: {`\
&#x20;       `must: [`\
&#x20;              `{fieldName1: value1},`\
&#x20;              `{FieldName2: value2}`\
&#x20;              `]`\
&#x20;        `}`

Use the following syntaxis ask to filter `fieldName1` **or**`FieldName2`

`filter: {`\
&#x20;       `should: [`\
&#x20;              `{fieldName1: value1},`\
&#x20;              `{FieldName2: value2}`\
&#x20;              `]`\
&#x20;        `}`

Add recursive filters by combining must and should operators:

`filter: {`\
&#x20;      `should: [`\
&#x20;            `{fieldName1: "value1"},`\
&#x20;           `{`\
&#x20;              `must: [`\
&#x20;                `{fieldName2: "value2"},`\
&#x20;                `{fieldName3:  value3}`\
&#x20;             `]`\
&#x20;          `}]`\
&#x20;       `}`

For example, the above example describes how to filter `value1` information or `value2` and `value3` values. Each value can have a different field type.

## mustNot Operator

Use the mustNot operator to exclude specific values from the results. It works similarly to must but filters out matching values instead of including them.

For example, to retrieve results that must include value1 but must not include value2:

`filter:{`\
&#x20;      `must:{`\
&#x20;           `fieldName1:"value1"`\
&#x20;           `}`\
&#x20;      `mustNot:{`\
&#x20;             `fieldName2:"value2"`\
&#x20;              `}`\
&#x20;       `}`

## Available fields

| Field Name    | Type     | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id`          | ID       | <p>Unique ID retrieved from the <a href="https://docs.suggestic.com/graphql/query/search/food-search-for-food-log/branded-foods-search"><code>brandedFoods</code></a> or <a href="https://docs.suggestic.com/graphql/query/search/food-search-for-food-log/common-foods-search"><code>customFoods</code> </a>search queries<br>Use this in the following: </p><ul><li><a href="https://docs.suggestic.com/graphql/query/search/food-search-for-food-log/common-foods-search">commonFoods</a></li><li><a href="https://docs.suggestic.com/graphql/query/search/food-search-for-food-log/branded-foods-search">brandedFoods</a></li></ul> |
| `externalID`  | String   | <p>Edamam o USDA unique ID, known ad foodID<br>Use this in the following: </p><ul><li><a href="https://docs.suggestic.com/graphql/query/search/food-search-for-food-log/common-foods-search">commonFoods</a></li><li><a href="https://docs.suggestic.com/graphql/query/search/food-search-for-food-log/branded-foods-search">brandedFoods</a></li></ul><p></p>                                                                                                                                                                                                                                                                          |
| `tags`        | String   | <p>Predefined tag to be added to use it to filter food. Add one or more tags. For example: <code>tags: \["tag1", "tag2"].</code> <br>Use this in the following: </p><ul><li><a href="https://docs.suggestic.com/graphql/query/search/food-search-for-food-log/common-foods-search">commonFoods</a></li><li><a href="https://docs.suggestic.com/graphql/query/search/food-search-for-food-log/branded-foods-search">brandedFoods</a></li></ul>                                                                                                                                                                                           |
| `mealTime`    | MealTime | Valid values are: `BREAKFAST`, `LUNCH`, `DINNER`, `SNACK`, `TREAT_DESSERT.` Use this in the [recipeSearch ](https://docs.suggestic.com/graphql/query/search/recipes)query                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `nutrients`   | Nutrient | <p>Valid Values: <a href="https://docs.suggestic.com/graphql/objects/food-logs/nutrients/nutrient-enum"><code>nutrient</code></a>, <code>range.</code></p><p> Use this in the following: </p><ul><li><a href="https://docs.suggestic.com/graphql/query/search/food-search-for-food-log/common-foods-search">commonFoods</a></li><li><a href="https://docs.suggestic.com/graphql/query/search/food-search-for-food-log/branded-foods-search">brandedFoods</a></li></ul>                                                                                                                                                                  |
| `ingredients` | String   | Add one or more ingredients. Use this in the [recipeSearch ](https://docs.suggestic.com/graphql/query/search/recipes)query                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `barcode`     | String   | Barcode number                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `name`        | String   | Food Name                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |

## Examples

### How to use tags

{% tabs %}
{% tab title="Example" %}

```graphql
filter: {
      tags: ["fat-free", "caffeine-free"]
 }
```

{% endtab %}
{% endtabs %}

### How to use mealTime

The following example filters the information of *lunch* **and** *dinner* meal times. See an example in the [`recipeSearch` ](https://docs.suggestic.com/graphql/query/search/recipes#search-for-more-than-a-mealtime-at-the-same-time)documentation.

{% tabs %}
{% tab title="Example" %}

```graphql
filter: {
		must: [
			{mealTime: LUNCH},
			{mealTime: DINNER}
		]}
```

{% endtab %}
{% endtabs %}

The following example filters the information of *lunch* **or** *dinner* meal times.&#x20;

{% tabs %}
{% tab title="Example" %}

```graphql
filter: {
		should: [
			{mealTime: LUNCH},
			{mealTime: DINNER}
		]}
```

{% endtab %}
{% endtabs %}

### How to use ingredients

The following example filters the information by *milk* **OR** *bread* ingredients.&#x20;

{% tabs %}
{% tab title="Example" %}

```graphql
 filter: {
   should: [
			{ingredients: "milk"},
			{ingredients: "bread"}
		]
```

{% endtab %}
{% endtabs %}

### How to use nutrients

The following example filters the information by food that contains Vitamin A and Folic Acid. The nutrient value can be replaced by using any of the values listed on filed name column of the the [Nutrient enum](https://docs.suggestic.com/graphql/objects/food-logs/nutrients/nutrient-enum) table

{% tabs %}
{% tab title="Example" %}

```graphql
filter: {
      nutrients: [
        {nutrient:VITAMIN_A_RAE range: {lte: 100}}
        {nutrient:FOLIC_ACID range: {gte: 10}}
      ]
    }
```

{% endtab %}
{% endtabs %}

### How to use mustNot operator

The following example filters foods that contain the ingredient **potato** but exclude those that contain the ingredient **onion** or have the tag “**high-fat**”

{% tabs %}
{% tab title="Example" %}

```graphql
filter:{
      must:{
        ingredients:"potato"
      }
    	mustNot:{
        ingredients:"onion"
        tags:"high-fat"
      }
    }
```

{% endtab %}
{% endtabs %}
