Esempio n. 1
0
        public void Page_Load(object sender, EventArgs e)
        {
            if (IsForbidden)
            {
                return;
            }

            if (IsPostBack)
            {
                return;
            }

            if (!Body.IsQueryExists("SeoMetaID"))
            {
                return;
            }
            var seoMetaId   = Body.GetQueryInt("SeoMetaID");
            var seoMetaInfo = DataProvider.SeoMetaDao.GetSeoMetaInfo(seoMetaId);

            if (seoMetaInfo == null)
            {
                return;
            }

            MetaName.Text = seoMetaInfo.SeoMetaName;
            MetaCode.Text = SeoManager.GetMetaContent(seoMetaInfo);
        }
Esempio n. 2
0
        public Category AddCategory(Category newItem)
        {
            var addeditem = CurrentDbContext.CategoryDB.Add(newItem);

            addeditem.SubCategories = null;
            addeditem.SeoName       = SeoManager.GetSeoCategory(addeditem.Name);
            CurrentDbContext.SaveChanges();
            return(addeditem);
        }
Esempio n. 3
0
        public Category EditCategory(Category item)
        {
            Category var = CurrentDbContext.CategoryDB.SingleOrDefault(c => c.Id == item.Id);

            var.Name    = item.Name;
            var.SeoName = SeoManager.GetSeoCategory(var.Name);
            CurrentDbContext.SaveChanges();
            return(var);
        }
Esempio n. 4
0
        public SubCategory EditSubCat(SubCategoryEdit item)
        {
            SubCategory var = CurrentDbContext.SubCategoryDB.Include("Category").SingleOrDefault(s => s.StringId == item.StringId);

            var.Name    = item.Name;
            var.SeoName = SeoManager.GetSeoCategory(var.Category.Name, var.Name);
            CurrentDbContext.SaveChanges();

            return(var);
        }
Esempio n. 5
0
        public void DeleteMatch(int publishmentSystemId, int nodeId, bool isChannel)
        {
            var parms = new IDataParameter[]
            {
                GetParameter(ParmNodeId, EDataType.Integer, nodeId),
                GetParameter(ParmIsChannel, EDataType.VarChar, 18, isChannel.ToString()),
            };

            ExecuteNonQuery(SqlDeleteMatchByNodeId, parms);
            SeoManager.RemoveCache(publishmentSystemId);
        }
Esempio n. 6
0
 public CountryBase AddCountry(CountryAdd newItem)
 {
     if (!CurrentDbContext.CountryDB.Any(a => a.Name.Contains(newItem.Name)))
     {
         var addedItem = CurrentDbContext.CountryDB.Add(Mapper.Map <Country>(newItem));
         addedItem.SeoName = SeoManager.GetSeoLocation(addedItem.Name);
         CurrentDbContext.SaveChanges();
         return((addedItem == null) ? null : Mapper.Map <CountryBase>(addedItem));
     }
     return(null);
 }
Esempio n. 7
0
        /// <summary>
        /// Get one ad with details for ListDetail.cshtml
        /// </summary>
        /// <param name="stringId"></param>
        /// <returns></returns>w
        public ClassifiedAdWithDetail GetClassifiedAdWithDetails(string stringId)
        {
            // Check for session id
            var ad = CurrentDbContext.ClassifiedDB.ProjectTo <ClassifiedAdWithDetail>().FirstOrDefault(x => x.StringId == stringId);

            if (ad != null)
            {
                ad.SeoCategory = SeoManager.GetSeoCategory(ad.Category.Id, ad.SubCategory.Id);
                ad.SeoLocation = SeoManager.GetSeoLocation(ad.Country.Id, ad.Region.Id);
            }
            return(ad);
        }
Esempio n. 8
0
 protected override void Dispose(bool disposing)
 {
     if (_classifiedAdManager != null)
     {
         _classifiedAdManager.Dispose();
         _classifiedAdManager = null;
     }
     if (_seoManager != null)
     {
         _seoManager.Dispose();
         _seoManager = null;
     }
     base.Dispose(disposing);
 }
