예제 #1
0
        public IndexObject GetIndexObject(object o)
        {
            IndexObject indexObject = null;

            Page page = (Page)o;
            NameValueCollection storeFields = new NameValueCollection();
            NameValueCollection sysFields = new NameValueCollection();

            sysFields.Add("SiteName", page.Site.FullName);
            sysFields.Add("PageName", page.FullName);

            string title = "";
            StringBuilder body = new StringBuilder();

            if (page.HtmlMeta != null && !string.IsNullOrEmpty(page.HtmlMeta.HtmlTitle))
            {
                title = page.HtmlMeta.HtmlTitle;
            }
            if (!string.IsNullOrEmpty(page.ContentTitle))
            {
                body.AppendFormat(title);

                title = page.ContentTitle;
            }

            if (page.PagePositions != null)
            {
                foreach (var item in page.PagePositions.Where(it => (it is HtmlBlockPosition) || (it is HtmlPosition)))
                {
                    if (item is HtmlBlockPosition)
                    {
                        HtmlBlockPosition htmlBlockPosition = (HtmlBlockPosition)item;
                        var htmlBlock = new HtmlBlock(page.Site, htmlBlockPosition.BlockName).LastVersion().AsActual();
                        if (htmlBlock != null)
                        {
                            body.Append(" " + Kooboo.StringExtensions.StripAllTags(htmlBlock.Body));
                        }
                    }
                    else
                    {
                        HtmlPosition htmlPosition = (HtmlPosition)item;
                        body.Append(" " + Kooboo.StringExtensions.StripAllTags(htmlPosition.Html));
                    }
                }
            }

            indexObject = new IndexObject()
            {
                Title = title,
                Body = body.ToString(),
                StoreFields = storeFields,
                SystemFields = sysFields,
                NativeType = typeof(Page).AssemblyQualifiedNameWithoutVersion()
            };

            return indexObject;
        }
예제 #2
0
        public virtual Models.IndexObject GetIndexObject(object o)
        {
            IndexObject indexObject = null;

            TextContent textContent = (TextContent)o;
            NameValueCollection storeFields = new NameValueCollection();
            NameValueCollection sysFields = new NameValueCollection();

            var repository = textContent.GetRepository();
            var schema = textContent.GetSchema().AsActual();
            var folder = textContent.FolderName;

            var folderSearchSetting = Providers.SearchSettingProvider.Get(new SearchSetting(repository, folder));
            if (folderSearchSetting != null)
            {
                string title = textContent.GetSummary();
                StringBuilder bodyBuilder = new StringBuilder();
                foreach (var key in textContent.Keys)
                {
                    var column = schema[key];

                    var includeField = IsIncluded(folderSearchSetting, key);
                    // If column == null, then it could be a system field.
                    var isSystemField = column == null || column.IsSystemField;
                    var index = !isSystemField && includeField;

                    var value = textContent[key];

                    string strValue = "";
                    string indexValue = "";
                    if (value != null)
                    {
                        if (value is DateTime)
                        {
                            var rawValue = (DateTime)value;
                            strValue = rawValue.Ticks.ToString();
                            indexValue = rawValue.ToString();
                        }
                        else
                        {
                            indexValue = strValue = value.ToString();
                        }
                    }
                    if (index && !column.Summarize)
                    {
                        bodyBuilder.AppendFormat(" {0} ", Kooboo.Extensions.StringExtensions.StripAllTags(indexValue.ToString()));
                    }

                    if (isSystemField)
                    {
                        sysFields[key] = strValue;
                    }
                    else
                    {
                        storeFields[key] = strValue;
                    }

                }

                indexObject = new IndexObject()
                {
                    Title = title,
                    Body = bodyBuilder.ToString(),
                    StoreFields = storeFields,
                    SystemFields = sysFields,
                    NativeType = typeof(TextContent).AssemblyQualifiedNameWithoutVersion()
                };
            }

            return indexObject;
        }
예제 #3
0
        public virtual IndexObject GetIndexObject(object o)
        {
            IndexObject indexObject = null;

            TextContent textContent = (TextContent)o;
            NameValueCollection storeFields = new NameValueCollection();
            NameValueCollection sysFields = new NameValueCollection();

            var repository = textContent.GetRepository();
            var schema = textContent.GetSchema().AsActual();
            var folder = textContent.FolderName;

            TextFolder tf = textContent.GetFolder().AsActual();

            var folderSearchSetting = SearchSettingProvider.Get(new SearchSetting(repository, folder));
            if (folderSearchSetting != null)
            {
                string title = textContent.GetSummary();
                StringBuilder bodyBuilder = new StringBuilder();
                foreach (var key in textContent.Keys)
                {
                    var column = schema[key];
                    // If column == null, then it could be a system field.
                    var isSystemField = column == null || column.IsSystemField;
                    var index = !isSystemField;

                    var value = textContent[key];

                    string strValue = "";
                    string indexValue = "";
                    if (value != null)
                    {
                        if (value is DateTime)
                        {
                            var rawValue = (DateTime)value;
                            strValue = rawValue.Ticks.ToString();
                            indexValue = rawValue.ToString();
                        }
                        else
                        {
                            indexValue = strValue = value.ToString();
                        }
                    }
                    if (index && !column.Summarize)
                    {
                        bodyBuilder.AppendFormat(" {0} ", Kooboo.StringExtensions.StripAllTags(indexValue.ToString()));
                    }

                    if (isSystemField)
                    {
                        sysFields[key] = strValue;
                    }
                    else
                    {
                        storeFields[key] = strValue;
                    }

                }

                // index folder categories under system field categoryUUIDs so we can query by category relations
                /*StringBuilder categories = new StringBuilder();
                foreach (CategoryFolder cf in tf.Categories)
                {
                    var cats = textContent.Categories(cf.FolderName).ToList();
                    foreach (TextContent cat in cats)
                    {
                        categories.Append(cat.UUID + ",");
                    }
                }

                sysFields["categories"] = categories.ToString();*/

                indexObject = new IndexObject()
                {
                    Title = title,
                    Body = bodyBuilder.ToString(),
                    StoreFields = storeFields,
                    SystemFields = sysFields,
                    NativeType = typeof(TextContent).AssemblyQualifiedNameWithoutVersion()
                };
            }

            return indexObject;
        }