예제 #1
0
        private void ConvertContentToIndexItem(IContent content, IndexRequestItem item)
        {
            var contentSecurable = content as IContentSecurable;
            var categorizable    = content as ICategorizable;

            LuceneContentSearchHandler.AddUriToIndexItem(content, item);
            this.AddMetaDataToIndexItem(content, item);
            this.AddSearchablePropertiesToIndexItem(content, item);
            LuceneContentSearchHandler.AddBinaryStorableToIndexItem(content, item);
            if (contentSecurable != null)
            {
                IContentSecurityDescriptor contentSecurityDescriptor = contentSecurable.GetContentSecurityDescriptor();
                if (contentSecurityDescriptor != null && contentSecurityDescriptor.Entries != null)
                {
                    LuceneContentSearchHandler.AddReadAccessToIndexItem(contentSecurityDescriptor.Entries, item);
                }
            }
            else
            {
                item.AccessControlList.Add(string.Format(System.Globalization.CultureInfo.InvariantCulture, "G:{0}", new object[]
                {
                    EveryoneRole.RoleName
                }));
            }
            if (categorizable != null)
            {
                LuceneContentSearchHandler.AddCategoriesToIndexItem(categorizable.Category, item);
            }
            this.AddVirtualPathToIndexItem(content.ContentLink, item);
            LuceneContentSearchHandler.AddItemStatusToIndexItem(item);
            LuceneContentSearchHandler.AddExpirationToIndexItem(content, item);
            item.NamedIndex = this.NamedIndex;
        }
예제 #2
0
        private void UpdateDescendantItemsOf(IContent contentItem)
        {
            foreach (var childContent in this.contentRepository.GetChildren <IContent>(contentItem.ContentLink))
            {
                var searchableItem = childContent as ISearchable;
                if (searchableItem == null)
                {
                    this.UpdateDescendantItemsOf(childContent);
                }
                else
                {
                    string searchId = LuceneContentSearchHandler.GetSearchId(childContent);
                    var    item     = new IndexRequestItem(searchId, searchableItem.IsSearchable && this.IsInSearchableBranch(childContent) ? IndexAction.Update : IndexAction.Remove);
                    if (item.IndexAction != IndexAction.Remove)
                    {
                        item.AutoUpdateVirtualPath = true;
                        this.ConvertContentToIndexItem(childContent, item);
                    }
                    this.searchHandler.UpdateIndex(item, this.NamedIndexingService);

                    if (searchableItem.AllowIndexChildren)
                    {
                        this.UpdateDescendantItemsOf(childContent);
                    }
                    else
                    {
                        this.RemoveDescendantItemsOf(childContent);
                    }
                }
            }
        }
예제 #3
0
        // Hieu Le - 2013
        public virtual void UpdateItem(IContent contentItem)
        {
            if (contentItem == null)
            {
                return;
            }

            if (!this.ServiceActive)
            {
                return;
            }

            var searchableItem = contentItem as ISearchable;

            if (searchableItem == null)
            {
                return;
            }

            string searchId = LuceneContentSearchHandler.GetSearchId(contentItem);

            var item = new IndexRequestItem(searchId, searchableItem.IsSearchable && this.IsInSearchableBranch(contentItem) ? IndexAction.Update : IndexAction.Remove);

            if (item.IndexAction != IndexAction.Remove)
            {
                item.AutoUpdateVirtualPath = true;
                this.ConvertContentToIndexItem(contentItem, item);
            }

            this.searchHandler.UpdateIndex(item, this.NamedIndexingService);

            this.UpdateDescendantItemsOf(contentItem);
        }
예제 #4
0
 private void RemoveDescendantItemsOf(IContent contentItem)
 {
     foreach (var childContent in this.contentRepository.GetChildren <IContent>(contentItem.ContentLink))
     {
         var item = new IndexRequestItem(LuceneContentSearchHandler.GetSearchId(childContent), IndexAction.Remove);
         this.searchHandler.UpdateIndex(item, this.NamedIndexingService);
         this.RemoveDescendantItemsOf(childContent);
     }
 }
