public IList <SearchIndexDocument> GetContentToIndex()
        {
            var searchDocuments    = new List <SearchIndexDocument>();
            var searchConfig       = Telligent.Common.Services.Get <SearchConfiguration>();
            var maxFileSizeInBytes = searchConfig.MaxAttachmentFileSizeMB * 1024 * 1024;
            var credentialsManager = ServiceLocator.Get <ICredentialsManager>();
            var items = listItemService.ListItemsToReindex(LibraryApplicationType.Id, 500);

            foreach (var item in items)
            {
                try
                {
                    var document = new Document(item);
                    if (document.IsFolder)
                    {
                        continue;
                    }

                    var extMatch = XExt.Match(document.Name);
                    var ext      = extMatch.Success ? extMatch.Groups[0].Value.TrimStart('.') : string.Empty;

                    var doc = TEApi.SearchIndexing.NewDocument(
                        document.ContentId,
                        Id,
                        "Document",
                        PublicApi.SharePointUrls.Document(document.ContentId),
                        document.DisplayName,
                        PublicApi.Documents.Events.OnRender(document, "Description", document.Name, "unknown"));


                    doc.AddField(TEApi.SearchIndexing.Constants.RelatedId, document.ContentId.ToString());
                    doc.AddField(TEApi.SearchIndexing.Constants.IsContent, true.ToString());
                    doc.AddField(TEApi.SearchIndexing.Constants.ContentID, document.ContentId.ToString());
                    doc.AddField(TEApi.SearchIndexing.Constants.ApplicationId, document.Library.Id.ToString());
                    doc.AddField(TEApi.SearchIndexing.Constants.GroupID, document.Library.GroupId.ToString(CultureInfo.InvariantCulture));
                    doc.AddField(TEApi.SearchIndexing.Constants.ContainerId, document.Library.Container.ContainerId.ToString());

                    doc.AddField("sp_fileextension", ext.ToLowerInvariant());
                    doc.AddField(TEApi.SearchIndexing.Constants.CollapseField, string.Format("document:{0}", document.ContentId));
                    doc.AddField(TEApi.SearchIndexing.Constants.Date, TEApi.SearchIndexing.FormatDate(document.CreatedDate));
                    doc.AddField(TEApi.SearchIndexing.Constants.Category, "Documents");

                    var user = TEApi.Users.Get(new UsersGetOptions {
                        Email = document.Author.Email
                    });
                    if (user != null && !user.HasErrors())
                    {
                        doc.AddField(TEApi.SearchIndexing.Constants.UserDisplayName, user.DisplayName);
                        doc.AddField(TEApi.SearchIndexing.Constants.Username, user.Username);
                        doc.AddField(TEApi.SearchIndexing.Constants.CreatedBy, user.DisplayName);
                    }

                    var tags = TEApi.Tags.Get(document.ContentId, Id, null);
                    if (tags != null)
                    {
                        foreach (var tag in tags)
                        {
                            doc.AddField(TEApi.SearchIndexing.Constants.TagKeyword, tag.TagName.ToLower());
                            doc.AddField(TEApi.SearchIndexing.Constants.Tag, tag.TagName);
                        }
                    }

                    doc.AddField(TEApi.SearchIndexing.Constants.AttachmentName, document.Name);
                    doc.AddField(TEApi.SearchIndexing.Constants.AttachmentText, RemoteAttachment.GetText(document.Library.SPWebUrl, document.Name, document.Path, credentialsManager, maxFileSizeInBytes));

                    foreach (var field in item.EditableFields())
                    {
                        var key   = string.Format("sp_{0}", field.InternalName.ToLowerInvariant());
                        var value = item.ValueAsText(field.InternalName);
                        if (value != null)
                        {
                            doc.AddField(key, value.ToLowerInvariant());
                        }
                    }

                    searchDocuments.Add(doc);
                }
                catch { }
            }

            return(searchDocuments);
        }
        public IList <SearchIndexDocument> GetContentToIndex()
        {
            var searchDocuments    = new List <SearchIndexDocument>();
            var searchConfig       = Telligent.Common.Services.Get <SearchConfiguration>();
            var maxFileSizeInBytes = searchConfig.MaxAttachmentFileSizeMB * 1024 * 1024;
            var credentialsManager = ServiceLocator.Get <ICredentialsManager>();
            var items = listItemService.ListItemsToReindex(ListApplicationType.Id, 500);

            foreach (var item in items)
            {
                var doc = TEApi.SearchIndexing.NewDocument(
                    item.ContentId,
                    Id,
                    "ListItem",
                    PublicApi.SharePointUrls.ListItem(item.ContentId),
                    item.DisplayName,
                    PublicApi.ListItems.Events.OnRender(item, "Description", item.DisplayName, "unknown"));

                var list = PublicApi.Lists.Get(item.ListId);

                doc.AddField(TEApi.SearchIndexing.Constants.RelatedId, item.ContentId.ToString());
                doc.AddField(TEApi.SearchIndexing.Constants.IsContent, true.ToString());
                doc.AddField(TEApi.SearchIndexing.Constants.ContentID, item.ContentId.ToString());
                doc.AddField(TEApi.SearchIndexing.Constants.ApplicationId, list.Id.ToString());
                doc.AddField(TEApi.SearchIndexing.Constants.GroupID, list.GroupId.ToString(CultureInfo.InvariantCulture));
                doc.AddField(TEApi.SearchIndexing.Constants.ContainerId, list.Container.ContainerId.ToString());

                doc.AddField(TEApi.SearchIndexing.Constants.CollapseField, string.Format("listitem:{0}", item.ContentId));
                doc.AddField(TEApi.SearchIndexing.Constants.Date, TEApi.SearchIndexing.FormatDate(item.CreatedDate));
                doc.AddField(TEApi.SearchIndexing.Constants.Category, "ListItems");

                var user = TEApi.Users.Get(new UsersGetOptions {
                    Email = item.Author.Email
                });
                if (user != null && !user.HasErrors())
                {
                    doc.AddField(TEApi.SearchIndexing.Constants.UserDisplayName, user.DisplayName);
                    doc.AddField(TEApi.SearchIndexing.Constants.Username, user.Username);
                    doc.AddField(TEApi.SearchIndexing.Constants.CreatedBy, user.DisplayName);
                }

                var tags = TEApi.Tags.Get(item.ContentId, Id, null);
                if (tags != null)
                {
                    foreach (var tag in tags)
                    {
                        doc.AddField(TEApi.SearchIndexing.Constants.TagKeyword, tag.TagName.ToLower());
                        doc.AddField(TEApi.SearchIndexing.Constants.Tag, tag.TagName);
                    }
                }

                foreach (var field in item.EditableFields())
                {
                    if (field.FieldTypeKind == Microsoft.SharePoint.Client.FieldType.Attachments)
                    {
                        var webUrl     = list.SPWebUrl.ToLowerInvariant();
                        var atachments = PublicApi.Attachments.List(item.ListId, new AttachmentsGetOptions(item.ContentId, field.InternalName));
                        foreach (var attachment in atachments)
                        {
                            string attachmentUrl = attachment.Uri.ToString().ToLowerInvariant();
                            if (attachmentUrl.StartsWith(webUrl))
                            {
                                string path = attachmentUrl.Replace(webUrl, string.Empty);
                                doc.AddField(string.Format("sp_{0}_{1}_name", field.InternalName.ToLowerInvariant(), attachment.Name.ToLowerInvariant()), attachment.Name);
                                doc.AddField(string.Format("sp_{0}_{1}_text", field.InternalName.ToLowerInvariant(), attachment.Name.ToLowerInvariant()), RemoteAttachment.GetText(webUrl, attachment.Name, path, credentialsManager, maxFileSizeInBytes));
                            }
                        }
                    }
                    else
                    {
                        var key   = string.Format("sp_{0}", field.InternalName.ToLowerInvariant());
                        var value = item.ValueAsText(field.InternalName);
                        if (value != null)
                        {
                            doc.AddField(key, value.ToLowerInvariant());
                        }
                    }
                }

                searchDocuments.Add(doc);
            }

            return(searchDocuments);
        }