Exemplo n.º 1
0
        public override void ContentChangedHandler(
            object sender,
            ContentChangedEventArgs e)
        {
            if (WebConfigSettings.DisableSearchIndex)
            {
                return;
            }
            if (sender == null)
            {
                return;
            }
            if (!(sender is CanhCam.Business.Product))
            {
                return;
            }

            CanhCam.Business.Product product      = (CanhCam.Business.Product)sender;
            SiteSettings             siteSettings = CacheHelper.GetCurrentSiteSettings();

            product.SiteId          = siteSettings.SiteId;
            product.SearchIndexPath = CanhCam.SearchIndex.IndexHelper.GetSearchIndexPath(siteSettings.SiteId);

            if (e.IsDeleted)
            {
                CanhCam.SearchIndex.IndexHelper.RemoveIndexItem(
                    product.ZoneId,
                    product.ProductGuid);
            }
            else
            {
                if (ThreadPool.QueueUserWorkItem(new WaitCallback(IndexItem), product))
                {
                    if (debugLog)
                    {
                        log.Debug("ProductIndexBuilderProvider.IndexItem queued");
                    }
                }
                else
                {
                    log.Error("Failed to queue a thread for ProductIndexBuilderProvider.IndexItem");
                }

                //IndexItem(news);
            }
        }
Exemplo n.º 2
0
        private static void IndexItem(object o)
        {
            if (WebConfigSettings.DisableSearchIndex)
            {
                return;
            }
            if (o == null)
            {
                return;
            }
            if (!(o is CanhCam.Business.Product))
            {
                return;
            }

            CanhCam.Business.Product content = o as CanhCam.Business.Product;
            IndexItem(content);
        }
Exemplo n.º 3
0
        private static void IndexItem(CanhCam.Business.Product product)
        {
            if (WebConfigSettings.DisableSearchIndex)
            {
                return;
            }

            if (product == null)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("product object passed to ProductIndexBuilderProvider.IndexItem was null");
                }
                return;
            }

            Guid             featureGuid = CanhCam.Business.Product.FeatureGuid;
            ModuleDefinition newsFeature = new ModuleDefinition(featureGuid);

            List <ContentAttribute> listAttribute = new List <ContentAttribute>();
            // Language
            List <Language> listLanguages  = LanguageHelper.GetPublishedLanguages();
            string          defaultCulture = WebConfigSettings.DefaultLanguageCultureForContent;
            // End Language

            ZoneSettings zoneSettings = new ZoneSettings(product.SiteId, product.ZoneId);

            //don't index pending/unpublished pages
            if (!zoneSettings.IsPublished)
            {
                return;
            }

            foreach (Language lang in listLanguages)
            {
                CanhCam.SearchIndex.IndexItem indexItem = new CanhCam.SearchIndex.IndexItem();
                if (product.SearchIndexPath.Length > 0)
                {
                    indexItem.IndexPath = product.SearchIndexPath;
                }
                indexItem.SiteId        = product.SiteId;
                indexItem.ZoneId        = zoneSettings.ZoneId;
                indexItem.ZoneName      = zoneSettings.Name;
                indexItem.ViewRoles     = zoneSettings.ViewRoles;
                indexItem.ZoneViewRoles = zoneSettings.ViewRoles;

                indexItem.PageMetaDescription = product.MetaDescription;
                indexItem.PageMetaKeywords    = product.MetaKeywords;
                indexItem.ItemGuid            = product.ProductGuid;
                indexItem.Title               = product.Title;
                indexItem.Content             = product.FullContent;
                indexItem.ContentAbstract     = product.BriefContent;
                indexItem.FeatureId           = featureGuid.ToString();
                indexItem.FeatureName         = newsFeature.FeatureName;
                indexItem.FeatureResourceFile = newsFeature.ResourceFile;

                //indexItem.OtherContent = stringBuilder.ToString();
                indexItem.IsPublished      = product.IsPublished;
                indexItem.PublishBeginDate = product.StartDate;
                indexItem.PublishEndDate   = product.EndDate;

                indexItem.CreatedUtc = product.StartDate;
                indexItem.LastModUtc = product.LastModUtc;

                if (product.Url.Length > 0)
                {
                    if (product.Url.StartsWith("http"))
                    {
                        indexItem.ViewPage = product.Url;
                    }
                    else
                    {
                        indexItem.ViewPage = product.Url.Replace("~/", string.Empty);
                    }
                }
                else
                {
                    indexItem.ViewPage = "Product/ProductDetail.aspx?zoneid="
                                         + indexItem.ZoneId.ToInvariantString()
                                         + "&ProductID=" + product.ProductId.ToInvariantString()
                    ;
                }

                indexItem.UseQueryStringParams = false;

                if (product.SubTitle.Length > 0)
                {
                    indexItem.Content += " " + product.SubTitle;
                }

                // Language
                string listGuid = zoneSettings.ZoneGuid.ToString()
                                  + ";" + product.ProductGuid.ToString();
                List <ContentLanguage> listContent = ContentLanguage.GetByListContent(listGuid);
                indexItem.LanguageCode = defaultCulture;
                if (lang.LanguageCode.ToLower() != defaultCulture.ToLower())
                {
                    indexItem.LanguageCode = lang.LanguageCode;
                    indexItem.RemoveOnly   = true;

                    foreach (ContentLanguage ct in listContent)
                    {
                        if (ct.ContentGuid == zoneSettings.PageGuid)
                        {
                            indexItem.ZoneName = ct.Title;
                        }
                        if (ct.ContentGuid == product.ProductGuid)
                        {
                            indexItem.PageMetaDescription = ct.MetaDescription;
                            indexItem.PageMetaKeywords    = ct.MetaKeywords;
                            indexItem.Title           = ct.Title;
                            indexItem.Content         = SecurityHelper.RemoveMarkup(ct.FullContent);
                            indexItem.ContentAbstract = SecurityHelper.RemoveMarkup(ct.BriefContent);

                            if (ct.ExtraText1.Length > 0)
                            {
                                indexItem.Content += " " + ct.ExtraText1;
                            }

                            indexItem.ViewPage   = ct.Url.Replace("~/", string.Empty);
                            indexItem.RemoveOnly = false;
                        }
                    }

                    listAttribute = ContentAttribute.GetByContentAsc(product.ProductGuid, lang.LanguageID);
                }
                else
                {
                    listAttribute = ContentAttribute.GetByContentAsc(product.ProductGuid);
                }
                // End Language

                if (product.Code.Length > 0)
                {
                    indexItem.Content += " " + product.Code;
                }

                foreach (ContentAttribute attribute in listAttribute)
                {
                    indexItem.Content += " " + attribute.Title + " " + SecurityHelper.RemoveMarkup(attribute.ContentText);
                }

                if (product.IsDeleted)
                {
                    indexItem.RemoveOnly = true;
                }

                CanhCam.SearchIndex.IndexHelper.RebuildIndex(indexItem);
            }

            if (debugLog)
            {
                log.Debug("Indexed " + product.Title);
            }
        }