/// <summary> /// Delete all ad/lucene images and remove from lucene /// </summary> /// <param name="ad"></param> public static void DeletePhotosFromLuceneIndex(int adId, string stringId, IEnumerable <ClassifiedAdPhoto> photos) { var lucenerecord = SearchEngineManager.GetClassifiedAdWithDetails(adId); // delete photos var dir = HostingEnvironment.MapPath("~/Photos/" + stringId.Substring(2, 4) + "/" + stringId.Substring(0, 4)); var lucenepath = Path.Combine(dir, "lucene"); if (photos != null) { foreach (var pho in photos) { try { // Delete Regular if (File.Exists(Path.Combine(dir, pho.AdDetails_FileName))) { File.Delete(Path.Combine(dir, pho.AdDetails_FileName)); } if (File.Exists(Path.Combine(dir, pho.AdList_FileName))) { File.Delete(Path.Combine(dir, pho.AdList_FileName)); } if (File.Exists(Path.Combine(dir, pho.Raw_FileName))) { File.Delete(Path.Combine(dir, pho.Raw_FileName)); } } catch (Exception) { } } } if (lucenerecord != null && lucenerecord.Photos != null) { foreach (var pho in lucenerecord.Photos) { // Delete Lucene if (File.Exists(Path.Combine(lucenepath, pho.AdDetails_FileName))) { File.Delete(Path.Combine(lucenepath, pho.AdDetails_FileName)); } if (File.Exists(Path.Combine(lucenepath, pho.AdList_FileName))) { File.Delete(Path.Combine(lucenepath, pho.AdList_FileName)); } if (File.Exists(Path.Combine(lucenepath, pho.Raw_FileName))) { File.Delete(Path.Combine(lucenepath, pho.Raw_FileName)); } } } // Delete temp folder PhotoFileManager.DeleteTempPhotos(adId, stringId); }
public static void AddUpdateLuceneIndex(ClassifiedAdLucene sampleData) { var oldlucenerecord = SearchEngineManager.GetClassifiedAdWithDetails(sampleData.Id); var dir = HostingEnvironment.MapPath("~/Photos/" + sampleData.StringId.Substring(2, 4) + "/" + sampleData.StringId.Substring(0, 4)); var lucenepath = Path.Combine(dir, "lucene"); // init lucene using (var analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30)) using (var writer = new IndexWriter(_write, analyzer, IndexWriter.MaxFieldLength.UNLIMITED)) { var searchQuery = new TermQuery(new Term("Id", sampleData.Id.ToString())); writer.DeleteDocuments(searchQuery); // Add Document doc = null; var ManagerSeo = new SeoManager(); _createLuceneIndex(sampleData, writer, ManagerSeo, doc); } var newlucenerecord = SearchEngineManager.GetClassifiedAdWithDetails(sampleData.Id); // Compare photos for changes and remove unused if (oldlucenerecord != null && newlucenerecord != null) { var photostodelete = oldlucenerecord.Photos.Except(newlucenerecord.Photos, new PhotoComparer()); foreach (var pho in photostodelete) { // Delete Lucene if (File.Exists(Path.Combine(lucenepath, pho.AdDetails_FileName))) { File.Delete(Path.Combine(lucenepath, pho.AdDetails_FileName)); } if (File.Exists(Path.Combine(lucenepath, pho.AdList_FileName))) { File.Delete(Path.Combine(lucenepath, pho.AdList_FileName)); } if (File.Exists(Path.Combine(lucenepath, pho.Raw_FileName))) { File.Delete(Path.Combine(lucenepath, pho.Raw_FileName)); } } } }
/// <summary> /// Generate Ad Detail Url From LUCENE /// </summary> /// <param name="stringId"></param> /// <returns></returns> public string GenerateAdDetailUrl(int Id) { var key = string.Format("ld-{0}", Id); var urlCache = CacheHelper.GetFromCache <string>(key); if (urlCache != null) { return(urlCache); } var format = "/cld-{0}/{1}/{2}/{3}"; string returnUrl; var ad = SearchEngineManager.GetClassifiedAdWithDetails(Id); if (ad == null) { return(null); } returnUrl = string.Format(format, CategorySlug(ad.Category.Id, ad.SubCategory.Id, ad.Category.Name, ad.SubCategory.Name), LocationSlug(ad.Country.Id, ad.Region.Id), ad.Id, TitleSlug(ad.Title)); CacheHelper.SaveTocache(key, returnUrl, DateTime.Now.AddHours(1)); return(returnUrl); }