Skip to content

Commit

Permalink
contexts and sharding in progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeme committed Sep 12, 2023
1 parent d88930d commit 1d0460e
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\DotJEM.Json.Index2.common.props" />

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<GenerateDocumentationFile>False</GenerateDocumentationFile>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="NUnit" Version="3.13.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DotJEM.Json.Index2.Contexts\DotJEM.Json.Index2.Contexts.csproj" />
<ProjectReference Include="..\DotJEM.Json.Index2\DotJEM.Json.Index2.csproj" />
</ItemGroup>

</Project>
48 changes: 48 additions & 0 deletions src/DotJEM.Json.Index2.Contexts.Test/LuceneIndexContextTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using DotJEM.Json.Index2.Documents.Fields;
using DotJEM.Json.Index2.IO;
using DotJEM.Json.Index2.Searching;
using DotJEM.Json.Index2.Storage;
using Lucene.Net.Analysis.Standard;
using Lucene.Net.Index;
using Lucene.Net.Search;
using Newtonsoft.Json.Linq;
using NUnit.Framework;

namespace DotJEM.Json.Index2.Contexts.Test;

public class LuceneIndexContextTest
{
[Test]
public async Task SayHello_ReturnsHello()
{
IJsonIndexContextBuilder builder = new JsonIndexContextBuilder();
builder
.ByDefault(x => x.UsingMemmoryStorage().Build());
builder
.For("IndexName", b => b.UsingStorage(new RamJsonIndexStorage()).Build());



IJsonIndexContext context = builder.Build();
context.Open("IndexName");

IJsonIndex index = new JsonIndexBuilder("myIndex")
.UsingMemmoryStorage()
.WithAnalyzer(cfg => new StandardAnalyzer(cfg.Version))
.WithFieldResolver(new FieldResolver("uuid", "type"))
.Build();

IJsonIndexWriter writer = index.CreateWriter();
writer.Create(JObject.FromObject(new { uuid = Guid.NewGuid(), type = "CAR" }));
writer.Create(JObject.FromObject(new { uuid = Guid.NewGuid(), type = "CAR" }));
writer.Create(JObject.FromObject(new { uuid = Guid.NewGuid(), type = "CAR" }));
writer.Create(JObject.FromObject(new { uuid = Guid.NewGuid(), type = "CAR" }));
writer.Create(JObject.FromObject(new { uuid = Guid.NewGuid(), type = "CAR" }));
writer.Commit();

IJsonIndexSearcher? searcher = index.CreateSearcher();
int count = searcher.Search(new TermQuery(new Term("type", "car"))).Count();
//int count = searcher.Search(new MatchAllDocsQuery()).Count();
Assert.AreEqual(5, count);
}
}
28 changes: 28 additions & 0 deletions src/DotJEM.Json.Index2.Contexts/LuceneIndexContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,31 @@ public interface ILuceneJsonIndexFactory
{
IJsonIndex Create(string name);
}

public interface IJsonIndexContextBuilder
{
IJsonIndexContextBuilder ByDefault(Func<IJsonIndexBuilder, IJsonIndex> defaultConfig);
IJsonIndexContextBuilder For(string name, Func<IJsonIndexBuilder, IJsonIndex> defaultConfig);
IJsonIndexContext Build();
}

public class JsonIndexContextBuilder : IJsonIndexContextBuilder
{
private readonly ConcurrentDictionary<string, Func<IJsonIndexBuilder, IJsonIndex>> configurators = new();
public IJsonIndexContextBuilder ByDefault(Func<IJsonIndexBuilder, IJsonIndex> defaultConfig)
{
configurators.AddOrUpdate("*", s => defaultConfig, (s, func) => defaultConfig);
return this;
}

public IJsonIndexContextBuilder For(string name, Func<IJsonIndexBuilder, IJsonIndex> defaultConfig)
{
configurators.AddOrUpdate(name, s => defaultConfig, (s, func) => defaultConfig);
return this;
}

public IJsonIndexContext Build()
{
return new JsonIndexContext(null);
}
}
37 changes: 37 additions & 0 deletions src/DotJEM.Json.Index2.Contexts/Sharding/ShardingJsonIndex.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DotJEM.Json.Index2.Configuration;
using DotJEM.Json.Index2.IO;
using DotJEM.Json.Index2.Searching;
using DotJEM.Json.Index2.Storage;
using DotJEM.ObservableExtensions.InfoStreams;

namespace DotJEM.Json.Index2.Contexts.Sharding
{
internal class ShardingJsonIndex : IJsonIndex
{
public IJsonIndexSearcher CreateSearcher()
{
throw new NotImplementedException();
}

public IInfoStream InfoStream { get; }
public IJsonIndexStorageManager Storage { get; }
public IJsonIndexConfiguration Configuration { get; }
public IIndexWriterManager WriterManager { get; }
public IIndexSearcherManager SearcherManager { get; }

public IJsonIndexWriter CreateWriter()
{
throw new NotImplementedException();
}

public void Close()
{
throw new NotImplementedException();
}
}
}
8 changes: 7 additions & 1 deletion src/DotJEM.Json.Index2.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotJEM.Json.Index2.Contexts
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotJEM.Json.Index2.QueryParsers", "DotJEM.Json.Index2.QueryParsers\DotJEM.Json.Index2.QueryParsers.csproj", "{B07B4E9F-7202-4E9D-ACCC-717B43469A7A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotJEM.Json.Index2.Snapshots", "DotJEM.Json.Index2.Snapshots\DotJEM.Json.Index2.Snapshots.csproj", "{98FF81EC-F9B6-4B6C-9B02-2A5830756B05}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotJEM.Json.Index2.Snapshots", "DotJEM.Json.Index2.Snapshots\DotJEM.Json.Index2.Snapshots.csproj", "{98FF81EC-F9B6-4B6C-9B02-2A5830756B05}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotJEM.Json.Index2.Contexts.Test", "DotJEM.Json.Index2.Contexts.Test\DotJEM.Json.Index2.Contexts.Test.csproj", "{8F30DDCD-334C-4C47-AE47-9DCEB0CB4C73}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -49,6 +51,10 @@ Global
{98FF81EC-F9B6-4B6C-9B02-2A5830756B05}.Debug|Any CPU.Build.0 = Debug|Any CPU
{98FF81EC-F9B6-4B6C-9B02-2A5830756B05}.Release|Any CPU.ActiveCfg = Release|Any CPU
{98FF81EC-F9B6-4B6C-9B02-2A5830756B05}.Release|Any CPU.Build.0 = Release|Any CPU
{8F30DDCD-334C-4C47-AE47-9DCEB0CB4C73}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8F30DDCD-334C-4C47-AE47-9DCEB0CB4C73}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8F30DDCD-334C-4C47-AE47-9DCEB0CB4C73}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8F30DDCD-334C-4C47-AE47-9DCEB0CB4C73}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 2 additions & 2 deletions src/DotJEM.Json.Index2/IJsonIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ public interface IJsonIndexBuilder

public class JsonIndexBuilder : IJsonIndexBuilder
{
private readonly string name = Guid.NewGuid().ToString("D");
public string Name { get; } = Guid.NewGuid().ToString("D");
private IJsonIndexStorage storage = new RamJsonIndexStorage();
private readonly Dictionary<Type, Func<IJsonIndexConfiguration, object>> factories = new();

public JsonIndexBuilder(string name)
{
this.name = name;
this.Name = name;
}

public IJsonIndexBuilder UsingStorage(IJsonIndexStorage storage)
Expand Down

0 comments on commit 1d0460e

Please sign in to comment.