-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7630604
commit 66eb858
Showing
25 changed files
with
228 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/Our.Umbraco.Extensions.Search/Analysis/WhitespaceSeparatorAnalyzer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Our.Umbraco.Extensions.Search/Analysis/WhitespaceSeparatorTokenizer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/Our.Umbraco.Extensions.Search/Composing/ConfigureIndexOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
25
src/Our.Umbraco.Extensions.Search/Composing/SearchComposer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
src/Our.Umbraco.Extensions.Search/Composing/ServiceLocator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/Our.Umbraco.Extensions.Search/Factories/MultipleValueTypeFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 0 additions & 38 deletions
38
src/Our.Umbraco.Extensions.Search/LuceneEngine/Analysis/WhitespaceSeparatorAnalyzer.cs
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
src/Our.Umbraco.Extensions.Search/LuceneEngine/Analysis/WhitespaceSeparatorTokenizer.cs
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
src/Our.Umbraco.Extensions.Search/LuceneEngine/Factories/MultipleValueTypeFactory.cs
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
src/Our.Umbraco.Extensions.Search/LuceneEngine/ValueTypes/ListValueType.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.