Esempio n. 9
0
        public static bool IsSeoMetaExists(PageInfo pageInfo)
        {
            var arraylists = SeoManager.GetSeoMetaArrayLists(pageInfo.PublishmentSystemId);

            if (pageInfo.PageContentId != 0)
            {
                var arraylist = arraylists[1];
                return(arraylist.Contains(pageInfo.PageNodeId));
            }
            else
            {
                var arraylist = arraylists[0];
                return(arraylist.Contains(pageInfo.PageNodeId));
            }
        }
Esempio n. 10
0
        protected void FillSeoInformation(string pageName)
        {
            string name = pageName;
            string desc = "";

            try
            {
                var seo = SeoManager.GetSeoInformation(this.CurrentBrand, pageName);
                name = seo.PageTitle;
                desc = seo.MetaDescription;
            }
            catch { }

            ViewBag.Title       = name;
            ViewBag.Description = desc;
        }
Esempio n. 11
0
        public RegionBase EditRegion(RegionEdit editItem)
        {
            var o = CurrentDbContext.RegionDB.Include("Country").SingleOrDefault(r => r.Id == editItem.Id);

            if (o != null)
            {
                o.Name    = editItem.Name;
                o.Lat     = editItem.Lat;
                o.Lng     = editItem.Lng;
                o.Zoom    = editItem.Zoom;
                o.SeoName = SeoManager.GetSeoLocation(o.Country.Name, o.Name);
                CurrentDbContext.SaveChanges();
            }

            return((o == null) ? null : Mapper.Map <RegionBase>(editItem));
        }
Esempio n. 12
0
 // Bulk Add
 public static void AdminCreateLuceneIndex(IEnumerable <ClassifiedAdLucene> data)
 {
     // init lucene
     using (var analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30))
         using (var writer = new IndexWriter(_write, analyzer, IndexWriter.MaxFieldLength.UNLIMITED))
         {
             // add new index entry
             // add new index entry
             Document doc        = null;
             var      ManagerSeo = new SeoManager();
             // add data to lucene search index (replaces older entry if any)
             foreach (var sampleData in data)
             {
                 _createLuceneIndex(sampleData, writer, ManagerSeo, doc);
             }
             ;
         }
 }
Esempio n. 13
0
        public SubCategory AddSubCategory(SubCategoryAdd newItem)
        {
            SubCategory addeditem = Mapper.Map <SubCategory>(newItem);

            addeditem.StringId = MySecurity.GetGen();
            var cat = CurrentDbContext.CategoryDB.Include("SubCategories").SingleOrDefault(x => x.Id == newItem.CategoryId);

            cat.SubCategories.Add(addeditem);
            addeditem.Category = cat;
            CurrentDbContext.SaveChanges();
            if (addeditem.Category.Name == "Business Services")
            {
                addeditem.AdInfoTemplate = CurrentDbContext.TemplateDB.FirstOrDefault(x => x.TemplateName == "BUSSERV");
            }
            addeditem.SeoName = SeoManager.GetSeoCategory(addeditem.Category.Name, addeditem.Name);
            CurrentDbContext.SaveChanges();

            return(addeditem);
        }
Esempio n. 14
0
        //siteserver_SeoMetasInNodes
        public void InsertMatch(int publishmentSystemId, int nodeId, int seoMetaId, bool isChannel)
        {
            var lastSeoMetaId = GetSeoMetaIdByNodeId(nodeId, isChannel);

            if (lastSeoMetaId != 0)
            {
                DeleteMatch(publishmentSystemId, nodeId, isChannel);
            }

            var insertParms = new IDataParameter[]
            {
                GetParameter(ParmNodeId, EDataType.Integer, nodeId),
                GetParameter(ParmIsChannel, EDataType.VarChar, 18, isChannel.ToString()),
                GetParameter(ParmSeoMetaId, EDataType.Integer, seoMetaId),
                GetParameter(ParmPublishmentSystemId, EDataType.Integer, publishmentSystemId),
            };

            ExecuteNonQuery(SqlInsertMatch, insertParms);
            SeoManager.RemoveCache(publishmentSystemId);
        }
Esempio n. 15
0
        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));
                    }
                }
            }
        }
