Пример #1
0
        public virtual void RemoveContentLanguageBranch(IContent content)
        {
            var deletedList = new List <string>();

            deletedList.Add(SearchDocument.FormatDocumentId(content));
            _documentRepository.DeleteFromIndex(deletedList);
        }
Пример #2
0
 public virtual void RemoveContentIndex(IContent content, bool includeChild = false)
 {
     if (!ContentReference.IsNullOrEmpty(content?.ContentLink))
     {
         SlimContentReader slimContentReader = new SlimContentReader(this._contentRepository, content.ContentLink, (c =>
         {
             return(includeChild);
         }));
         var deletedList = new List <string>();
         while (slimContentReader.Next())
         {
             if (!ContentReference.IsNullOrEmpty(slimContentReader.Current?.ContentLink))
             {
                 if (!slimContentReader.Current.ContentLink.CompareToIgnoreWorkID(ContentReference.RootPage))
                 {
                     var allLanguageBranch = _contentRepository.GetLanguageBranches <IContent>(slimContentReader.Current.ContentLink);
                     foreach (var lang in allLanguageBranch)
                     {
                         deletedList.Add(SearchDocument.FormatDocumentId(lang));
                     }
                 }
             }
             _documentRepository.DeleteFromIndex(deletedList);
         }
     }
 }
Пример #3
0
        public virtual void IncludeDefaultField(Document document, IContent content)
        {
            var versionable      = (content as IVersionable);
            var changeTrackable  = content as IChangeTrackable;
            var contentStatus    = ((int)versionable.Status).ToString();
            var virtualPath      = ContentIndexHelpers.GetContentVirtualpath(content);
            var acl              = ContentIndexHelpers.GetContentACL(content);
            var contentType      = ContentIndexHelpers.GetContentType(content);
            var language         = (content as ILocalizable).Language.Name;
            var startPublishDate = versionable.StartPublish.HasValue ? DateTools.DateToString(versionable.StartPublish.Value.ToUniversalTime(), DateTools.Resolution.SECOND) : string.Empty;
            var stopPublishDate  = versionable.StopPublish.HasValue ? DateTools.DateToString(versionable.StopPublish.Value.ToUniversalTime(), DateTools.Resolution.SECOND) : string.Empty;
            var expired          = "";

            if ((versionable.StopPublish.HasValue && versionable.StopPublish.Value.ToUniversalTime() < DateTime.UtcNow) ||
                (versionable.StartPublish.HasValue && versionable.StartPublish.Value.ToUniversalTime() > DateTime.UtcNow))
            {
                expired = "true";
            }
            var createdDate = DateTools.DateToString(changeTrackable.Created.ToUniversalTime(), DateTools.Resolution.SECOND);
            var updatedDate = DateTools.DateToString(changeTrackable.Changed.ToUniversalTime(), DateTools.Resolution.SECOND);
            var idField     = new Field(ContentIndexHelpers.GetIndexFieldName(Constants.INDEX_FIELD_NAME_ID),
                                        SearchDocument.FormatDocumentId(content), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES);
            var nameField = new Field(ContentIndexHelpers.GetIndexFieldName(Constants.INDEX_FIELD_NAME_NAME),
                                      content.Name, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES);
            var statusField = new Field(ContentIndexHelpers.GetIndexFieldName(Constants.INDEX_FIELD_NAME_STATUS),
                                        contentStatus, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES);
            var virtualPathField = new Field(ContentIndexHelpers.GetIndexFieldName(Constants.INDEX_FIELD_NAME_VIRTUAL_PATH),
                                             virtualPath, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES);
            var aclField = new Field(ContentIndexHelpers.GetIndexFieldName(Constants.INDEX_FIELD_NAME_ACL),
                                     acl, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES);
            var typeField = new Field(ContentIndexHelpers.GetIndexFieldName(Constants.INDEX_FIELD_NAME_TYPE),
                                      contentType, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES);
            var langField = new Field(ContentIndexHelpers.GetIndexFieldName(Constants.INDEX_FIELD_NAME_LANGUAGE),
                                      language, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES);
            var startPublishField = new Field(ContentIndexHelpers.GetIndexFieldName(Constants.INDEX_FIELD_NAME_START_PUBLISHDATE),
                                              startPublishDate, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES);
            var stopPublishField = new Field(ContentIndexHelpers.GetIndexFieldName(Constants.INDEX_FIELD_NAME_STOP_PUBLISHDATE),
                                             stopPublishDate, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES);
            var referenceField = new Field(ContentIndexHelpers.GetIndexFieldName(Constants.INDEX_FIELD_NAME_REFERENCE),
                                           content.ContentLink.ID.ToString(), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES);
            var createdField = new Field(ContentIndexHelpers.GetIndexFieldName(Constants.INDEX_FIELD_NAME_CREATED),
                                         createdDate, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES);
            var updatedField = new Field(ContentIndexHelpers.GetIndexFieldName(Constants.INDEX_FIELD_NAME_CHANGED),
                                         updatedDate, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES);
            var expiredField = new Field(ContentIndexHelpers.GetIndexFieldName(Constants.INDEX_FIELD_NAME_EXPIRED),
                                         expired, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES);

            document.Add(idField);
            document.Add(nameField);
            document.Add(statusField);
            document.Add(virtualPathField);
            document.Add(aclField);
            document.Add(typeField);
            document.Add(langField);
            document.Add(startPublishField);
            document.Add(stopPublishField);
            document.Add(referenceField);
            document.Add(createdField);
            document.Add(updatedField);
            document.Add(expiredField);
        }
