public List <RecipeAbstractModel> SearchRecipesWithQueryText(RecipeSearchOptions options) { var recipes = this.dbContext.Set <RecipeAbstract>() .FromSqlInterpolated($"spSearchRecipes @QueryText={options.QueryText}, @Difficulty={options.Difficulty}, @Spicy={options.Spicy}") .ToList(); return(this._mapper.Map <List <RecipeAbstractModel> >(recipes)); }
public List <RecipeAbstractModel> SearchRecipes(RecipeSearchOptions options) { if (options.QueryText == null) { return(this.SearchRecipesWithoutQueryText(options)); } else { return(this.SearchRecipesWithQueryText(options)); } }
public ActionResult RecipeFinder(RecipeSearchOptions recipeSearchOptions) { var recipes = this.RecipeSearchService.SearchRecipes(recipeSearchOptions); if (!recipes.Any()) { this.AppendMessage(new InfoMessage { Text = "We couldn't find any recipes that match your search options" }); return(this.View(recipeSearchOptions)); } return(this.View("RecipeFinderResults", new RecipeSearchResults { RecipeSearchOptions = recipeSearchOptions, Recipes = recipes })); }
public List <RecipeAbstractModel> SearchRecipesWithoutQueryText(RecipeSearchOptions options) { var query = this._recipeRepository.Query(); if (options.Difficulty != null) { query = query.Where(x => x.Difficulty == options.Difficulty); } if (options.Spicy != null) { query = query.Where(x => x.Spicy == options.Spicy); } if (options.AuthorId != null) { query = query.Where(x => x.AuthorId == options.AuthorId); } if (options.LikeByUserId != null) { query = query.Where(x => x.Liked.Any(lr => lr.UserId == options.LikeByUserId)); } var recipes = query.Include(x => x.Author).Include(x => x.Liked); return(this._mapper.Map <List <RecipeAbstractModel> >(recipes.ToList())); }
public ActionResult <List <RecipeAbstractModel> > Search([FromQuery] RecipeSearchOptions options) { return(this._recipeService.SearchRecipes(options)); }
/// <summary> /// Searches for recipes /// </summary> public IList <RecipeSummary> SearchRecipes(RecipeSearchOptions recipeSearchOptions) { var query = this.Repository.GetSet <Recipe>() .Where(x => x.IsActive && x.IsPublic); // Recipe Types if (recipeSearchOptions.RecipeTypes.Any()) { query = query.WhereIn(x => x.RecipeTypeId, recipeSearchOptions.RecipeTypes.Select(y => (int)y)); } // Recipe Styles if (recipeSearchOptions.RecipeStyles.Any()) { query = query.WhereIn(x => x.BjcpStyleSubCategoryId, recipeSearchOptions.RecipeStyles); } // Appears to be a Clone if (recipeSearchOptions.IsClone) { query = query.Where(x => !x.RecipeName.StartsWith("Clone of")); query = query.Where(x => x.RecipeName.Contains(" clone") || x.RecipeName.Contains("clone ")); } // Has Brew Sessions if (recipeSearchOptions.HasBrewSessions) { query = query.Where(x => x.BrewSessions.Any(y => y.IsActive && y.IsPublic)); } // Has Tasting Notes if (recipeSearchOptions.HasTastingNotes) { query = query.Where(x => x.RecipeMetaData.TastingNoteCount > 0); } // Has Comments if (recipeSearchOptions.HasComments) { query = query.Where(x => x.RecipeComments.Any(y => y.IsActive)); } // Search Terms if (!string.IsNullOrWhiteSpace(recipeSearchOptions.SearchTerm)) { var words = recipeSearchOptions.SearchTerm.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); if (recipeSearchOptions.AndSearchTerm) { query = query.Where(x => words.All(y => x.RecipeName.Contains(y) || x.Description.Contains(y))); } else { query = query.Where(x => words.Any(y => x.RecipeName.Contains(y) || x.Description.Contains(y))); } } // Limit Results to 100 (to show on one page for now) return(query .OrderByDescending(x => x.DateCreated) .Take(100) .Select(x => x.RecipeSummary) .ToList()); }