searchForFood & searchForFoodSemantic

Search the database of foods with a given search term.

searchForFood now returns PassioSearchResult and a list of search options. The PassioSearchResult represent a specific food item associated with the search term, while search options provide a list of possible suggested search terms connected to the input term.

Import the PassioSDK

import {
  PassioSDK,
  type FoodSearchResult,
} from '@passiolife/nutritionai-react-native-sdk-v3'

You can utilize the searchForFood API from the SDK to retrieve food records based on a search string. This API returns a PassioSearchResult object containing both results and alternatives.

The results property holds an array of food search results, while the alternatives property provides additional suggestions or alternative options if available.


  /**
   * Search the database of foods with a given search term.
   * @param searchQuery - The search term to match against food item names.
   * @returns A `Promise` resolving to an array of food item names.
   */
   searchForFood(searchQuery: string): Promise<PassioSearchResult | null>
  /**
   * Search for food semantic will return a list of alternate search and search result
   * @param searchQuery - User typed text.
   * @returns A `Promise` resolving to an array of food item result.
   */
  searchForFoodSemantic(searchQuery: string): Promise<PassioSearchResult | null>

How to use it?

      try {
          // Fetch food results from the PassioSDK based on the query
          const searchFoods = await PassioSDK.searchForFood(query)
        } catch (error) {
          // Handle errors, e.g., network issues or API failures
        }
try {
          // Fetch food results from the PassioSDK based on the query
          const searchFoods = await PassioSDK.searchForFoodSemantic(query)
        } catch (error) 
          // Handle errors, e.g., network issues or API failures
        }

How to get PassioFoodItem using SearchFood Response?

   try {
          // Fetch food results from the PassioSDK based on the query
          const passioFoodItem = await PassioSDK.fetchFoodItemForDataInfo(passioFoodDataInfo)
        } catch (error) {
          // Handle errors, e.g., network issues or API failures
        }

Last updated