Skip to content

Commit

Permalink
Update project to Umbraco 9.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
callumbwhyte committed May 29, 2022
1 parent 7630604 commit 66eb858
Show file tree
Hide file tree
Showing 25 changed files with 228 additions and 274 deletions.
4 changes: 2 additions & 2 deletions src/Our.Umbraco.Extensions.Search.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30104.148
# Visual Studio Version 17
VisualStudioVersion = 17.1.32319.34
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Our.Umbraco.Extensions.Search", "Our.Umbraco.Extensions.Search\Our.Umbraco.Extensions.Search.csproj", "{E5CC7AF7-800D-4636-B753-931C85DD28CA}"
EndProject
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.IO;
using Lucene.Net.Analysis;
using Lucene.Net.Util;

namespace Our.Umbraco.Extensions.Search.Analysis
{
public class WhitespaceSeparatorAnalyzer : Analyzer
{
public WhitespaceSeparatorAnalyzer(LuceneVersion matchVersion, char separator)
{
MatchVersion = matchVersion;
Separator = separator;
}

public LuceneVersion MatchVersion { get; }

public char Separator { get; }

protected override TokenStreamComponents CreateComponents(string fieldName, TextReader reader)
{
return new TokenStreamComponents(new WhitespaceSeparatorTokenizer(MatchVersion, reader, Separator));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.IO;
using J2N;
using Lucene.Net.Analysis.Util;
using Lucene.Net.Util;

namespace Our.Umbraco.Extensions.Search.Analysis
{
internal sealed class WhitespaceSeparatorTokenizer : CharTokenizer
{
public WhitespaceSeparatorTokenizer(LuceneVersion matchVersion, TextReader input, char separator)
: base(matchVersion, input)
{
Separator = separator;
}

public char Separator { get; }

protected override bool IsTokenChar(int c)
{
return Character.IsWhiteSpace(c) == false && Separator.Equals(c) == false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Collections.Generic;
using Examine;
using Examine.Lucene;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Our.Umbraco.Extensions.Search.ValueTypes;

namespace Our.Umbraco.Extensions.Search.Composing
{
internal class ConfigureIndexOptions : IConfigureNamedOptions<LuceneDirectoryIndexOptions>
{
private readonly ILoggerFactory _loggerFactory;

public ConfigureIndexOptions(ILoggerFactory loggerFactory)
{
_loggerFactory = loggerFactory;
}

public void Configure(string name, LuceneDirectoryIndexOptions options)
{
options.IndexValueTypesFactory = new Dictionary<string, IFieldValueTypeFactory>
{
{ "json", new DelegateFieldValueTypeFactory(fieldName => new JsonValueType(fieldName, _loggerFactory)) },
{ "list", new DelegateFieldValueTypeFactory(fieldName => new ListValueType(fieldName, _loggerFactory)) },
{ "picker", new DelegateFieldValueTypeFactory(fieldName => new PickerValueType(fieldName, _loggerFactory)) },
{ "udi", new DelegateFieldValueTypeFactory(fieldName => new UdiValueType(fieldName, _loggerFactory)) },
};

options.FieldDefinitions.AddOrUpdate(new FieldDefinition("path", "list"));

options.FieldDefinitions.AddOrUpdate(new FieldDefinition("createDate", "date"));

options.FieldDefinitions.AddOrUpdate(new FieldDefinition("updateDate", "date"));
}

public void Configure(LuceneDirectoryIndexOptions options) => Configure(string.Empty, options);
}
}
25 changes: 25 additions & 0 deletions src/Our.Umbraco.Extensions.Search/Composing/SearchComposer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.Extensions.DependencyInjection;
using Our.Umbraco.Extensions.Search.Helpers;
using Our.Umbraco.Extensions.Search.Mappers;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Web.Common.DependencyInjection;

namespace Our.Umbraco.Extensions.Search.Composing
{
public class SearchComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.Services.AddSingleton<SearchHelper>();

builder.Services.AddSingleton<PublishedContentHelper>();

builder.Services.ConfigureOptions<ConfigureIndexOptions>();

builder.MapDefinitions().Add<PublishedContentMapper>();

ServiceLocator.Configure(type => StaticServiceProvider.Instance.GetService(type));
}
}
}
16 changes: 16 additions & 0 deletions src/Our.Umbraco.Extensions.Search/Composing/ServiceLocator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace Our.Umbraco.Extensions.Search.Composing
{
internal class ServiceLocator
{
private static Func<Type, object> _findService;

public static T GetInstance<T>() => (T)_findService(typeof(T));

public static void Configure(Func<Type, object> findService)
{
_findService = findService;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using Examine.Lucene;
using Examine.Lucene.Indexing;
using Microsoft.Extensions.Logging;
using Our.Umbraco.Extensions.Search.ValueTypes;

namespace Our.Umbraco.Extensions.Search.Factories
{
public class MultipleValueTypeFactory : IFieldValueTypeFactory
{
private readonly ILoggerFactory _loggerFactory;
private readonly Func<string, IEnumerable<IIndexFieldValueType>> _factories;

public MultipleValueTypeFactory(ILoggerFactory loggerFactory, Func<string, IEnumerable<IIndexFieldValueType>> factories)
{
_loggerFactory = loggerFactory;
_factories = factories;
}

public IIndexFieldValueType Create(string fieldName)
{
return new MultiValueType(fieldName, _loggerFactory, _factories(fieldName));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web;
using UdiEntityType = Umbraco.Core.Constants.UdiEntityType;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.Web;

namespace Our.Umbraco.Extensions.Search.Helpers
{
Expand All @@ -28,7 +27,7 @@ public IPublishedContent GetByString(string id)
return GetByGuid(guidId);
}

if (Udi.TryParse(id, out Udi udi) == true)
if (UdiParser.TryParse(id, out Udi udi) == true)
{
return GetByUdi(udi);
}
Expand Down Expand Up @@ -58,7 +57,7 @@ public IPublishedContent GetByUdi(Udi udi)
{
using (var context = _umbracoContextFactory.EnsureUmbracoContext())
{
var umbracoType = UdiEntityType.ToUmbracoObjectType(udi.EntityType);
var umbracoType = UdiEntityTypeHelper.ToUmbracoObjectType(udi.EntityType);

if (umbracoType == UmbracoObjectTypes.Document)
{
Expand Down
19 changes: 1 addition & 18 deletions src/Our.Umbraco.Extensions.Search/Helpers/SearchHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,12 @@
using System.Linq;
using Examine;
using Examine.Search;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Cms.Core.Models.PublishedContent;

namespace Our.Umbraco.Extensions.Search.Helpers
{
public class SearchHelper
{
private readonly IExamineManager _examineManager;

public SearchHelper(IExamineManager examineManager)
{
_examineManager = examineManager;
}

/// <summary>
/// Get a searcher by name
/// </summary>
public ISearcher GetSearcher(string name)
{
_examineManager.TryGetSearcher(name, out ISearcher searcher);

return searcher;
}

/// <summary>
/// Get the results for the given query
/// </summary>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using Examine;
using Our.Umbraco.Extensions.Search.Helpers;
using Umbraco.Core;
using Umbraco.Core.Mapping;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Mapping;
using Umbraco.Cms.Core.Models.PublishedContent;

namespace Our.Umbraco.Extensions.Search.Mappers
{
Expand All @@ -16,7 +16,7 @@ public PublishedContentMapper(PublishedContentHelper publishedContentHelper)
_publishedContentHelper = publishedContentHelper;
}

public void DefineMaps(UmbracoMapper mapper)
public void DefineMaps(IUmbracoMapper mapper)
{
mapper.Define<ISearchResult, IPublishedContent>((source, context) => _publishedContentHelper.GetByString(source.Id));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<Version Condition="'$(BUILD_BUILDNUMBER)' == ''">1.0.0.0</Version>
<Version Condition="'$(BUILD_BUILDNUMBER)' != ''">$(BUILD_BUILDNUMBER)</Version>
<Description>Extensions for performing searches in Umbraco</Description>
Expand All @@ -15,6 +15,6 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="UmbracoCms.Web" Version="8.1.0" />
<PackageReference Include="Umbraco.Cms.Examine.Lucene" Version="[9.0.1,10.0.0)" />
</ItemGroup>
</Project>
Loading

0 comments on commit 66eb858

Please sign in to comment.