Adds IValueIndexer for the RTE
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
using Lucene.Net.Documents;
|
||||
using Umbraco.Core;
|
||||
using Examine.LuceneEngine.Indexing;
|
||||
using Umbraco.Core.Xml;
|
||||
|
||||
namespace Umbraco.Examine
|
||||
{
|
||||
/// <summary>
|
||||
/// Strips HTML symbols from the text
|
||||
/// </summary>
|
||||
public class HtmlValueType : FullTextType
|
||||
{
|
||||
private readonly bool _storeRawValue;
|
||||
|
||||
public HtmlValueType(string fieldName, bool storeRawValue) : base(fieldName, false)
|
||||
{
|
||||
_storeRawValue = storeRawValue;
|
||||
}
|
||||
|
||||
protected override void AddSingleValue(Document doc, object value)
|
||||
{
|
||||
if (TryConvert<string>(value, out var str))
|
||||
{
|
||||
if (XmlHelper.CouldItBeXml(str))
|
||||
{
|
||||
base.AddSingleValue(doc, str.StripHtml());
|
||||
|
||||
if (_storeRawValue)
|
||||
{
|
||||
doc.Add(new Field(UmbracoExamineIndexer.RawFieldPrefix + FieldName, str,
|
||||
Field.Store.YES,
|
||||
Field.Index.NO,
|
||||
Field.TermVector.NO));
|
||||
}
|
||||
}
|
||||
else
|
||||
base.AddSingleValue(doc, str);
|
||||
}
|
||||
else
|
||||
base.AddSingleValue(doc, str);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,6 @@
|
||||
<Compile Include="Config\IndexSet.cs" />
|
||||
<Compile Include="Config\IndexSetCollection.cs" />
|
||||
<Compile Include="Config\IndexSets.cs" />
|
||||
<Compile Include="HtmlValueType.cs" />
|
||||
<Compile Include="IUmbracoIndexer.cs" />
|
||||
<Compile Include="UmbracoExamineExtensions.cs" />
|
||||
<Compile Include="IndexTypes.cs" />
|
||||
|
||||
@@ -6,6 +6,7 @@ using Umbraco.Core.Macros;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Examine;
|
||||
using Umbraco.Web.Macros;
|
||||
|
||||
namespace Umbraco.Web.PropertyEditors
|
||||
@@ -31,6 +32,7 @@ namespace Umbraco.Web.PropertyEditors
|
||||
|
||||
protected override IConfigurationEditor CreateConfigurationEditor() => new RichTextConfigurationEditor();
|
||||
|
||||
public override IValueIndexer ValueIndexer => new RichTextValueIndexer();
|
||||
|
||||
/// <summary>
|
||||
/// A custom value editor to ensure that macro syntax is parsed when being persisted and formatted correctly for display in the editor
|
||||
@@ -90,6 +92,21 @@ namespace Umbraco.Web.PropertyEditors
|
||||
return parsed;
|
||||
}
|
||||
}
|
||||
|
||||
internal class RichTextValueIndexer : IValueIndexer
|
||||
{
|
||||
public IEnumerable<KeyValuePair<string, object[]>> GetIndexValues(Property property, string culture)
|
||||
{
|
||||
var val = property.GetValue(culture);
|
||||
|
||||
if (!(val is string strVal)) yield break;
|
||||
|
||||
//index the stripped html values
|
||||
yield return new KeyValuePair<string, object[]>(property.Alias, new[] { strVal.StripHtml() });
|
||||
//store the raw value
|
||||
yield return new KeyValuePair<string, object[]>($"{UmbracoExamineIndexer.RawFieldPrefix}{property.Alias}", new[] { strVal });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user