diff --git a/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs
index 19a995bcbf..de59563a6b 100644
--- a/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs
+++ b/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs
@@ -17,6 +17,7 @@ using Examine.Session;
using LightInject;
using Umbraco.Core.Logging;
using Umbraco.Core.Strings;
+using UmbracoExamine;
namespace Umbraco.Tests.PublishedContent
{
@@ -104,7 +105,7 @@ namespace Umbraco.Tests.PublishedContent
public void Ensure_Children_Sorted_With_Examine()
{
using (var luceneDir = new RAMDirectory())
- using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir))
+ using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir, options: new UmbracoContentIndexerOptions(true, false, null)))
using (var session = new ThreadScopedIndexSession(indexer.SearcherContext))
{
indexer.RebuildIndex();
@@ -136,7 +137,7 @@ namespace Umbraco.Tests.PublishedContent
public void Do_Not_Find_In_Recycle_Bin()
{
using (var luceneDir = new RAMDirectory())
- using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir))
+ using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir, options: new UmbracoContentIndexerOptions(true, false, null)))
using (var session = new ThreadScopedIndexSession(indexer.SearcherContext))
{
indexer.RebuildIndex();
@@ -159,6 +160,7 @@ namespace Umbraco.Tests.PublishedContent
jpg
");
indexer.ReIndexNode(newXml, "media");
+ session.WaitForChanges();
//ensure it still exists in the index (raw examine search)
var criteria = searcher.CreateSearchCriteria();
@@ -179,7 +181,7 @@ namespace Umbraco.Tests.PublishedContent
public void Children_With_Examine()
{
using (var luceneDir = new RAMDirectory())
- using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir))
+ using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir, options: new UmbracoContentIndexerOptions(true, false, null)))
using (var session = new ThreadScopedIndexSession(indexer.SearcherContext))
{
indexer.RebuildIndex();
@@ -204,7 +206,7 @@ namespace Umbraco.Tests.PublishedContent
public void Descendants_With_Examine()
{
using (var luceneDir = new RAMDirectory())
- using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir))
+ using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir, options: new UmbracoContentIndexerOptions(true, false, null)))
using (var session = new ThreadScopedIndexSession(indexer.SearcherContext))
{
indexer.RebuildIndex();
@@ -229,7 +231,7 @@ namespace Umbraco.Tests.PublishedContent
public void DescendantsOrSelf_With_Examine()
{
using (var luceneDir = new RAMDirectory())
- using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir))
+ using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir, options: new UmbracoContentIndexerOptions(true, false, null)))
using (var session = new ThreadScopedIndexSession(indexer.SearcherContext))
{
indexer.RebuildIndex();
@@ -254,7 +256,7 @@ namespace Umbraco.Tests.PublishedContent
public void Ancestors_With_Examine()
{
using (var luceneDir = new RAMDirectory())
- using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir))
+ using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir, options: new UmbracoContentIndexerOptions(true, false, null)))
using (var session = new ThreadScopedIndexSession(indexer.SearcherContext))
{
indexer.RebuildIndex();
@@ -276,7 +278,7 @@ namespace Umbraco.Tests.PublishedContent
public void AncestorsOrSelf_With_Examine()
{
using (var luceneDir = new RAMDirectory())
- using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir))
+ using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir, options: new UmbracoContentIndexerOptions(true, false, null)))
using (var session = new ThreadScopedIndexSession(indexer.SearcherContext))
{
indexer.RebuildIndex();
diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs
index 98ecc18058..d4adafad23 100644
--- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs
+++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs
@@ -628,15 +628,9 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
{
if (LoadedFromExamine)
{
- try
- {
- //we might need to parse the date time using Lucene converters
- return DateTools.StringToDate(val);
- }
- catch (FormatException)
- {
- //swallow exception, its not formatted correctly so revert to just trying to parse
- }
+ //we need to parse the date time using Lucene converters
+ var ticks = long.Parse(val);
+ return new DateTime(ticks);
}
return DateTime.Parse(val);
diff --git a/src/UmbracoExamine/BaseUmbracoIndexer.cs b/src/UmbracoExamine/BaseUmbracoIndexer.cs
index 3f6d62ec15..ff4e13de13 100644
--- a/src/UmbracoExamine/BaseUmbracoIndexer.cs
+++ b/src/UmbracoExamine/BaseUmbracoIndexer.cs
@@ -36,6 +36,7 @@ namespace UmbracoExamine
public const string IndexPathFieldName = "__Path";
public const string NodeTypeAliasFieldName = "__NodeTypeAlias";
public const string IconFieldName = "__Icon";
+ public const string PublishedFieldName = "__Published";
///
/// The prefix added to a field when it is duplicated in order to store the original raw value.
///
@@ -254,11 +255,20 @@ namespace UmbracoExamine
}
}
+ public override void IndexItems(IEnumerable nodes)
+ {
+ if (CanInitialize())
+ {
+ base.IndexItems(nodes);
+ }
+ }
+
+ [Obsolete("Use ValueSets with IndexItems instead")]
public override void ReIndexNode(XElement node, string type)
{
if (CanInitialize())
{
- if (!SupportedTypes.Contains(type))
+ if (SupportedTypes.Contains(type) == false)
return;
if (node.Attribute("id") != null)
@@ -271,8 +281,6 @@ namespace UmbracoExamine
ProfilingLogger.Logger.Error(GetType(), "ReIndexNode cannot proceed, the format of the XElement is invalid",
new XmlException("XElement is invalid, the xml has not id attribute"));
}
-
- base.ReIndexNode(node, type);
}
}
diff --git a/src/UmbracoExamine/UmbracoContentIndexer.cs b/src/UmbracoExamine/UmbracoContentIndexer.cs
index 7632a86063..29795610f1 100644
--- a/src/UmbracoExamine/UmbracoContentIndexer.cs
+++ b/src/UmbracoExamine/UmbracoContentIndexer.cs
@@ -327,6 +327,7 @@ namespace UmbracoExamine
//add a custom 'icon' attribute
xml.Add(new XAttribute("icon", c.ContentType.Icon));
+ xml.Add(new XAttribute(PublishedFieldName, c.Published ? 1 : 0));
yield return xml;
}
diff --git a/src/UmbracoExamine/UmbracoContentValueSetValidator.cs b/src/UmbracoExamine/UmbracoContentValueSetValidator.cs
index 48f06809a6..18842db11b 100644
--- a/src/UmbracoExamine/UmbracoContentValueSetValidator.cs
+++ b/src/UmbracoExamine/UmbracoContentValueSetValidator.cs
@@ -14,7 +14,7 @@ namespace UmbracoExamine
{
private readonly UmbracoContentIndexerOptions _options;
private readonly IPublicAccessService _publicAccessService;
-
+ private const string PathKey = "path";
public UmbracoContentValueSetValidator(UmbracoContentIndexerOptions options, IPublicAccessService publicAccessService)
{
_options = options;
@@ -23,23 +23,33 @@ namespace UmbracoExamine
public bool Validate(ValueSet valueSet)
{
+ //check for published content
+ if (valueSet.IndexCategory == IndexTypes.Content
+ && valueSet.Values.ContainsKey(BaseUmbracoIndexer.PublishedFieldName))
+ {
+ var published = valueSet.Values[BaseUmbracoIndexer.PublishedFieldName] != null && valueSet.Values[BaseUmbracoIndexer.PublishedFieldName][0].Equals(1);
+ //we don't support unpublished and the item is not published return false
+ if (_options.SupportUnpublishedContent == false && published == false)
+ {
+ return false;
+ }
+ }
+
//must have a 'path'
- if (valueSet.Values.ContainsKey("path") == false) return false;
+ if (valueSet.Values.ContainsKey(PathKey) == false) return false;
+ var path = valueSet.Values[PathKey] == null ? string.Empty : valueSet.Values[PathKey][0].ToString();
- var path = valueSet.Values["path"] == null ? string.Empty : valueSet.Values["path"][0].ToString();
-
-
// Test for access if we're only indexing published content
// return nothing if we're not supporting protected content and it is protected, and we're not supporting unpublished content
- if (_options.SupportUnpublishedContent == false
- && (_options.SupportProtectedContent == false
- && path != null
- && _publicAccessService.IsProtected(path)))
+ if (valueSet.IndexCategory == IndexTypes.Content
+ && _options.SupportUnpublishedContent == false
+ && _options.SupportProtectedContent == false
+ && _publicAccessService.IsProtected(path))
{
return false;
}
- //check if this document is a descendent of the parent
+ //check if this document is a descendent of the parent
if (_options.ParentId.HasValue && _options.ParentId.Value > 0)
{
if (path.IsNullOrWhiteSpace()) return false;
@@ -47,6 +57,15 @@ namespace UmbracoExamine
return false;
}
+ //check for recycle bin
+ if (_options.SupportUnpublishedContent == false)
+ {
+ if (path.IsNullOrWhiteSpace()) return false;
+ var recycleBinId = valueSet.IndexCategory == IndexTypes.Content ? Constants.System.RecycleBinContent : Constants.System.RecycleBinMedia;
+ if (path.Contains(string.Concat(",", recycleBinId, ",")))
+ return false;
+ }
+
return true;
}
}