예제 #1
0
        /// <summary>
        /// Finds related recipes based on the ingredients
        /// </summary>
        /// <param name="recipe"></param>
        /// <returns></returns>
        public IEnumerable<SearchHit> FindRelated(Recipe recipe)
        {
            using (var indexReader = IndexReader.Open(_directory, true))
            {
                BooleanQuery ingredientsQuery = new BooleanQuery();
                QueryParser parser =new QueryParser(Version.LUCENE_30, "recipe-ingredient",_analyzer);

                foreach (var ingredient in recipe.Ingredients)
                {
                    Query queryPart = parser.Parse(ingredient.Name);
                    ingredientsQuery.Add(new BooleanClause(queryPart, Occur.SHOULD));
                }

                // Make the final query where at least one ingredient must be included
                BooleanQuery searchQuery = new BooleanQuery();
                searchQuery.Add(ingredientsQuery,Occur.MUST);

                // Exclude the original item, because that one will definitely look like the ones we're looking for.
                string recipeId = recipe.RecipeId.ToString(CultureInfo.InvariantCulture);
                searchQuery.Add(new BooleanClause(new TermQuery(new Term("id", recipeId)), Occur.MUST_NOT));

                return PerformSearchQuery(searchQuery, indexReader);
            }
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Recipes EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToRecipes(Recipe recipe)
 {
     base.AddObject("Recipes", recipe);
 }
 /// <summary>
 /// Create a new Recipe object.
 /// </summary>
 /// <param name="recipeId">Initial value of the RecipeId property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="description">Initial value of the Description property.</param>
 /// <param name="cookingInstructions">Initial value of the CookingInstructions property.</param>
 /// <param name="timeNeeded">Initial value of the TimeNeeded property.</param>
 /// <param name="dateCreated">Initial value of the DateCreated property.</param>
 /// <param name="createdBy">Initial value of the CreatedBy property.</param>
 /// <param name="version">Initial value of the Version property.</param>
 /// <param name="rating">Initial value of the Rating property.</param>
 public static Recipe CreateRecipe(global::System.Decimal recipeId, global::System.String name, global::System.String description, global::System.String cookingInstructions, global::System.TimeSpan timeNeeded, global::System.DateTime dateCreated, global::System.String createdBy, global::System.Byte[] version, global::System.Decimal rating)
 {
     Recipe recipe = new Recipe();
     recipe.RecipeId = recipeId;
     recipe.Name = name;
     recipe.Description = description;
     recipe.CookingInstructions = cookingInstructions;
     recipe.TimeNeeded = timeNeeded;
     recipe.DateCreated = dateCreated;
     recipe.CreatedBy = createdBy;
     recipe.Version = version;
     recipe.Rating = rating;
     return recipe;
 }