Skip to content

Commit

Permalink
Indexing media tags as a facet; showing raw value for incorrectly ind…
Browse files Browse the repository at this point in the history
…exed date fields (#689)
  • Loading branch information
Anstsiya authored Oct 25, 2019
1 parent a5026f0 commit 97099e8
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 8 deletions.
1 change: 1 addition & 0 deletions Composite/Composite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@
<Compile Include="Properties\GitCommitInfo.cs" />
<Compile Include="Search\Crawling\DataFieldProcessors\DateTimeDataFieldProcessor.cs" />
<Compile Include="Search\Crawling\DataFieldProcessors\FileNameDataFieldProcessor.cs" />
<Compile Include="Search\Crawling\DataFieldProcessors\MediaTagsDataFieldProcessor.cs" />
<Compile Include="Search\Crawling\DataFieldProcessors\MimeTypeDataFieldProcessor.cs" />
<Compile Include="Search\Crawling\DataFieldProcessors\PublicationStatusDataFieldProcessor.cs" />
<Compile Include="Search\Crawling\DocumentFieldNames.cs" />
Expand Down
4 changes: 2 additions & 2 deletions Composite/Data/Types/IMediaFile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using Composite.Data.Hierarchy;
using Composite.Core.WebClient.Renderings.Data;

Expand Down Expand Up @@ -58,7 +58,7 @@ public interface IMediaFile : IFile
/// <exclude />
[ImmutableFieldId("{016372B5-9692-4C2D-B64D-8FC6594BBCFF}")]
[StoreFieldType(PhysicalStoreFieldType.LargeString)]
[SearchableField(true, true, false)]
[SearchableField(true, true, true)]
string Tags { get; set; }


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Globalization;
using System.Reflection;

Expand All @@ -21,10 +21,12 @@ protected override DocumentFieldPreview.ValuePreviewDelegate GetPreviewFunction(
return value =>
{
if (value == null) return null;
var date = DateTime.ParseExact((string)value, "s", CultureInfo.InvariantCulture);

return date.ToString("yyyy MMM d");
};
if (DateTime.TryParseExact((string)value, "s", CultureInfo.InvariantCulture, DateTimeStyles.None, out var date))
{
return date.ToString("yyyy MMM d");
}
return (string)value;
};
}

/// <exclude />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Composite.Core.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Composite.Search.Crawling.DataFieldProcessors
{
class MediaTagsDataFieldProcessor : DefaultDataFieldProcessor
{
public override string[] GetFacetValues(object value)
{
var str = (string)value;
var strList = str.Split(',').Select(s => s.Trim()).Where(s => !s.IsNullOrEmpty()).ToArray();
return strList;
}

public override DocumentFieldFacet GetDocumentFieldFacet(PropertyInfo propertyInfo)
{
var result = base.GetDocumentFieldFacet(propertyInfo);

result.FacetType = FacetType.MultipleValues;

return result;
}

}

}

8 changes: 7 additions & 1 deletion Composite/Search/Crawling/DataTypeSearchReflectionHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -81,6 +81,12 @@ internal static IDataFieldProcessor GetDataFieldProcessor(PropertyInfo propertyI
return new MimeTypeDataFieldProcessor();
}

if (propertyInfo.DeclaringType == typeof(IMediaFile)
&& propertyInfo.Name == nameof(IMediaFile.Tags))
{
return new MediaTagsDataFieldProcessor();
}

return new DefaultDataFieldProcessor();
});
}
Expand Down

0 comments on commit 97099e8

Please sign in to comment.