-
Notifications
You must be signed in to change notification settings - Fork 32
Recipes and Search
KitchenPC supports structured recipe reads, filtered search, ratings, and recipe creation. Database-backed calls work without optional in-memory capabilities.
var results = await context.Recipes
.Search(q => q
.Keywords("chocolate cake")
.Meal(MealFilter.Dessert)
.MinRating(Rating.ThreeStars)
.MaxPrep(30)
.HasPhoto(RecipeQuery.PhotoFilter.Photo)
.SortBy(RecipeQuery.SortOrder.Rating,
RecipeQuery.SortDirection.Descending))
.ResultsAsync(cancellationToken);
Console.WriteLine($"{results.TotalCount} matches");
foreach (var brief in results.Briefs)
Console.WriteLine(brief.Title);RecipeQuery.PageSize is 100. Use .Offset(n) for paging. Available filters include:
- keywords and minimum rating;
- included or excluded ingredients;
- breakfast, lunch, dinner, or dessert;
- photo/high-resolution photo;
- maximum prep and cook time;
- mild-to-spicy and savory-to-sweet scales;
- gluten-free and animal/meat/pork/red-meat exclusions;
- low calorie, carb, fat, sodium, or sugar;
- common ingredients, easy, or quick;
- title, times, rating, or image sort order.
Filters depend on recipe metadata and classifications in the store. Missing or poorly classified data cannot produce reliable filters. NHSearch uses ordinary SQL; implement ISearchProvider for specialized full-text behavior.
var recipes = await context.Recipes
.Load(Recipe.FromId(firstId))
.Load(Recipe.FromId(secondId))
.WithMethod
.WithUserRating
.WithMenuCount
.ListAsync(cancellationToken);Batch IDs before calling List. Method text, current-user rating, and menu count are opt-in read options. Treat recipe method HTML as untrusted if records can originate outside your control: sanitize it before rendering as HTML, or render it as plain text.
await context.Recipes
.Rate(Recipe.FromId(recipeId), Rating.FiveStars)
.CommitAsync(cancellationToken);Ratings use the context identity. Applications should require an authenticated, stable AuthIdentity before exposing this mutation.
var result = context.Recipes.Create
.WithTitle("Puff Pancake")
.WithDescription("A simple baked breakfast.")
.WithCredit("Example Kitchen")
.WithCreditUrl(new Uri("https://example.com/recipes/puff-pancake"))
.WithImage(new Uri("https://example.com/images/puff-pancake.jpg"))
.WithPrepTime(15)
.WithCookTime(23)
.WithServingSize(4)
.WithMethod("Mix, pour into a pie dish, and bake at 400°F.")
.WithIngredients(items => items
.AddRaw("4 eggs")
.AddRaw("1 cup flour")
.AddRaw("1 cup milk"))
.WithIngredients("Toppings", items => items
.AddRaw("bananas")
.AddRaw("maple syrup"))
.Commit();AddRaw requires ingredient parsing. You can avoid NLP by adding an existing IngredientUsage or building one with normalized ingredient, form, and amount values. Validate title, URLs, time, serving count, and method content at the application boundary. A DB context persists the recipe; a static context only changes its process-local state.
RecipeResult reports whether a recipe was created or updated and provides NewRecipeId for a new record. Invalid recipe data is reported with InvalidRecipeDataException; raw ingredients that cannot be parsed produce CouldNotParseUsageException.
KitchenPC is MIT licensed. Runnable applications live in KitchenPC/Samples.