Esempio n. 16
0
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            if (Page.IsPostBack && Page.IsValid)
            {
                PublishmentSystemInfo.Additional.SiteMapBaiduPath       = SiteMapBaiduPath.Text;
                PublishmentSystemInfo.Additional.SiteMapBaiduUpdatePeri = SiteMapBaiduUpdatePeri.Text;
                PublishmentSystemInfo.Additional.SiteMapBaiduWebMaster  = SiteMapBaiduWebMaster.Text;

                try
                {
                    DataProvider.PublishmentSystemDao.Update(PublishmentSystemInfo);
                    SeoManager.CreateSiteMapBaidu(PublishmentSystemInfo);
                    Body.AddSiteLog(PublishmentSystemId, "生成百度新闻地图");
                    SuccessMessage("百度新闻地图生成成功!");
                }
                catch (Exception ex)
                {
                    FailMessage(ex, "百度新闻地图生成失败!");
                }
            }
        }
Esempio n. 17
0
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            if (Page.IsPostBack && Page.IsValid)
            {
                PublishmentSystemInfo.Additional.SiteMapGooglePath               = SiteMapGooglePath.Text;
                PublishmentSystemInfo.Additional.SiteMapGoogleChangeFrequency    = SiteMapGoogleChangeFrequency.SelectedValue;
                PublishmentSystemInfo.Additional.SiteMapGoogleIsShowLastModified = TranslateUtils.ToBool(SiteMapGoogleIsShowLastModified.SelectedValue);
                PublishmentSystemInfo.Additional.SiteMapGooglePageCount          = TranslateUtils.ToInt(SiteMapGooglePageCount.Text);

                try
                {
                    DataProvider.PublishmentSystemDao.Update(PublishmentSystemInfo);
                    SeoManager.CreateSiteMapGoogle(PublishmentSystemInfo);
                    Body.AddSiteLog(PublishmentSystemId, "生成谷歌站点地图");
                    SuccessMessage("谷歌站点地图生成成功!");
                }
                catch (Exception ex)
                {
                    FailMessage(ex, "谷歌站点地图生成失败!");
                }
            }
        }
Esempio n. 18
0
        public RegionBase AddRegion(RegionAdd newItem)
        {
            // get associated object
            var o = CurrentDbContext.CountryDB.Include("Regions").SingleOrDefault(a => a.Id == newItem.CountryId);

            if (o == null)
            {
                return(Mapper.Map <RegionBase>(newItem));
            }

            // check for duplicate region
            var dup = o.Regions.SingleOrDefault(a => a.Name == newItem.Name);

            if (!o.Regions.Any(a => a.Name == newItem.Name))
            {
                var addedItem = CurrentDbContext.RegionDB.Add(Mapper.Map <Region>(newItem));
                addedItem.Country = o;
                addedItem.SeoName = SeoManager.GetSeoLocation(addedItem.Country.Name, addedItem.Name);
                o.RegionCount++;
                CurrentDbContext.SaveChanges();
                return((addedItem == null) ? null : Mapper.Map <RegionBase>(addedItem));
            }
            return(Mapper.Map <RegionBase>(newItem));
        }
