Ejemplo n.º 1
0
        private List <Recipe> SearchByQuery(string query)
        {
            var tokenaizedSearchValues = TokanizationHelper.Tokenaize(query);

            var recipesBeforeSort =
                _dbManager.
                RecipesCollection.
                Find(
                    recipe =>
                    tokenaizedSearchValues.
                    Any(value => recipe.ValuesToSearch.Contains(value))).
                ToList();

            var recipesWithRank = new List <RecipeWithRank>();

            foreach (var recipe in recipesBeforeSort)
            {
                var recipeWithRank = new RecipeWithRank(recipe, CheckNumberOfMatchValues(recipe, tokenaizedSearchValues));

                recipesWithRank.Add(recipeWithRank);
            }

            var matchToQueryAfterSort = recipesWithRank.OrderByDescending(recipeWithRank => recipeWithRank.Rank);
            var recipesAfterSort      = new List <Recipe>();

            foreach (var recipeWithRank in matchToQueryAfterSort)
            {
                recipesAfterSort.Add(recipeWithRank.Recipe);
            }

            return(recipesAfterSort);
        }
Ejemplo n.º 2
0
        protected override async Task <Recipe> ScrapeInternalAsync(string url)
        {
            Console.WriteLine($"{nameof(ShefLavanScraper)} {nameof(ScrapeInternalAsync)} started [{nameof(url)}={url}]");

            var web     = new HtmlWeb();
            var htmlDoc = await web.LoadWithRetryAsync(url);

            var title           = htmlDoc.DocumentNode.SelectSingleNode("//meta[@property='og:title']").GetAttributeValue("content", "");
            var image           = htmlDoc.DocumentNode.SelectSingleNode("//meta[@property='og:image']").GetAttributeValue("content", "");
            var preparationTime = htmlDoc.DocumentNode.SelectSingleNode("//div[@class='short-properties bold']/span[@class='cooking-time']")?.InnerText;
            var link            = htmlDoc.DocumentNode.SelectSingleNode("//meta[@property='og:url']").GetAttributeValue("content", "");
            var numberOfDishes  = htmlDoc.DocumentNode.SelectSingleNode("//div[@class='properties']/span[@class='property']/strong")?.InnerText;
            var ingredients     = htmlDoc.DocumentNode.SelectNodes("//div[@class='ingredients col-lg-3 col-md-4 col-sm-6 ']/ul[@class='ingredients-list']/li");

            var recipeToAdd = new Recipe
            {
                Id = GetIdFromUrl(link),
                PreparationTime        = preparationTime,
                Link                   = link,
                NumberOfDishes         = GetNumberOfDishes(numberOfDishes),
                Picture                = image,
                RecipeTitle            = title,
                IngredientsList        = CreateIngredientsList(ingredients),
                ValuesToSearch         = TokanizationHelper.Tokenaize(title),
                NormalaizedIngredients = CreatenormalaizedIngredientsList(ingredients)
            };

            Console.WriteLine($"{nameof(ShefLavanScraper)} {nameof(ScrapeInternalAsync)} finished.");

            return(recipeToAdd);
        }
Ejemplo n.º 3
0
        protected override async Task <Recipe> ScrapeInternalAsync(string url)
        {
            Console.WriteLine($"{nameof(MakoScraper)} {nameof(ScrapeInternalAsync)} started [{nameof(url)}={url}]");

            var web     = new HtmlWeb();
            var htmlDoc = await web.LoadWithRetryAsync(url);

            var title       = htmlDoc.DocumentNode.SelectSingleNode("//meta[@property='og:title']").GetAttributeValue("content", "");
            var image       = htmlDoc.DocumentNode.SelectSingleNode("//meta[@property='og:image']").GetAttributeValue("content", "");
            var prepTime    = htmlDoc.DocumentNode.SelectSingleNode("//ul[@class='table_container']/li[@class='titleContainer']/div/span[@itemprop='totalTime']")?.InnerText;
            var link        = htmlDoc.DocumentNode.SelectSingleNode("//meta[@property='og:url']").GetAttributeValue("content", "");
            var numOfDishes = htmlDoc.DocumentNode.SelectNodes("//div[@class='ingredients']/h3[@class='IngredientsTitle fontSize']")?.First().InnerText;
            var ingredients = htmlDoc.DocumentNode.SelectNodes("//div[@class='ingredients']/ul[@class='recipeIngredients']/li/span");

            var recipeToAdd = new Recipe
            {
                Id = GetIdFromUrl(link),
                PreparationTime        = prepTime,
                Link                   = link,
                NumberOfDishes         = GetNumberOfDishes(numOfDishes),
                Picture                = image,
                RecipeTitle            = title,
                IngredientsList        = CreateIngredientsList(ingredients),
                ValuesToSearch         = TokanizationHelper.Tokenaize(title),
                NormalaizedIngredients = CreatenormalaizedIngredientsList(ingredients)
            };

            Console.WriteLine($"{nameof(MakoScraper)} {nameof(ScrapeInternalAsync)} finished.");

            return(recipeToAdd);
        }
Ejemplo n.º 4
0
        public List <string> CreatenormalaizedIngredientsList(HtmlNodeCollection ingredients)
        {
            List <string> normalaizedIngredients = new List <string>();

            for (int currIngredientsIndex = 0; currIngredientsIndex < ingredients.Count; currIngredientsIndex++)
            {
                string        ingredient       = ingredients[currIngredientsIndex].InnerText;
                List <string> ingredientValues = TokanizationHelper.Tokenaize(ingredient);

                for (int ingredientValueIndex = 0; ingredientValueIndex < ingredientValues.Count; ingredientValueIndex++)
                {
                    normalaizedIngredients.Add(ingredientValues[ingredientValueIndex]);
                }
            }

            return(normalaizedIngredients);
        }