Пример #1
0
 public void IndexNode(int id, bool isPublished)
 {
     if (!CurrentConfiguration.ConfigurationExists)
     {
         this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Warn, "No Solis Search configuration found in web.config, skipping indexing.", (Exception)null);
     }
     else
     {
         ICmsContent contentById = this.cmsIndexer.GetContentById(id);
         string      indexRoot   = CurrentConfiguration.SearchSettings.IndexRoot;
         if (indexRoot != this.cmsIndexer.CmsRootId)
         {
             this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("IndexRoot is set to {0}, checking if node is descendant.", (object)indexRoot), (Exception)null);
             if (!((IEnumerable <string>)contentById.Path.Split(new string[1]
             {
                 ","
             }, StringSplitOptions.RemoveEmptyEntries)).Contains <string>(this.cmsIndexer.CmsEntityFactory.ActualId(contentById.Id)))
             {
                 this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("Node path {0} does not contain indexRoot {1}, node will not be indexed.", (object)contentById.Path, (object)indexRoot), (Exception)null);
                 return;
             }
         }
         this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, "Publishing document \"" + contentById.Name + "\", adding to Solr index.", (Exception)null);
         CmsSearchResultItem searchResultItem = this.GetCmsSearchResultItem(contentById);
         if (searchResultItem == null)
         {
             this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, "No indexitem to index", (Exception)null);
         }
         else
         {
             this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, "Saving indexitem to index", (Exception)null);
             this.IndexItem(searchResultItem, isPublished);
             if (!searchResultItem.Documents.Any <string>())
             {
                 return;
             }
             foreach (string str in searchResultItem.Documents.Distinct <string>())
             {
                 ICmsMedia cmsMedia = this.cmsIndexer.ResolveMedia(str);
                 if (cmsMedia != null)
                 {
                     this.IndexRichText(str, cmsMedia.Id.ToString((IFormatProvider)CultureInfo.InvariantCulture), searchResultItem.Acl, searchResultItem.Languages, searchResultItem.StartPublish, searchResultItem.EndPublish, searchResultItem.Id);
                 }
             }
         }
     }
 }
Пример #2
0
        public void IndexItem(CmsSearchResultItem content, bool isPublished)
        {
            if (InstanceHelper.IsInstance(content))
            {
                ISolrOperations <CmsSearchResultItem> instance = ServiceLocator.Current.GetInstance <ISolrOperations <CmsSearchResultItem> >();
                instance.Add(content);
                instance.Commit();
            }

            if (isPublished)
            {
                var contentPublished = Mapper.Map <CmsSearchResultItemPublished>(content);

                if (InstanceHelper.IsInstance(contentPublished))
                {
                    ISolrOperations <CmsSearchResultItemPublished> instancePublished = ServiceLocator.Current.GetInstance <ISolrOperations <CmsSearchResultItemPublished> >();
                    instancePublished.Add(contentPublished);
                    instancePublished.Commit();
                }
            }
        }
Пример #3
0
 public void RebuildIndex()
 {
     if (!CurrentConfiguration.ConfigurationExists)
     {
         this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Warn, "No Solis Search configuration found in web.config, skipping indexing.", (Exception)null);
     }
     else
     {
         IList <ICmsContent> indexingRoot = this.cmsIndexer.GetIndexingRoot((object)CurrentConfiguration.SearchSettings.IndexRoot);
         if (indexingRoot.Any <ICmsContent>())
         {
             List <CmsSearchResultItem> items = new List <CmsSearchResultItem>();
             foreach (ICmsContent node in (IEnumerable <ICmsContent>)indexingRoot)
             {
                 this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Info, string.Format("Rebuilding index from node {0}, id {1}.", (object)node.Name, (object)node.Id), (Exception)null);
                 if (node.Id != this.cmsIndexer.CmsRootId)
                 {
                     CmsSearchResultItem searchResultItem = this.GetCmsSearchResultItem(node);
                     if (searchResultItem != null)
                     {
                         items.Add(searchResultItem);
                     }
                 }
                 List <CmsSearchResultItem> list = this.cmsIndexer.GetDescendants(node).Select <ICmsContent, CmsSearchResultItem>(new Func <ICmsContent, CmsSearchResultItem>(this.GetCmsSearchResultItem)).ToList <CmsSearchResultItem>();
                 if (list.Any <CmsSearchResultItem>())
                 {
                     items.AddRange(list.Where <CmsSearchResultItem>((Func <CmsSearchResultItem, bool>)(i => i != null)));
                 }
             }
             this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Info, string.Format("Found total of {0} nodes to index", (object)items.Count), (Exception)null);
             this.ClearIndex();
             this.IndexItems(items);
             this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, "Done, index rebuilt", (Exception)null);
         }
         else
         {
             this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Error, "No nodes to index found, is there no content or configuration error?", (Exception)null);
         }
     }
 }