Esempio n. 19
0
        private static void AddSeoMetaToContent(PageInfo pageInfo, StringBuilder contentBuilder)
        {
            if (IsSeoMetaExists(pageInfo))
            {
                int seoMetaId;
                if (pageInfo.PageContentId != 0)
                {
                    seoMetaId = DataProvider.SeoMetaDao.GetSeoMetaIdByNodeId(pageInfo.PageNodeId, false);
                    if (seoMetaId == 0)
                    {
                        seoMetaId = DataProvider.SeoMetaDao.GetDefaultSeoMetaId(pageInfo.PublishmentSystemId);
                    }
                }
                else
                {
                    seoMetaId = DataProvider.SeoMetaDao.GetSeoMetaIdByNodeId(pageInfo.PageNodeId, true);
                    if (seoMetaId == 0)
                    {
                        seoMetaId = DataProvider.SeoMetaDao.GetDefaultSeoMetaId(pageInfo.PublishmentSystemId);
                    }
                }
                if (seoMetaId != 0)
                {
                    var seoMetaInfo             = DataProvider.SeoMetaDao.GetSeoMetaInfo(seoMetaId);
                    var seoMetaInfoFromTemplate = SeoManager.GetSeoMetaInfo(contentBuilder.ToString());
                    if (!string.IsNullOrEmpty(seoMetaInfoFromTemplate.PageTitle))
                    {
                        seoMetaInfo.PageTitle = string.Empty;
                    }
                    if (!string.IsNullOrEmpty(seoMetaInfoFromTemplate.Keywords))
                    {
                        seoMetaInfo.Keywords = string.Empty;
                    }
                    if (!string.IsNullOrEmpty(seoMetaInfoFromTemplate.Description))
                    {
                        seoMetaInfo.Description = string.Empty;
                    }
                    if (!string.IsNullOrEmpty(seoMetaInfoFromTemplate.Copyright))
                    {
                        seoMetaInfo.Copyright = string.Empty;
                    }
                    if (!string.IsNullOrEmpty(seoMetaInfoFromTemplate.Author))
                    {
                        seoMetaInfo.Author = string.Empty;
                    }
                    if (!string.IsNullOrEmpty(seoMetaInfoFromTemplate.Email))
                    {
                        seoMetaInfo.Email = string.Empty;
                    }
                    if (!string.IsNullOrEmpty(seoMetaInfoFromTemplate.Language))
                    {
                        seoMetaInfo.Language = string.Empty;
                    }
                    if (!string.IsNullOrEmpty(seoMetaInfoFromTemplate.Charset))
                    {
                        seoMetaInfo.Charset = string.Empty;
                    }
                    if (!string.IsNullOrEmpty(seoMetaInfoFromTemplate.Distribution))
                    {
                        seoMetaInfo.Distribution = string.Empty;
                    }
                    if (!string.IsNullOrEmpty(seoMetaInfoFromTemplate.Rating))
                    {
                        seoMetaInfo.Rating = string.Empty;
                    }
                    if (!string.IsNullOrEmpty(seoMetaInfoFromTemplate.Robots))
                    {
                        seoMetaInfo.Robots = string.Empty;
                    }
                    if (!string.IsNullOrEmpty(seoMetaInfoFromTemplate.RevisitAfter))
                    {
                        seoMetaInfo.RevisitAfter = string.Empty;
                    }
                    if (!string.IsNullOrEmpty(seoMetaInfoFromTemplate.Expires))
                    {
                        seoMetaInfo.Expires = string.Empty;
                    }

                    var metaContent = SeoManager.GetMetaContent(seoMetaInfo);

                    if (!string.IsNullOrEmpty(metaContent))
                    {
                        StringUtils.InsertBefore("</head>", contentBuilder, metaContent);
                    }
                }
            }
        }
