diff --git a/.gitattributes b/.gitattributes index 0899b91..974c308 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,3 @@ * text eol=crlf -*.png binary \ No newline at end of file +*.png binary +*.jpg binary \ No newline at end of file diff --git a/src/Kentico.Xperience.Lucene.Core/Indexing/IndexedItemModelExtensions.cs b/src/Kentico.Xperience.Lucene.Core/Indexing/IndexedItemModelExtensions.cs index 73b787a..3fe017c 100644 --- a/src/Kentico.Xperience.Lucene.Core/Indexing/IndexedItemModelExtensions.cs +++ b/src/Kentico.Xperience.Lucene.Core/Indexing/IndexedItemModelExtensions.cs @@ -1,101 +1,106 @@ -using CMS.ContentEngine.Internal; -using CMS.Core; - -namespace Kentico.Xperience.Lucene.Core.Indexing; - -/// -/// Lucene extension methods for the class. -/// -internal static class IndexedItemModelExtensions -{ - /// - /// Returns true if the node is included in the Lucene index based on the index's defined paths - /// - /// Logs an error if the search model cannot be found. - /// The node to check for indexing. - /// - /// The Lucene index code name. - /// - /// - /// - public static bool IsIndexedByIndex(this IndexEventWebPageItemModel item, IEventLogService log, ILuceneIndexManager indexManager, string indexName, string eventName) - { - if (string.IsNullOrWhiteSpace(indexName)) - { - throw new ArgumentNullException(nameof(indexName)); - } - if (item is null) - { - throw new ArgumentNullException(nameof(item)); - } - - var luceneIndex = indexManager.GetIndex(indexName); - if (luceneIndex is null) - { - log.LogError(nameof(IndexedItemModelExtensions), nameof(IsIndexedByIndex), $"Error loading registered Lucene index '{indexName}' for event [{eventName}]."); - return false; - } - - if (!luceneIndex.LanguageNames.Exists(x => x == item.LanguageName)) - { - return false; - } - - return luceneIndex.IncludedPaths.Any(path => - { - bool matchesContentType = path.ContentTypes.Exists(x => string.Equals(x.ContentTypeName, item.ContentTypeName)); - - if (!matchesContentType) - { - return false; - } - - // Supports wildcard matching - if (path.AliasPath.EndsWith("/%", StringComparison.OrdinalIgnoreCase)) - { - string pathToMatch = path.AliasPath[..^2]; - var pathsOnPath = TreePathUtils.GetTreePathsOnPath(item.WebPageItemTreePath, true, false).ToHashSet(); - - return pathsOnPath.Any(p => p.StartsWith(pathToMatch, StringComparison.OrdinalIgnoreCase)); - } - - return item.WebPageItemTreePath.Equals(path.AliasPath, StringComparison.OrdinalIgnoreCase); - }); - } - - /// - /// Returns true if the node is included in the Lucene index's allowed - /// - /// Logs an error if the search model cannot be found. - /// The node to check for indexing. - /// - /// The Lucene index code name. - /// - /// - /// - public static bool IsIndexedByIndex(this IndexEventReusableItemModel item, IEventLogService log, ILuceneIndexManager indexManager, string indexName, string eventName) - { - if (string.IsNullOrEmpty(indexName)) - { - throw new ArgumentNullException(nameof(indexName)); - } - if (item is null) - { - throw new ArgumentNullException(nameof(item)); - } - - var luceneIndex = indexManager.GetIndex(indexName); - if (luceneIndex is null) - { - log.LogError(nameof(IndexedItemModelExtensions), nameof(IsIndexedByIndex), $"Error loading registered Lucene index '{indexName}' for event [{eventName}]."); - return false; - } - - if (luceneIndex.LanguageNames.Exists(x => x == item.LanguageName)) - { - return true; - } - - return false; - } -} +using CMS.ContentEngine.Internal; +using CMS.Core; + +namespace Kentico.Xperience.Lucene.Core.Indexing; + +/// +/// Lucene extension methods for the class. +/// +internal static class IndexedItemModelExtensions +{ + /// + /// Returns true if the node is included in the Lucene index based on the index's defined paths + /// + /// Logs an error if the search model cannot be found. + /// The node to check for indexing. + /// + /// The Lucene index code name. + /// + /// + /// + public static bool IsIndexedByIndex(this IndexEventWebPageItemModel item, IEventLogService log, ILuceneIndexManager indexManager, string indexName, string eventName) + { + if (string.IsNullOrWhiteSpace(indexName)) + { + throw new ArgumentNullException(nameof(indexName)); + } + if (item is null) + { + throw new ArgumentNullException(nameof(item)); + } + + var luceneIndex = indexManager.GetIndex(indexName); + if (luceneIndex is null) + { + log.LogError(nameof(IndexedItemModelExtensions), nameof(IsIndexedByIndex), $"Error loading registered Lucene index '{indexName}' for event [{eventName}]."); + return false; + } + + if (!string.Equals(item.WebsiteChannelName, luceneIndex.WebSiteChannelName)) + { + return false; + } + + if (!luceneIndex.LanguageNames.Exists(x => x == item.LanguageName)) + { + return false; + } + + return luceneIndex.IncludedPaths.Any(path => + { + bool matchesContentType = path.ContentTypes.Exists(x => string.Equals(x.ContentTypeName, item.ContentTypeName)); + + if (!matchesContentType) + { + return false; + } + + // Supports wildcard matching + if (path.AliasPath.EndsWith("/%", StringComparison.OrdinalIgnoreCase)) + { + string pathToMatch = path.AliasPath[..^2]; + var pathsOnPath = TreePathUtils.GetTreePathsOnPath(item.WebPageItemTreePath, true, false).ToHashSet(); + + return pathsOnPath.Any(p => p.StartsWith(pathToMatch, StringComparison.OrdinalIgnoreCase)); + } + + return item.WebPageItemTreePath.Equals(path.AliasPath, StringComparison.OrdinalIgnoreCase); + }); + } + + /// + /// Returns true if the node is included in the Lucene index's allowed + /// + /// Logs an error if the search model cannot be found. + /// The node to check for indexing. + /// + /// The Lucene index code name. + /// + /// + /// + public static bool IsIndexedByIndex(this IndexEventReusableItemModel item, IEventLogService log, ILuceneIndexManager indexManager, string indexName, string eventName) + { + if (string.IsNullOrEmpty(indexName)) + { + throw new ArgumentNullException(nameof(indexName)); + } + if (item is null) + { + throw new ArgumentNullException(nameof(item)); + } + + var luceneIndex = indexManager.GetIndex(indexName); + if (luceneIndex is null) + { + log.LogError(nameof(IndexedItemModelExtensions), nameof(IsIndexedByIndex), $"Error loading registered Lucene index '{indexName}' for event [{eventName}]."); + return false; + } + + if (luceneIndex.LanguageNames.Exists(x => x == item.LanguageName)) + { + return true; + } + + return false; + } +}