public object Clone() { var clonedQuery = new RecipeQuery() { Keywords = this.Keywords, Rating = this.Rating, Meal = this.Meal, Offset = this.Offset, Photos = this.Photos, Sort = this.Sort, Direction = this.Direction, Time = this.Time.Clone() as TimeFilter, Diet = this.Diet.Clone() as DietFilter, Nutrition = this.Nutrition.Clone() as NutritionFilter, Skill = this.Skill.Clone() as SkillFilter, Taste = this.Taste.Clone() as TasteFilter }; if (this.Include != null) { clonedQuery.Include = this.Include.Clone() as Guid[]; } if (this.Exclude != null) { clonedQuery.Exclude = this.Exclude.Clone() as Guid[]; } return(clonedQuery); }
public void RecipeActionSearch_ShouldReturnARecipeFinderWithCorrectValues() { var recipeQuery = new RecipeQuery(); var recipeFinder = this.Action.Search(recipeQuery); Assert.IsInstanceOf(typeof(RecipeFinder), recipeFinder); Assert.AreSame(this.Context, recipeFinder.Context); Assert.AreSame(recipeQuery, recipeFinder.Query); }
public RecipeQuery(RecipeQuery query) { this.Keywords = query.Keywords; this.Rating = query.Rating; if (query.Include != null) this.Include = (Guid[]) query.Include.Clone(); if (query.Exclude != null) this.Exclude = (Guid[]) query.Exclude.Clone(); this.Time = query.Time; this.Photos = query.Photos; this.Sort = query.Sort; this.Direction = query.Direction; }
public void RecipeQueryClone_ShouldCloneObject() { var query = new RecipeQuery { Keywords = "clone", Meal = MealFilter.Breakfast, Rating = Rating.OneStar, Sort = SortOrder.CookTime, Direction = SortDirection.Ascending, Offset = 3, Photos = PhotoFilter.HighRes, Taste = { MildToSpicy = SpicinessLevel.Spicy, SavoryToSweet = SweetnessLevel.Sweet }, Include = new Guid[] { Guid.NewGuid(), }, Exclude = new Guid[] { Guid.NewGuid(), Guid.NewGuid() } }; var clonedQuery = query.Clone() as RecipeQuery; Assert.AreEqual(query.Keywords, clonedQuery.Keywords); Assert.AreEqual(query.Meal, clonedQuery.Meal); Assert.AreEqual(query.Rating, clonedQuery.Rating); Assert.AreEqual(query.Sort, clonedQuery.Sort); Assert.AreEqual(query.Direction, clonedQuery.Direction); Assert.AreEqual(query.Offset, clonedQuery.Offset); Assert.AreEqual(query.Photos, clonedQuery.Photos); Assert.AreEqual(query.Time, clonedQuery.Time); Assert.AreNotSame(query.Time, clonedQuery.Time); Assert.AreEqual(query.Diet, clonedQuery.Diet); Assert.AreNotSame(query.Diet, clonedQuery.Diet); Assert.AreEqual(query.Nutrition, clonedQuery.Nutrition); Assert.AreNotSame(query.Nutrition, clonedQuery.Nutrition); Assert.AreEqual(query.Skill, clonedQuery.Skill); Assert.AreNotSame(query.Skill, clonedQuery.Skill); Assert.AreEqual(query.Taste, clonedQuery.Taste); Assert.AreNotSame(query.Taste, clonedQuery.Taste); CollectionAssert.AreEqual(query.Include, clonedQuery.Include); Assert.AreNotSame(query.Include, clonedQuery.Include); CollectionAssert.AreEqual(query.Exclude, clonedQuery.Exclude); Assert.AreNotSame(query.Exclude, clonedQuery.Exclude); }
public RecipeQuery(RecipeQuery query) { this.Keywords = query.Keywords; this.Rating = query.Rating; if (query.Include != null) { this.Include = (Guid[])query.Include.Clone(); } if (query.Exclude != null) { this.Exclude = (Guid[])query.Exclude.Clone(); } this.Time = query.Time; this.Photos = query.Photos; this.Sort = query.Sort; this.Direction = query.Direction; }
public void TestRecipeQueryConstructor() { var query = new RecipeQuery(); CollectionAssert.AreEqual(query.Include, new Guid[0]); CollectionAssert.AreEqual(query.Exclude, new Guid[0]); Assert.AreEqual(query.Keywords, null); Assert.AreEqual(query.Meal, MealFilter.All); Assert.AreEqual(query.Photos, PhotoFilter.All); Assert.AreEqual(query.Rating, Rating.None); Assert.AreEqual(SortOrder.Rating, query.Sort); Assert.AreEqual(SortDirection.Descending, query.Direction); Assert.AreEqual(query.Time, new TimeFilter()); Assert.AreEqual(query.Diet, new DietFilter()); Assert.AreEqual(query.Nutrition, new NutritionFilter()); Assert.AreEqual(query.Skill, new SkillFilter()); Assert.AreEqual(query.Taste, new TasteFilter()); }
public RecipeQueryBuilder SortBy(RecipeQuery.SortOrder sortOrder, RecipeQuery.SortDirection direction = RecipeQuery.SortDirection.Ascending) { query.Sort = sortOrder; query.Direction = direction; return this; }
public RecipeQueryBuilder SavoryToSweet(RecipeQuery.SweetnessLevel scale) { query.Taste.SavoryToSweet = scale; return this; }
public RecipeQueryBuilder MildToSpicy(RecipeQuery.SpicinessLevel scale) { query.Taste.MildToSpicy = scale; return this; }
private static IQueryOver<Recipes, Recipes> SearchByDiet( RecipeQuery query, IQueryOver<Recipes, Recipes> recipesQuery, RecipeMetadata metadata) { if (query.Diet.GlutenFree) { recipesQuery = recipesQuery.Where(() => metadata.DietGlutenFree); } if (query.Diet.NoAnimals) { recipesQuery = recipesQuery.Where(() => metadata.DietNoAnimals); } if (query.Diet.NoMeat) { recipesQuery = recipesQuery.Where(() => metadata.DietNomeat); } if (query.Diet.NoPork) { recipesQuery = recipesQuery.Where(() => metadata.DietNoPork); } if (query.Diet.NoRedMeat) { recipesQuery = recipesQuery.Where(() => metadata.DietNoRedMeat); } return recipesQuery; }
/// <summary> /// Searches for recipes matching the specified criteria. /// </summary> /// <param name="query">A RecipeQuery object indicating the recipes to match.</param> /// <returns>A SearchResults object containing recipe briefs and a total count.</returns> public virtual SearchResults RecipeSearch(RecipeQuery query) { return this.Adapter.RecipeSearch(this.Identity, query); }
public void RecipeFinderResults_ShouldCallContextRecipeSearch() { var testQuery = new RecipeQuery(); var recipeFinder = new RecipeFinder(this.Context, testQuery); this.Context.RSCalledTimes = 0; var search = recipeFinder.Results(); var query = this.Context.search; Assert.AreEqual(1, this.Context.RSCalledTimes); CollectionAssert.AreEqual(query.Include, new Guid[0]); CollectionAssert.AreEqual(query.Exclude, new Guid[0]); Assert.AreEqual(query.Keywords, null); Assert.AreEqual(query.Meal, MealFilter.All); Assert.AreEqual(query.Photos, PhotoFilter.All); Assert.AreEqual(query.Rating, Rating.None); Assert.AreEqual(SortOrder.Rating, query.Sort); Assert.AreEqual(SortDirection.Descending, query.Direction); Assert.AreEqual(query.Time, new TimeFilter()); Assert.AreEqual(query.Diet, new DietFilter()); Assert.AreEqual(query.Nutrition, new NutritionFilter()); Assert.AreEqual(query.Skill, new SkillFilter()); Assert.AreEqual(query.Taste, new TasteFilter()); }
public SearchResults Search(AuthIdentity identity, RecipeQuery query) { using (var session = this.adapter.GetSession()) { Recipes recipe = null; var q = session.QueryOver<Recipes>(() => recipe) .Where(p => !p.Hidden); // Add keyword search if (!string.IsNullOrWhiteSpace(query.Keywords)) { q = q.Where( Restrictions.Or( Restrictions.InsensitiveLike("Title", string.Format("%{0}%", query.Keywords.Trim())), Restrictions.InsensitiveLike("Description", string.Format("%{0}%", query.Keywords.Trim())))); } if (query.Time.MaxPrep.HasValue) { q = q.Where(p => p.PrepTime <= query.Time.MaxPrep.Value); } if (query.Time.MaxCook.HasValue) { q = q.Where(p => p.CookTime <= query.Time.MaxCook.Value); } if (query.Rating > 0) { q = q.Where(p => p.Rating >= (int)query.Rating); } // Add ingredients to include if (query.Include != null && query.Include.Length > 0) { // Create a sub-query for ingredients to include q = q.WithSubquery .WhereExists(QueryOver.Of<RecipeIngredients>() .Where(item => item.Recipe.RecipeId == recipe.RecipeId) .Where(Restrictions.InG("Ingredient", query.Include.Select(Models.Ingredients.FromId).ToArray())) .Select(i => i.RecipeIngredientId).Take(1)); } // Add ingredients to exclude if (query.Exclude != null && query.Exclude.Length > 0) { // Create a sub-query for ingredients to exclude q = q.WithSubquery .WhereNotExists(QueryOver.Of<RecipeIngredients>() .Where(item => item.Recipe.RecipeId == recipe.RecipeId) .Where(Restrictions.InG("Ingredient", query.Exclude.Select(Models.Ingredients.FromId).ToArray())) .Select(i => i.RecipeIngredientId).Take(1)); } if (query.Photos == PhotoFilter.Photo || query.Photos == PhotoFilter.HighRes) { q = q.Where(Restrictions.IsNotNull("ImageUrl")); } // Need to search in metadata if (query.Diet || query.Nutrition || query.Skill || query.Taste || (query.Meal != MealFilter.All) || (query.Photos == PhotoFilter.HighRes)) { RecipeMetadata metadata = null; q = q.JoinAlias(r => r.RecipeMetadata, () => metadata); // Meal if (query.Meal != MealFilter.All) { if (query.Meal == MealFilter.Breakfast) { q = q.Where(() => metadata.MealBreakfast); } if (query.Meal == MealFilter.Dessert) { q = q.Where(() => metadata.MealDessert); } if (query.Meal == MealFilter.Dinner) { q = q.Where(() => metadata.MealDinner); } if (query.Meal == MealFilter.Lunch) { q = q.Where(() => metadata.MealLunch); } } // High-res photos if (query.Photos == PhotoFilter.HighRes) { q = q.Where(() => metadata.PhotoRes >= 1024 * 768); } // Diet if (query.Diet.GlutenFree) { q = q.Where(() => metadata.DietGlutenFree); } if (query.Diet.NoAnimals) { q = q.Where(() => metadata.DietNoAnimals); } if (query.Diet.NoMeat) { q = q.Where(() => metadata.DietNomeat); } if (query.Diet.NoPork) { q = q.Where(() => metadata.DietNoPork); } if (query.Diet.NoRedMeat) { q = q.Where(() => metadata.DietNoRedMeat); } // Nutrition if (query.Nutrition.LowCalorie) { q = q.Where(() => metadata.NutritionLowCalorie); } if (query.Nutrition.LowCarb) { q = q.Where(() => metadata.NutritionLowCarb); } if (query.Nutrition.LowFat) { q = q.Where(() => metadata.NutritionLowFat); } if (query.Nutrition.LowSodium) { q = q.Where(() => metadata.NutritionLowSodium); } if (query.Nutrition.LowSugar) { q = q.Where(() => metadata.NutritionLowSugar); } // Skill if (query.Skill.Common) { q = q.Where(() => metadata.SkillCommon).OrderBy(() => metadata.Commonality).Desc(); } if (query.Skill.Easy) { q = q.Where(() => metadata.SkillEasy); } if (query.Skill.Quick) { q = q.Where(() => metadata.SkillQuick); } // Taste if (query.Taste.MildToSpicy != SpicinessLevel.Medium) { q = query.Taste.MildToSpicy < SpicinessLevel.Medium ? q.Where(() => metadata.TasteMildToSpicy <= query.Taste.Spiciness).OrderBy(() => metadata.TasteMildToSpicy).Asc() : q.Where(() => metadata.TasteMildToSpicy >= query.Taste.Spiciness).OrderBy(() => metadata.TasteMildToSpicy).Desc(); } if (query.Taste.SavoryToSweet != SweetnessLevel.Medium) { q = query.Taste.SavoryToSweet < SweetnessLevel.Medium ? q.Where(() => metadata.TasteSavoryToSweet <= query.Taste.Sweetness).OrderBy(() => metadata.TasteSavoryToSweet).Asc() : q.Where(() => metadata.TasteSavoryToSweet >= query.Taste.Sweetness).OrderBy(() => metadata.TasteSavoryToSweet).Desc(); } } IQueryOverOrderBuilder<Recipes, Recipes> orderBy; switch (query.Sort) { case SortOrder.Title: orderBy = q.OrderBy(p => p.Title); break; case SortOrder.PrepTime: orderBy = q.OrderBy(p => p.PrepTime); break; case SortOrder.CookTime: orderBy = q.OrderBy(p => p.CookTime); break; case SortOrder.Image: orderBy = q.OrderBy(p => p.ImageUrl); break; default: orderBy = q.OrderBy(p => p.Rating); break; } var results = (query.Direction == SortDirection.Descending ? orderBy.Desc() : orderBy.Asc()) .Skip(query.Offset) .List(); return new SearchResults { Briefs = results.Select(r => r.AsRecipeBrief()).ToArray(), TotalCount = results.Count }; } }
public SearchResults Search(AuthorIdentity identity, RecipeQuery query) { using (var session = this.adapter.GetSession()) { Recipes recipe = null; var recipesQuery = session.QueryOver(() => recipe).Where(p => !p.Hidden); if (!string.IsNullOrWhiteSpace(query.Keywords)) { // Add keyword search recipesQuery = recipesQuery.Where( Restrictions.Or( Restrictions.InsensitiveLike( "Title", string.Format("%{0}%", query.Keywords.Trim())), Restrictions.InsensitiveLike("Description", string.Format("%{0}%", query.Keywords.Trim())))); } if (query.Time.MaxPrep.HasValue) { recipesQuery = recipesQuery.Where(p => p.PrepTime <= query.Time.MaxPrep.Value); } if (query.Time.MaxCook.HasValue) { recipesQuery = recipesQuery.Where(p => p.CookTime <= query.Time.MaxCook.Value); } if (query.Rating > 0) { recipesQuery = recipesQuery.Where(p => p.Rating >= (int)query.Rating.Value); } recipesQuery = AddIngredientsToInclude(query, recipesQuery, recipe); recipesQuery = AddIngredientsToExclude(query, recipesQuery, recipe); if (query.Photos == PhotoFilter.Photo || query.Photos == PhotoFilter.HighRes) { recipesQuery = recipesQuery.Where(Restrictions.IsNotNull("ImageUrl")); } if (query.Diet || query.Nutrition || query.Skill || query.Taste || (query.Meal != MealFilter.All) || (query.Photos == PhotoFilter.HighRes)) { // Need to search in metadata RecipeMetadata metadata = null; recipesQuery = recipesQuery.JoinAlias(r => r.RecipeMetadata, () => metadata); recipesQuery = SearchByMeal(query, recipesQuery, metadata); recipesQuery = SearchByHighResolutionPhotos(query, recipesQuery, metadata); recipesQuery = SearchByDiet(query, recipesQuery, metadata); recipesQuery = SearchByNutrition(query, recipesQuery, metadata); recipesQuery = SearchBySkill(query, recipesQuery, metadata); recipesQuery = SearchByTaste(query, recipesQuery, metadata); } IQueryOverOrderBuilder<Recipes, Recipes> orderBy; switch (query.Sort) { case SortOrder.Title: orderBy = recipesQuery.OrderBy(p => p.Title); break; case SortOrder.PrepTime: orderBy = recipesQuery.OrderBy(p => p.PrepTime); break; case SortOrder.CookTime: orderBy = recipesQuery.OrderBy(p => p.CookTime); break; case SortOrder.Image: orderBy = recipesQuery.OrderBy(p => p.ImageUrl); break; default: orderBy = recipesQuery.OrderBy(p => p.Rating); break; } var results = (query.Direction == SortDirection.Descending ? orderBy.Desc() : orderBy.Asc()).Skip(query.Offset) .Take(100) .List(); return new SearchResults { Briefs = results.Select(r => r.AsRecipeBrief()).ToArray(), TotalCount = results.Count // TODO: This needs to be the total matches, not the returned matches }; } }
private static IQueryOver<Recipes, Recipes> SearchByTaste( RecipeQuery query, IQueryOver<Recipes, Recipes> recipesQuery, RecipeMetadata metadata) { if (query.Taste.MildToSpicy != SpicinessLevel.Medium) { recipesQuery = query.Taste.MildToSpicy < SpicinessLevel.Medium ? recipesQuery.Where(() => metadata.TasteMildToSpicy <= query.Taste.Spiciness) .OrderBy(() => metadata.TasteMildToSpicy) .Asc() : recipesQuery.Where(() => metadata.TasteMildToSpicy >= query.Taste.Spiciness) .OrderBy(() => metadata.TasteMildToSpicy) .Desc(); } if (query.Taste.SavoryToSweet != SweetnessLevel.Medium) { recipesQuery = query.Taste.SavoryToSweet < SweetnessLevel.Medium ? recipesQuery.Where(() => metadata.TasteSavoryToSweet <= query.Taste.Sweetness) .OrderBy(() => metadata.TasteSavoryToSweet) .Asc() : recipesQuery.Where(() => metadata.TasteSavoryToSweet >= query.Taste.Sweetness) .OrderBy(() => metadata.TasteSavoryToSweet) .Desc(); } return recipesQuery; }
private static IQueryOver<Recipes, Recipes> SearchBySkill( RecipeQuery query, IQueryOver<Recipes, Recipes> recipesQuery, RecipeMetadata metadata) { if (query.Skill.Common) { recipesQuery = recipesQuery.Where(() => metadata.SkillCommon).OrderBy(() => metadata.Commonality).Desc(); } if (query.Skill.Easy) { recipesQuery = recipesQuery.Where(() => metadata.SkillEasy); } if (query.Skill.Quick) { recipesQuery = recipesQuery.Where(() => metadata.SkillQuick); } return recipesQuery; }
private static IQueryOver<Recipes, Recipes> SearchByNutrition( RecipeQuery query, IQueryOver<Recipes, Recipes> recipesQuery, RecipeMetadata metadata) { if (query.Nutrition.LowCalorie) { recipesQuery = recipesQuery.Where(() => metadata.NutritionLowCalorie); } if (query.Nutrition.LowCarb) { recipesQuery = recipesQuery.Where(() => metadata.NutritionLowCarb); } if (query.Nutrition.LowFat) { recipesQuery = recipesQuery.Where(() => metadata.NutritionLowFat); } if (query.Nutrition.LowSodium) { recipesQuery = recipesQuery.Where(() => metadata.NutritionLowSodium); } if (query.Nutrition.LowSugar) { recipesQuery = recipesQuery.Where(() => metadata.NutritionLowSugar); } return recipesQuery; }
private static IQueryOver<Recipes, Recipes> SearchByMeal( RecipeQuery query, IQueryOver<Recipes, Recipes> recipesQuery, RecipeMetadata metadata) { if (query.Meal != MealFilter.All) { if (query.Meal == MealFilter.Breakfast) { recipesQuery = recipesQuery.Where(() => metadata.MealBreakfast); } if (query.Meal == MealFilter.Dessert) { recipesQuery = recipesQuery.Where(() => metadata.MealDessert); } if (query.Meal == MealFilter.Dinner) { recipesQuery = recipesQuery.Where(() => metadata.MealDinner); } if (query.Meal == MealFilter.Lunch) { recipesQuery = recipesQuery.Where(() => metadata.MealLunch); } } return recipesQuery; }
private static IQueryOver<Recipes, Recipes> SearchByHighResolutionPhotos( RecipeQuery query, IQueryOver<Recipes, Recipes> recipesQuery, RecipeMetadata metadata) { int highResolution = 1024 * 768; if (query.Photos == PhotoFilter.HighRes) { recipesQuery = recipesQuery.Where(() => metadata.PhotoRes >= highResolution); } return recipesQuery; }
/// <summary> /// Searches for recipes matching the specified criteria. /// </summary> /// <param name="query">A RecipeQuery object indicating the recipes to match.</param> /// <returns>A SearchResults object containing recipe briefs and a total count.</returns> public SearchResults RecipeSearch(RecipeQuery query) { if (searchProvder == null) searchProvder = new StaticSearch(store); return searchProvder.Search(Identity, query); }
public SearchResults RecipeSearch(AuthIdentity identity, RecipeQuery query) { if (SearchProvider == null) throw new NoConfiguredSearchProvidersException(); return SearchProvider.Search(identity, query); }
public object Clone() { var clonedQuery = new RecipeQuery() { Keywords = this.Keywords, Rating = this.Rating, Meal = this.Meal, Offset = this.Offset, Photos = this.Photos, Sort = this.Sort, Direction = this.Direction, Time = this.Time.Clone() as TimeFilter, Diet = this.Diet.Clone() as DietFilter, Nutrition = this.Nutrition.Clone() as NutritionFilter, Skill = this.Skill.Clone() as SkillFilter, Taste = this.Taste.Clone() as TasteFilter }; if (this.Include != null) { clonedQuery.Include = this.Include.Clone() as Guid[]; } if (this.Exclude != null) { clonedQuery.Exclude = this.Exclude.Clone() as Guid[]; } return clonedQuery; }
public SearchResults Search(AuthIdentity identity, RecipeQuery query) { var index = this.store.GetSearchIndex(); var q = index.Where(p => !p.Recipe.Hidden); if (!string.IsNullOrWhiteSpace(query.Keywords)) { q = q.Where(p => (p.Recipe.Title ?? string.Empty).IndexOf(query.Keywords, StringComparison.OrdinalIgnoreCase) >= 0 || (p.Recipe.Description ?? string.Empty).IndexOf(query.Keywords, StringComparison.OrdinalIgnoreCase) >= 0); } if (query.Time.MaxPrep.HasValue) { q = q.Where(p => p.Recipe.PreparationTime <= query.Time.MaxPrep.Value); } if (query.Time.MaxCook.HasValue) { q = q.Where(p => p.Recipe.CookTime <= query.Time.MaxCook.Value); } if (query.Rating > 0) { q = q.Where(p => p.Recipe.Rating >= (int)query.Rating.Value); } if (query.Include != null && query.Include.Length > 0) { // Add ingredients to include q = q.Where(p => p.Ingredients.Any(i => query.Include.Contains(i.IngredientId))); } if (query.Exclude != null && query.Exclude.Length > 0) { // Add ingredients to exclude q = q.Where(p => !p.Ingredients.Any(i => query.Exclude.Contains(i.IngredientId))); } if (query.Photos == PhotoFilter.Photo || query.Photos == PhotoFilter.HighRes) { q = q.Where(p => p.Recipe.ImageUrl != null); } // Need to search in metadata if (query.Diet || query.Nutrition || query.Skill || query.Taste || query.Meal != MealFilter.All || query.Photos == PhotoFilter.HighRes) { // Meal if (query.Meal != MealFilter.All) { switch (query.Meal) { case MealFilter.Breakfast: q = q.Where(p => p.Metadata.MealBreakfast); break; case MealFilter.Lunch: q = q.Where(p => p.Metadata.MealLunch); break; case MealFilter.Dinner: q = q.Where(p => p.Metadata.MealDinner); break; case MealFilter.Dessert: q = q.Where(p => p.Metadata.MealDessert); break; default: break; } } // High-resolution photos if (query.Photos == PhotoFilter.HighRes) { q = q.Where(p => p.Metadata.PhotoResolution >= 1024 * 768); } // Diet if (query.Diet.GlutenFree) { q = q.Where(p => p.Metadata.DietGlutenFree); } if (query.Diet.NoAnimals) { q = q.Where(p => p.Metadata.DietNoAnimals); } if (query.Diet.NoMeat) { q = q.Where(p => p.Metadata.DietNomeat); } if (query.Diet.NoPork) { q = q.Where(p => p.Metadata.DietNoPork); } if (query.Diet.NoRedMeat) { q = q.Where(p => p.Metadata.DietNoRedMeat); } // Nutrition if (query.Nutrition.LowCalorie) { q = q.Where(p => p.Metadata.NutritionLowCalorie); } if (query.Nutrition.LowCarb) { q = q.Where(p => p.Metadata.NutritionLowCarb); } if (query.Nutrition.LowFat) { q = q.Where(p => p.Metadata.NutritionLowFat); } if (query.Nutrition.LowSodium) { q = q.Where(p => p.Metadata.NutritionLowSodium); } if (query.Nutrition.LowSugar) { q = q.Where(p => p.Metadata.NutritionLowSugar); } // Skill if (query.Skill.Common) { q = q.Where(p => p.Metadata.SkillCommonIngredients).OrderByDescending(p => p.Metadata.Commonality); } if (query.Skill.Easy) { q = q.Where(p => p.Metadata.SkillEasyToMake); } if (query.Skill.Quick) { q = q.Where(p => p.Metadata.SkillQuick); } // Taste if (query.Taste.MildToSpicy != SpicinessLevel.Medium) { q = query.Taste.MildToSpicy < SpicinessLevel.Medium ? q.Where(p => p.Metadata.TasteMildToSpicy <= query.Taste.Spiciness).OrderBy(p => p.Metadata.TasteMildToSpicy) : q.Where(p => p.Metadata.TasteMildToSpicy >= query.Taste.Spiciness).OrderByDescending(p => p.Metadata.TasteMildToSpicy); } if (query.Taste.SavoryToSweet != SweetnessLevel.Medium) { q = query.Taste.SavoryToSweet < SweetnessLevel.Medium ? q.Where(p => p.Metadata.TasteSavoryToSweet <= query.Taste.Sweetness).OrderBy(p => p.Metadata.TasteSavoryToSweet) : q.Where(p => p.Metadata.TasteSavoryToSweet >= query.Taste.Sweetness).OrderByDescending(p => p.Metadata.TasteSavoryToSweet); } } switch (query.Sort) { case SortOrder.Title: q = (query.Direction == SortDirection.Ascending) ? q.OrderBy(p => p.Recipe.Title) : q.OrderByDescending(p => p.Recipe.Title); break; case SortOrder.PrepTime: q = (query.Direction == SortDirection.Ascending) ? q.OrderBy(p => p.Recipe.PreparationTime) : q.OrderByDescending(p => p.Recipe.PreparationTime); break; case SortOrder.CookTime: q = (query.Direction == SortDirection.Ascending) ? q.OrderBy(p => p.Recipe.CookTime) : q.OrderByDescending(p => p.Recipe.CookTime); break; case SortOrder.Image: q = (query.Direction == SortDirection.Ascending) ? q.OrderBy(p => p.Recipe.ImageUrl) : q.OrderByDescending(p => p.Recipe.ImageUrl); break; default: q = (query.Direction == SortDirection.Ascending) ? q.OrderBy(p => p.Recipe.Rating) : q.OrderByDescending(p => p.Recipe.Rating); break; } return new SearchResults { Briefs = q.Select(r => Data.DTO.Recipes.ToRecipeBrief(r.Recipe)).ToArray(), TotalCount = q.Count() }; }
public SearchResults RecipeSearch(RecipeQuery query) { this.RSCalledTimes++; this.search = query; return new SearchResults(); }
/// <summary> /// Searches for recipes matching the specified criteria. /// </summary> /// <param name="query">A RecipeQuery object indicating the recipes to match.</param> /// <returns>A SearchResults object containing recipe briefs and a total count.</returns> public SearchResults RecipeSearch(RecipeQuery query) { if (this.searchProvder == null) { this.searchProvder = new StaticSearch(this.store); } return this.searchProvder.Search(this.Identity, query); }
public RecipeFinder(IKPCContext context, RecipeQuery query) { this.context = context; this.query = query; }
public RecipeFinder Search(RecipeQuery query) { var result = new RecipeFinder(this.context, query); return result; }
private static IQueryOver<Recipes, Recipes> AddIngredientsToInclude( RecipeQuery query, IQueryOver<Recipes, Recipes> subQuery, Recipes recipe) { if (query.Include != null && query.Include.Length > 0) { // Add ingredients to include // Create a sub-query for ingredients to include subQuery = subQuery.WithSubquery.WhereExists( QueryOver.Of<RecipeIngredients>() .Where(item => item.Recipe.RecipeId == recipe.RecipeId) .Where(Restrictions.InG("Ingredient", query.Include.Select(Ingredients.FromId).ToArray())) .Select(i => i.RecipeIngredientId) .Take(1)); } return subQuery; }
public RecipeQueryBuilder(RecipeQuery query) { this.query = query; }
public RecipeFinder Search(RecipeQuery query) { return new RecipeFinder(context, query); }
public SearchResults RecipeSearch(RecipeQuery query) { throw new NotImplementedException(); }
public RecipeQueryBuilder HasPhoto(RecipeQuery.PhotoFilter photoFilter) { query.Photos = photoFilter; return this; }