Esempio n. 20
0
        void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext)
        {
#if DEBUG
            var profiler = MiniProfiler.Current;
            using (profiler.Step("url correct"))
            {
#endif
            // base
            OnActionExecuting(filterContext);

            string searchString = null;
            // Append searchString to url
            if (filterContext.ActionParameters.ContainsKey("searchString"))
            {
                searchString = (string)filterContext.ActionParameters["searchString"] ?? null;
                if (searchString != null)
                {
                    filterContext.ActionParameters["searchString"] = (string)GetSearchString(searchString);
                }
            }

            // redirect check .. Read and delete temp value
            if (filterContext.Controller.TempData["wasRedirected"] != null)
            {
                filterContext.Controller.TempData["wasRedirected"] = null; return;
            }
            // Get parameters
            var parameters     = filterContext.ActionParameters;
            string url         = null;
            string requestUrl  = null;
            string searchQuery = null;
            searchQuery = filterContext.RequestContext.HttpContext.Request.QueryString.ToString();
            requestUrl  = filterContext.RequestContext.HttpContext.Request.RawUrl;

            // Check controller
            // If AdLIst
            if (filterContext.ActionDescriptor.ActionName.Equals("AdList"))
            {
                // Allow query strings for catId subCatId CountryId RegionId
                var    newSearchQuery  = HttpUtility.ParseQueryString(searchQuery);
                int    catId           = 0;
                int    subCatId        = 0;
                int    CountryId       = 0;
                int    RegionId        = 0;
                string modelBodyType   = null;
                string modelRentalType = null;

                int.TryParse(newSearchQuery.Get("catId"), out catId);
                newSearchQuery.Remove("catId");
                int.TryParse(newSearchQuery.Get("subCatId"), out subCatId);
                newSearchQuery.Remove("subCatId");
                int.TryParse(newSearchQuery.Get("CountryId"), out CountryId);
                newSearchQuery.Remove("CountryId");
                int.TryParse(newSearchQuery.Get("RegionId"), out RegionId);
                newSearchQuery.Remove("RegionId");
                modelBodyType = newSearchQuery.Get("modelBodyType");
                newSearchQuery.Remove("modelBodyType");
                modelBodyType = newSearchQuery.Get("modelRentalType");
                newSearchQuery.Remove("modelRentalType");

                searchQuery = newSearchQuery.ToString();

                if (catId > 0 || subCatId > 0 || CountryId > 0 || RegionId > 0)
                {
                    if (catId == 0)
                    {
                        catId = (int)parameters["catId"];
                    }
                    if (subCatId == 0)
                    {
                        subCatId = (int)parameters["subCatId"];
                    }
                    if (CountryId == 0)
                    {
                        CountryId = (int)parameters["CountryId"];
                    }
                    if (RegionId == 0)
                    {
                        RegionId = (int)parameters["RegionId"];
                    }
                    url = SeoManager.GenerateAdListUrl(
                        ref catId,
                        ref subCatId,
                        ref CountryId,
                        ref RegionId);
                    if (catId > 0)
                    {
                        parameters["catId"] = catId;
                    }
                    if (subCatId > 0)
                    {
                        parameters["subCatId"] = subCatId;
                    }
                    if (CountryId > 0)
                    {
                        parameters["CountryId"] = CountryId;
                    }
                    if (RegionId > 0)
                    {
                        parameters["RegionId"] = RegionId;
                    }
                }
                else
                {
                    url = SeoManager.GenerateAdListUrl(
                        (int)parameters["catId"],
                        (int)parameters["subCatId"],
                        (int)parameters["CountryId"],
                        (int)parameters["RegionId"]);
                }

                if (url == null)
                {
                    filterContext.Result = new HttpStatusCodeResult(404);
                    return;
                }
                else
                {
                    // Append searchString to url
                    if (filterContext.Controller.TempData["AdSearchIdNotFound"] == null)
                    {
                        url = string.Format("{0}{1}", url, searchString != null ? "/" + new SeoManager().GetSeoTitle(searchString) : null);
                    }
                }

                // check if modelbodytype value is a parameter
                if (modelBodyType == null)
                {
                    modelBodyType = (string)parameters["modelBodyType"];
                }
                // check if modelrentaltype value is a parameter
                if (modelRentalType == null)
                {
                    modelRentalType = (string)parameters["modelRentalType"];
                }

                // insert modelbodytype into url
                if (modelBodyType != null && url.Contains("vehicles-cars-trucks"))
                {
                    url = url.Replace("vehicles-cars-trucks/", "vehicles-cars-trucks/" + modelBodyType + "/");
                }
                // insert modelrentaltype into url
                if (modelRentalType != null && url.Contains("real-estate-apartments-condos-rental"))
                {
                    url = url.Replace("real-estate-apartments-condos-rental/", "real-estate-apartments-condos-rental/" + modelRentalType + "/");
                }
                if (modelRentalType != null && url.Contains("real-estate-land-rental-leasing"))
                {
                    url = url.Replace("real-estate-land-rental-leasing/", "real-estate-land-rental-leasing/" + modelRentalType + "/");
                }
                if (modelRentalType != null && url.Contains("real-estate-house-rental"))
                {
                    url = url.Replace("real-estate-house-rental/", "real-estate-house-rental/" + modelRentalType + "/");
                }
            }

            // If ListDetails
            else if (filterContext.ActionDescriptor.ActionName.Equals("AdDetails"))
            {
                url = SeoManager.GenerateAdDetailUrl((int)parameters["Id"]);
                if (url == null)
                {
                    // check if ad is suspended
                    if (SeoManager.IsAdSuspended((int)parameters["Id"]))
                    {
                        filterContext.Result = new RedirectResult(new UrlHelper(filterContext.RequestContext).Action("AdSuspended", "Errors", new { Area = "" }));
                        return;
                    }
                    filterContext.Result = new HttpStatusCodeResult(410);
                    return;
                }
            }

            // Compare ulrs
            if (url != null)
            {
                var responseUrl = string.Format("{0}{1}", url, searchQuery != "" ? "?" + searchQuery : null);
                if (requestUrl != responseUrl)
                {
                    filterContext.Result = new RedirectResult(responseUrl, true);
                    filterContext.Controller.TempData["wasRedirected"] = true;
                    return;
                }
            }
#if DEBUG
        }
#endif
        }