Пример #4
0
        private CmsSearchResultItem GetCmsSearchResultItem(ICmsContent node)
        {
            if (node.Id == null)
            {
                this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, "Node id is null, not recognized object for indexing. Skipping.", (Exception)null);
                return((CmsSearchResultItem)null);
            }
            object propertyValue1 = this.cmsIndexer.GetPropertyValue(node, "solisSearchNoIndex");

            if (propertyValue1 != null)
            {
                try
                {
                    if (Convert.ToBoolean(propertyValue1))
                    {
                        this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, "solisSearchNoIndex is true, removing it from index if exist and skips node.", (Exception)null);
                        this.DeleteFromIndex((object)node.Id);
                        return((CmsSearchResultItem)null);
                    }
                }
                catch (Exception ex)
                {
                    this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Error, "Error checking if node should be indexed.", ex);
                }
            }
            DocType docType = CurrentConfiguration.DocTypes[node.ContentType];

            if (docType != null && docType.Exclude)
            {
                this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("DocType {0} is configured to be excluded from index, skipping", (object)node.ContentType), (Exception)null);
                return((CmsSearchResultItem)null);
            }
            if (docType == null)
            {
                this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Warn, string.Format("Cannot find any configuration for DocType {0}, loading default configuration", (object)node.ContentType), (Exception)null);
                docType = CurrentConfiguration.DocTypes["default"];
            }
            if (docType == null)
            {
                this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Warn, string.Format("Cannot find any configuration for DocType {0}, not even default backup configuration, cannot index content.", (object)node.ContentType), (Exception)null);
                return((CmsSearchResultItem)null);
            }
            CmsSearchResultItem searchResultItem = new CmsSearchResultItem()
            {
                Id           = node.Id,
                Name         = node.Name,
                LinkUrl      = this.cmsIndexer.GetContentUrl(node),
                Created      = node.CreateDate,
                StartPublish = node.StartPublish,
                LastModified = node.UpdateDate,
                EndPublish   = node.EndPublish,
                Breadcrumbs  = this.cmsIndexer.GetBreadcrumbs(node),
                Acl          = this.cmsIndexer.GetNodeAcl(node),
                Languages    = this.cmsIndexer.GetNodeLanguages(node),
                DocTypes     = this.cmsIndexer.GetContentTypes(node)
            };

            try
            {
                object propertyValue2 = this.cmsIndexer.GetPropertyValue(node, "solisSearchCustomUrl");
                if (propertyValue2 != null)
                {
                    if (!string.IsNullOrWhiteSpace(propertyValue2 as string))
                    {
                        this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("Found custom value for node url, inserting to index {0}", propertyValue2), (Exception)null);
                        searchResultItem.LinkUrl = propertyValue2.ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Error, "Error reading custom url", ex);
            }
            if (docType.AddPageNameToContent)
            {
                searchResultItem.Content.Add(node.Name);
            }
            foreach (Property property1 in docType.DocTypeProperties.Cast <Property>())
            {
                string       propertyName = property1.PropertyName;
                ICmsProperty property2    = this.cmsIndexer.GetProperty(node, propertyName);
                if (property2 == null)
                {
                    this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("Property {0} not found on document, skipping", (object)propertyName), (Exception)null);
                }
                else
                {
                    IPropertyParser parser;
                    if (!string.IsNullOrEmpty(property1.Parser))
                    {
                        Type type = Type.GetType(property1.Parser);
                        if (type == (Type)null)
                        {
                            this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Error, string.Format("Parser was configured as {0}, but parser type is not recognized, will use default parser.", (object)property1.Parser), (Exception)null);
                            parser = (IPropertyParser) new DefaultParser();
                        }
                        else
                        {
                            parser = Activator.CreateInstance(type) as IPropertyParser;
                        }
                    }
                    else
                    {
                        parser = (IPropertyParser) new DefaultParser();
                    }
                    parser.CurrentCmsNode       = node;
                    parser.CurrentCmsProperty   = property2;
                    parser.CurrentSolisProperty = property1;
                    string str1 = property2 != null?parser.GetPropertyValue(property2.Value) : string.Empty;

                    if (property1.Recursive && string.IsNullOrEmpty(str1))
                    {
                        str1 = this.GetRecursiveValue(node, propertyName, parser);
                    }
                    bool   forceMultiValued      = property1.ForceMultiValued;
                    string dynamicFieldExtension = FieldNameHelper.GetDynamicFieldExtension(property1);
                    if (!string.IsNullOrEmpty(str1))
                    {
                        if (property2 != null)
                        {
                            if (searchResultItem.Documents == null)
                            {
                                searchResultItem.Documents = this.ExtractDocumentLinks(str1, property2.Name);
                            }
                            else
                            {
                                searchResultItem.Documents.AddRange((IEnumerable <string>) this.ExtractDocumentLinks(str1, property2.Name));
                            }
                        }
                        if (property1.StripHtml)
                        {
                            str1 = str1.StripHtml();
                        }
                        if (property1.Content)
                        {
                            this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("Property is set as Content, adding content value from property {0} with value \"{1}\" to indexitem ", (object)propertyName, (object)str1), (Exception)null);
                            searchResultItem.Content.Add(str1);
                        }
                        string key = propertyName + dynamicFieldExtension;
                        this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("Adding property {0} with value \"{1}\" to indexitem ", (object)key, (object)str1), (Exception)null);
                        if (forceMultiValued)
                        {
                            char[] trimchars = new char[3]
                            {
                                ' ',
                                '\n',
                                '\r'
                            };
                            IEnumerable <string> strings = ((IEnumerable <string>)Array.ConvertAll <string, string>(str1.Split(new string[1]
                            {
                                property1.SplitChar
                            }, StringSplitOptions.RemoveEmptyEntries), (Converter <string, string>)(s => s.Trim(trimchars)))).AsEnumerable <string>();
                            searchResultItem.CmsProperties.Add(new KeyValuePair <string, object>(key, (object)strings));
                            if (property1.AlphabeticalIndex)
                            {
                                this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, "Multivalued property is set for alphabetical index, adding first letters to alphaindex", (Exception)null);
                                foreach (string str2 in strings)
                                {
                                    string lower = str2.Substring(0, 1).ToLower();
                                    if (!searchResultItem.AlphaIndex.Contains(lower))
                                    {
                                        searchResultItem.AlphaIndex.Add(lower);
                                    }
                                }
                            }
                        }
                        else
                        {
                            searchResultItem.CmsProperties.Add(new KeyValuePair <string, object>(key, (object)str1));
                            if (property1.AlphabeticalIndex)
                            {
                                this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, "Property is set for alphabetical index, adding first letter to alphaindex", (Exception)null);
                                string lower = str1.Substring(0, 1).ToLower();
                                if (!searchResultItem.AlphaIndex.Contains(lower))
                                {
                                    searchResultItem.AlphaIndex.Add(lower);
                                }
                            }
                        }
                    }
                }
            }
            return(searchResultItem);
        }