Пример #4
0
        public virtual SearchDocument GetDocFromContent(IContent content)
        {
            try
            {
                var document = new Document();
                IncludeDefaultField(document, content);
                var possibleIndexModels = LuceneConfiguration.IncludedTypes.Where(x => x.Value.ContentType.IsAssignableFrom(content.GetOriginalType())).Select(x => x.Value).ToList();
                foreach (var documentIndexModel in possibleIndexModels)
                {
                    IncludeContentField(document, content, documentIndexModel);
                    var computedFieldList = documentIndexModel.IndexedFields;
                    foreach (var field in computedFieldList)
                    {
                        var fieldInstance = field.Value;
                        var value         = fieldInstance.GetValue(content, field.Key);
                        if (value != null)
                        {
                            AbstractField luceneField;
                            var           indexFieldName   = ContentIndexHelpers.GetIndexFieldName(field.Key);
                            var           existedFieldName = document.GetField(indexFieldName);
                            if (existedFieldName != null)
                            {
                                document.RemoveField(indexFieldName);
                            }
                            if (fieldInstance.DataType == LuceneFieldType.Multilist)
                            {
                                var listValue = (List <string>)value;
                                foreach (var item in listValue)
                                {
                                    document.Add(new Field(indexFieldName, item, fieldInstance.Store, fieldInstance.Index, fieldInstance.Vector));
                                }
                                continue;
                            }
                            switch (fieldInstance.DataType)
                            {
                            case LuceneFieldType.Datetime:
                                DateTime d1 = Convert.ToDateTime(value);
                                luceneField = new Field(indexFieldName, DateTools.DateToString(d1.ToUniversalTime(), DateTools.Resolution.SECOND), fieldInstance.Store, fieldInstance.Index, fieldInstance.Vector);
                                break;

                            case LuceneFieldType.Numeric:
                                luceneField = new NumericField(indexFieldName, fieldInstance.Store, true).SetLongValue(string.IsNullOrEmpty(value + "") ? 0 : long.Parse(value + ""));
                                break;

                            default:
                                luceneField = new Field(indexFieldName, value.ToString(), fieldInstance.Store, fieldInstance.Index, fieldInstance.Vector);
                                break;
                            }
                            document.Add(luceneField);
                        }
                    }
                }
                var result = new SearchDocument()
                {
                    Id       = SearchDocument.FormatDocumentId(content),
                    Document = document
                };
                return(result);
            }
            catch (Exception ex)
            {
                _logger.Error("Fetch Document error", ex);
                return(null);
            }
        }