Esempio n. 21
0
        // Add to index
        public static void _createLuceneIndex(ClassifiedAdLucene data, IndexWriter writer, SeoManager ManagerSeo, Document doc)
        {
            doc = new Document();
            // add lucene fields mapped to db fields
            doc.Add(new Field("Id", data.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("StringId", data.StringId, Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("PosterId", data.PosterId, Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("PosterName", data.PosterName, Field.Store.YES, Field.Index.NOT_ANALYZED));
            // Default
            // Title
            doc.Add(new Field("Title", data.Title, Field.Store.YES, Field.Index.ANALYZED));
            // Descripton
            var hfd = HttpUtility.HtmlDecode(data.HtmlFreeDescription);

            doc.Add(new Field("HtmlFreeDescription", hfd, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("Description", data.Description, Field.Store.YES, Field.Index.ANALYZED));
            // Price
            var price = new NumericField("Price", Field.Store.YES, true);

            price.SetIntValue(data.Price);
            doc.Add(price);
            // Price Info
            doc.Add(new Field("PriceInfo", data.PriceInfo, Field.Store.YES, Field.Index.NOT_ANALYZED));
            // Status
            var stat = new NumericField("Status", Field.Store.YES, true);

            stat.SetIntValue(data.Status);
            doc.Add(stat);
            // Ad Type
            doc.Add(new Field("AdType", data.AdType, Field.Store.YES, Field.Index.NOT_ANALYZED));
            // Featured Status
            doc.Add(new Field("FeaturedAdStatus", data.AdPromotionFeaturedAdStatus.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            // Top Ad Status
            doc.Add(new Field("TopAdStatus", data.AdPromotionTopAdStatus.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            // Urgent Ad Status
            doc.Add(new Field("UrgentAdStatus", data.AdPromotionUrgentAdStatus.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            // Contact info
            doc.Add(new Field("ContactPrivacy", data.ContactPrivacy.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            if (!string.IsNullOrEmpty(data.AdContactName))
            {
                doc.Add(new Field("AdContactName", data.AdContactName, Field.Store.YES, Field.Index.NOT_ANALYZED));
            }
            if (!string.IsNullOrEmpty(data.AdContactPhone))
            {
                doc.Add(new Field("AdContactPhone", data.AdContactPhone, Field.Store.YES, Field.Index.NOT_ANALYZED));
            }
            if (!string.IsNullOrEmpty(data.AdContactPhone2))
            {
                doc.Add(new Field("AdContactPhone2", data.AdContactPhone2, Field.Store.YES, Field.Index.NOT_ANALYZED));
            }
            if (!string.IsNullOrEmpty(data.AdContactPhone3))
            {
                doc.Add(new Field("AdContactPhone3", data.AdContactPhone3, Field.Store.YES, Field.Index.NOT_ANALYZED));
            }
            if (!string.IsNullOrEmpty(data.AdContactEmail))
            {
                doc.Add(new Field("AdContactEmail", data.AdContactEmail, Field.Store.YES, Field.Index.NOT_ANALYZED));
            }
            // Category
            doc.Add(new Field("CategoryId", data.CategoryId.ToString(), Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("CategoryName", data.CategoryName, Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("CategorySeoName", data.CategorySeoName, Field.Store.YES, Field.Index.NO));
            // SubCategory
            doc.Add(new Field("SubCategoryId", data.SubCategoryId.ToString(), Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("SubCategoryName", data.SubCategoryName, Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("SubCategorySeoName", data.SubCategorySeoName, Field.Store.YES, Field.Index.NO));
            // Time Tick
            var tick = new NumericField("TimeStampTicks", Field.Store.YES, true);

            tick.SetLongValue(data.TimeStamp.Ticks);
            doc.Add(tick);
            tick = new NumericField("EditStampTicks", Field.Store.YES, false);
            tick.SetLongValue(data.EditTimeStamp.Ticks);
            doc.Add(tick);
            // Location
            var cid = new NumericField("CountryId", Field.Store.YES, true);

            cid.SetIntValue(data.CountryId);
            doc.Add(cid);
            var rid = new NumericField("RegionId", Field.Store.YES, true);

            rid.SetIntValue(data.RegionId);
            doc.Add(rid);
            doc.Add(new Field("CountryName", data.CountryName, Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("RegionName", data.RegionName, Field.Store.YES, Field.Index.NO));
            // Seo Title
            doc.Add(new Field("SeoTitle", new SeoManager().GetSeoTitle(data.Title), Field.Store.YES, Field.Index.NO));
            // Seo Category
            doc.Add(new Field("SeoCategory", data.SubCategorySeoName, Field.Store.YES, Field.Index.NO));
            // Seo Location
            doc.Add(new Field("SeoLocation", data.RegionSeoName, Field.Store.YES, Field.Index.NO));
            // Lists
            // AdInfo Search Store
            foreach (var ai in data.AdInfo)
            {
                if (!string.IsNullOrEmpty(ai.Description))
                {
                    if (ai.Name.Equals("Mileage"))
                    {
                        var mil = new NumericField("Mileage", Field.Store.YES, true);
                        mil.SetIntValue(int.Parse(ai.Description.Replace(",", "")));
                        doc.Add(mil);
                    }
                    else if (ai.Name.Equals("Year"))
                    {
                        var yr = new NumericField("Year", Field.Store.YES, true);
                        yr.SetIntValue(int.Parse(ai.Description.Replace(",", "")));
                        doc.Add(yr);
                    }
                    else if (ai.Name.Equals("Size"))
                    {
                        var size = new NumericField("Size", Field.Store.YES, true);
                        size.SetIntValue(int.Parse(ai.Description.Replace(",", "")));
                        doc.Add(size);
                    }
                    else if (ai.Name.Equals("Body Type"))
                    {
                        doc.Add(new Field(ai.Name, ManagerSeo.GetSeoTitle(ai.Description.Replace("(2 door)", "")), Field.Store.YES, Field.Index.NOT_ANALYZED));
                    }
                    else if (ai.Name.Equals("Rental Type"))
                    {
                        doc.Add(new Field(ai.Name, ManagerSeo.GetSeoTitle(ai.Description), Field.Store.YES, Field.Index.NOT_ANALYZED));
                    }
                    else
                    {
                        doc.Add(new Field(ai.Name, ai.Description, Field.Store.YES, Field.Index.NOT_ANALYZED));
                    }
                }
            }
            var serializer = new JavaScriptSerializer();

            serializer.MaxJsonLength = Int32.MaxValue;
            // AdInfo For Ad Details
            if (data.AdInfo != null && data.AdInfo.Count > 0)
            {
                // Get adinfo excluding nulls
                var adlist = from list in data.AdInfo
                             where list.Description != null
                             select new { list.Name, list.Description };
                var adinfos = serializer.Serialize(adlist);
                doc.Add(new Field("AdInfo", adinfos, Field.Store.YES, Field.Index.NO));
            }
            // Photo For Ad Details
            // For first image store all
            // Store adlist_filename and raw_filename for rest
            if (data.Photos != null && data.Photos.Count > 0)
            {
                // For ad list thumbnail
                // convert thubmnail to byte array
                var dir        = HostingEnvironment.MapPath("~/Photos/" + data.StringId.Substring(2, 4) + "/" + data.StringId.Substring(0, 4));
                var lucenepath = Path.Combine(dir, "lucene");
                System.IO.Directory.CreateDirectory(lucenepath);
                var adphotosJson = serializer.Serialize(data.Photos);
                // All other photos
                doc.Add(new Field("AdPhotos", adphotosJson, Field.Store.YES, Field.Index.NO));
                // Add Byte Array
                // Add photos
                Document images;
                foreach (var ap in data.Photos)
                {
                    if (ap.AdList_FileName != null)
                    {
                        images = new Document();
                        //var adlist = PhotoEditing.FileToByteArray(Path.Combine(dir, ap.AdList_FileName));
                        images.Add(new Field("AdPhotoLocatorId", string.Format("{0}-{1}", data.Id, ap.AdList_FileName), Field.Store.YES, Field.Index.NOT_ANALYZED));
                        //images.Add(new Field("AdPhoto", adlist, 0, adlist.Length, Field.Store.YES));
                        images.Add(new Field("FilePath", Path.Combine(lucenepath, ap.AdList_FileName), Field.Store.YES, Field.Index.NO));
                        images.Add(new Field("ContentType", ap.ContentType, Field.Store.YES, Field.Index.NO));
                        if (File.Exists(Path.Combine(lucenepath, ap.AdList_FileName)) == false)
                        {
                            try
                            {
                                File.Copy(Path.Combine(dir, ap.AdList_FileName), Path.Combine(lucenepath, ap.AdList_FileName), false);
                            }
                            catch (Exception ex) { }
                        }
                        writer.AddDocument(images);
                    }
                    images = new Document();
                    //var addetails = PhotoEditing.FileToByteArray(Path.Combine(dir, ap.AdDetails_FileName));
                    images.Add(new Field("AdPhotoLocatorId", string.Format("{0}-{1}", data.Id, ap.AdDetails_FileName), Field.Store.YES, Field.Index.NOT_ANALYZED));
                    //images.Add(new Field("AdPhoto", addetails, 0, addetails.Length, Field.Store.YES));
                    images.Add(new Field("FilePath", Path.Combine(lucenepath, ap.AdDetails_FileName), Field.Store.YES, Field.Index.NO));
                    images.Add(new Field("ContentType", ap.ContentType, Field.Store.YES, Field.Index.NO));
                    if (File.Exists(Path.Combine(lucenepath, ap.AdDetails_FileName)) == false)
                    {
                        try
                        {
                            File.Copy(string.Format("{0}/{1}", dir, ap.AdDetails_FileName), Path.Combine(lucenepath, ap.AdDetails_FileName), false);
                        }
                        catch (Exception ex) { }
                    }
                    writer.AddDocument(images);
                    images = new Document();
                    //var adraw = PhotoEditing.FileToByteArray(Path.Combine(dir, ap.Raw_FileName));
                    images.Add(new Field("AdPhotoLocatorId", string.Format("{0}-{1}", data.Id, ap.Raw_FileName), Field.Store.YES, Field.Index.NOT_ANALYZED));
                    //images.Add(new Field("AdPhoto", adraw, 0, adraw.Length, Field.Store.YES));
                    images.Add(new Field("FilePath", Path.Combine(lucenepath, ap.Raw_FileName), Field.Store.YES, Field.Index.NO));
                    images.Add(new Field("ContentType", ap.ContentType, Field.Store.YES, Field.Index.NO));
                    if (File.Exists(Path.Combine(lucenepath, ap.Raw_FileName)) == false)
                    {
                        try
                        {
                            File.Copy(Path.Combine(dir, ap.Raw_FileName), Path.Combine(lucenepath, ap.Raw_FileName), false);
                        }
                        catch (Exception ex) { }
                    }
                    writer.AddDocument(images);
                }
            }
            else
            {
                doc.Add(new Field("AdPhotos", "_NULL_", Field.Store.YES, Field.Index.NOT_ANALYZED));
            }
            // add entry to index
            writer.AddDocument(doc);
        }