public JsonResult CompleteHashTags(string term) { var hashTags = HashTagSearcher.Search(term, "Value", 5).Select( h => h.Value); return(Json(hashTags, JsonRequestBehavior.AllowGet)); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); ApplicationDbContext db = new ApplicationDbContext(); PostcardSearcher.ClearIndex(); PostcardSearcher.AddUpdateLuceneIndex(db.Postcards); HashTagSearcher.ClearIndex(); HashTagSearcher.AddUpdateLuceneIndex(db.HashTags); }
public static void AddHashTag(this Postcard postcard, string hashTag) { using (ApplicationDbContext db = new ApplicationDbContext()) { postcard = db.Postcards.Single(p => p.Id == postcard.Id); HashTag existingHashTag = db.HashTags.SingleOrDefault(h => h.Value == hashTag); if (existingHashTag == null) { existingHashTag = new HashTag { Value = hashTag }; HashTagSearcher.AddUpdateLuceneIndex(existingHashTag); } postcard.HashTags.Add(existingHashTag); db.SaveChanges(); } }