예제 #5
0
 private void AddVirtualPathToIndexItem(ContentReference contentLink, IndexRequestItem item)
 {
     if (!ContentReference.IsNullOrEmpty(contentLink))
     {
         foreach (string current in LuceneContentSearchHandler.GetVirtualPathNodes(contentLink, this.contentRepository))
         {
             item.VirtualPathNodes.Add(current);
         }
     }
 }
예제 #6
0
        private static string GetSearchId(IContent content)
        {
            System.Globalization.CultureInfo language = null;
            var locale = content as ILocale;

            if (locale != null)
            {
                language = locale.Language;
            }
            return(LuceneContentSearchHandler.CreateSearchId(content.ContentGuid, language));
        }
예제 #7
0
        private void AddMetaDataToIndexItem(IContent content, IndexRequestItem item)
        {
            var locale          = content as ILocale;
            var changeTrackable = content as IChangeTrackable;

            item.Title    = content.Name;
            item.Created  = ((changeTrackable != null) ? changeTrackable.Created : System.DateTime.MinValue);
            item.Modified = ((changeTrackable != null) ? changeTrackable.Changed : System.DateTime.MinValue);
            item.Culture  = ((locale != null) ? LuceneContentSearchHandler.GetCultureIdentifier(locale.Language) : string.Empty);
            item.ItemType = this.GetItemType(content.GetOriginalType());
            item.Authors.Add((changeTrackable != null) ? changeTrackable.CreatedBy : string.Empty);
        }
예제 #8
0
        public virtual void RemoveLanguageBranch(IContent contentItem)
        {
            Validator.ThrowIfNull("contentItem", contentItem);
            if (!this.ServiceActive)
            {
                return;
            }
            string searchId         = LuceneContentSearchHandler.GetSearchId(contentItem);
            var    indexRequestItem = new IndexRequestItem(searchId, IndexAction.Remove);

            indexRequestItem.NamedIndex = this.NamedIndex;
            this.searchHandler.UpdateIndex(indexRequestItem, this.NamedIndexingService);
        }
예제 #9
0
        public virtual string GetItemType(Type contentType)
        {
            Validator.ThrowIfNull("contentType", contentType);
            var stringBuilder = new System.Text.StringBuilder(LuceneContentSearchHandler.GetItemTypeSection(contentType));

            if (contentType.IsClass)
            {
                while (contentType.BaseType != typeof(object))
                {
                    contentType = contentType.BaseType;
                    stringBuilder.Append(" ");
                    stringBuilder.Append(LuceneContentSearchHandler.GetItemTypeSection(contentType));
                }
            }
            stringBuilder.Append(" ");
            stringBuilder.Append(LuceneContentSearchHandler.BaseItemType);
            return(stringBuilder.ToString());
        }
예제 #10
0
        public virtual void MoveItem(ContentReference contentLink)
        {
            if (!this.ServiceActive)
            {
                return;
            }
            if (ContentReference.IsNullOrEmpty(contentLink))
            {
                return;
            }
            IContent content;

            if (!this.contentRepository.TryGet(contentLink, this.languageSelectorFactory.MasterLanguage(), out content))
            {
                return;
            }
            string searchId         = LuceneContentSearchHandler.GetSearchId(content);
            var    indexRequestItem = new IndexRequestItem(searchId, IndexAction.Update);

            indexRequestItem.AutoUpdateVirtualPath = true;
            this.ConvertContentToIndexItem(content, indexRequestItem);
            this.searchHandler.UpdateIndex(indexRequestItem, this.NamedIndexingService);
        }
예제 #11
0
 private static string CreateSearchId(System.Guid contentGuid, System.Globalization.CultureInfo language)
 {
     return(string.Format("{0}|{1}", contentGuid, LuceneContentSearchHandler.GetCultureIdentifier(language)));
 }
예제 #12
0
 public static string GetItemTypeSection <T>()
 {
     return(LuceneContentSearchHandler.GetItemTypeSection(typeof(T)));
 }