Skip to content

Commit 6489247

Browse files
committed
Add new constructor parameter to pass AdvancedZoneTreeOptions.
1 parent f8955b6 commit 6489247

6 files changed

+101
-27
lines changed

src/ZoneTree.FullTextSearch/Directory.Build.props

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<Authors>Ahmed Yasin Koculu</Authors>
66
<PackageId>ZoneTree.FullTextSearch</PackageId>
77
<Title>ZoneTree.FullTextSearch</Title>
8-
<ProductVersion>1.0.7.0</ProductVersion>
9-
<Version>1.0.7.0</Version>
8+
<ProductVersion>1.0.8.0</ProductVersion>
9+
<Version>1.0.8.0</Version>
1010
<Authors>Ahmed Yasin Koculu</Authors>
1111
<AssemblyTitle>ZoneTree.FullTextSearch</AssemblyTitle>
1212
<Description>ZoneTree.FullTextSearch is an open-source library that extends ZoneTree to provide efficient full-text search capabilities. It offers a fast, embedded search engine suitable for applications that require high performance and do not rely on external databases.</Description>

src/ZoneTree.FullTextSearch/Index/IndexOfTokenRecordPreviousToken.cs

+11-17
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using ZoneTree.FullTextSearch.Model;
77
using ZoneTree.FullTextSearch.QueryLanguage;
88
using ZoneTree.FullTextSearch.Search;
9+
using ZoneTree.FullTextSearch.SearchEngines;
910

1011
namespace ZoneTree.FullTextSearch.Index;
1112

@@ -91,33 +92,26 @@ public bool IsReadOnly
9192
/// Initializes a new instance of the <see cref="IndexOfTokenRecordPreviousToken{TRecord, TToken}"/> class,
9293
/// with the option to configure primary and secondary zone trees.
9394
/// </summary>
95+
/// <param name="dataPath">The path to the data storage, defaulting to "data".</param>
9496
/// <param name="recordComparer">The comparer of record.</param>
9597
/// <param name="tokenComparer">The comparer of token.</param>
96-
/// <param name="useSecondaryIndex">Indicates whether a secondary index should be used to perform faster deletion.</param>
97-
/// <param name="dataPath">The path to the data storage, defaulting to "data".</param>
98-
/// <param name="configure1">Optional configuration action for the primary zone tree.</param>
99-
/// <param name="configure2">Optional configuration action for the secondary zone tree.</param>
98+
/// <param name="useSecondaryIndex">Indicates whether a secondary index should be used to perform faster deletion.</param>
10099
/// <param name="blockCacheLifeTimeInMilliseconds">Defines the life time of cached blocks. Default is 1 minute.</param>
100+
/// /// <param name="advancedOptions">Advanced ZoneTree Options enabling customization of underlying ZoneTree instances.</param>
101101
public IndexOfTokenRecordPreviousToken(
102102
string dataPath = "data",
103103
IRefComparer<TRecord> recordComparer = null,
104104
IRefComparer<TToken> tokenComparer = null,
105105
bool useSecondaryIndex = false,
106-
Action<
107-
ZoneTreeFactory<
108-
CompositeKeyOfTokenRecordPrevious<TRecord, TToken>,
109-
byte>> configure1 = null,
110-
Action<
111-
ZoneTreeFactory<
112-
CompositeKeyOfRecordToken<TRecord, TToken>,
113-
byte>> configure2 = null,
114-
long blockCacheLifeTimeInMilliseconds = 60_000)
106+
long blockCacheLifeTimeInMilliseconds = 60_000,
107+
AdvancedZoneTreeOptions<TRecord, TToken> advancedOptions = null)
115108
{
116109
if (recordComparer == null)
117110
recordComparer = ComponentsForKnownTypes.GetComparer<TRecord>();
118111
if (tokenComparer == null)
119112
tokenComparer = ComponentsForKnownTypes.GetComparer<TToken>();
120-
var factory1 = new ZoneTreeFactory<CompositeKeyOfTokenRecordPrevious<TRecord, TToken>, byte>()
113+
var fileStreamProvider = advancedOptions?.FileStreamProvider;
114+
var factory1 = new ZoneTreeFactory<CompositeKeyOfTokenRecordPrevious<TRecord, TToken>, byte>(fileStreamProvider)
121115
.SetDataDirectory($"{dataPath}/index1")
122116
.SetIsDeletedDelegate(
123117
(in CompositeKeyOfTokenRecordPrevious<TRecord, TToken> key, in byte value) => value == 1)
@@ -128,7 +122,7 @@ public IndexOfTokenRecordPreviousToken(
128122
recordComparer,
129123
tokenComparer));
130124

131-
configure1?.Invoke(factory1);
125+
advancedOptions?.FactoryConfigurator1?.Invoke(factory1);
132126

133127
ZoneTree1 = factory1.OpenOrCreate();
134128
Maintainer1 = ZoneTree1.CreateMaintainer();
@@ -141,7 +135,7 @@ public IndexOfTokenRecordPreviousToken(
141135
this.useSecondaryIndex = useSecondaryIndex;
142136
if (useSecondaryIndex)
143137
{
144-
var factory2 = new ZoneTreeFactory<CompositeKeyOfRecordToken<TRecord, TToken>, byte>()
138+
var factory2 = new ZoneTreeFactory<CompositeKeyOfRecordToken<TRecord, TToken>, byte>(fileStreamProvider)
145139
.SetDataDirectory($"{dataPath}/index2")
146140
.SetIsDeletedDelegate(
147141
(in CompositeKeyOfRecordToken<TRecord, TToken> key, in byte value) => value == 1)
@@ -152,7 +146,7 @@ public IndexOfTokenRecordPreviousToken(
152146
recordComparer,
153147
tokenComparer));
154148

155-
configure2?.Invoke(factory2);
149+
advancedOptions?.FactoryConfigurator2?.Invoke(factory2);
156150

157151
ZoneTree2 = factory2.OpenOrCreate();
158152
Maintainer2 = ZoneTree2.CreateMaintainer();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using Tenray.ZoneTree;
2+
using ZoneTree.FullTextSearch.Model;
3+
using Tenray.ZoneTree.AbstractFileStream;
4+
5+
namespace ZoneTree.FullTextSearch.SearchEngines;
6+
7+
/// <summary>
8+
/// Provides advanced options for configuring the underlying ZoneTree instances
9+
/// used in the full-text search engine.
10+
/// </summary>
11+
/// <typeparam name="TRecord">
12+
/// The type of the record being indexed.
13+
/// </typeparam>
14+
/// <typeparam name="TToken">
15+
/// The type of the token used for hashing and indexing.
16+
/// </typeparam>
17+
public sealed class AdvancedZoneTreeOptions<TRecord, TToken>
18+
where TRecord : unmanaged
19+
where TToken : unmanaged
20+
{
21+
/// <summary>
22+
/// Gets or sets the <see cref="IFileStreamProvider"/> used to manage file streams
23+
/// for storing ZoneTree data. If this is <c>null</c>, the default implementation
24+
/// provided by ZoneTree will be used.
25+
/// </summary>
26+
public IFileStreamProvider FileStreamProvider { get; set; }
27+
28+
/// <summary>
29+
/// Gets or sets an optional delegate that configures the <see cref="ZoneTreeFactory{TKey,TValue}"/>
30+
/// for the <see cref="CompositeKeyOfTokenRecordPrevious{TRecord, TToken}"/> keys
31+
/// and <see cref="byte"/> values.
32+
/// <para>
33+
/// This is called before the factory builds its internal ZoneTree. You can use it
34+
/// to configure advanced settings such as in-memory or on-disk data paths, caching,
35+
/// block sizes, compression, or other low-level ZoneTree behaviors.
36+
/// </para>
37+
/// </summary>
38+
/// <remarks>
39+
/// This configurator applies specifically to data indexed by the hashed token
40+
/// combined with the "previous token" to enforce token order.
41+
/// </remarks>
42+
public Action<
43+
ZoneTreeFactory<
44+
CompositeKeyOfTokenRecordPrevious<TRecord, TToken>,
45+
byte>> FactoryConfigurator1
46+
{ get; set; }
47+
48+
/// <summary>
49+
/// Gets or sets an optional delegate that configures the <see cref="ZoneTreeFactory{TKey,TValue}"/>
50+
/// for the <see cref="CompositeKeyOfRecordToken{TRecord, TToken}"/> keys and <see cref="byte"/> values.
51+
/// <para>
52+
/// Similar to <see cref="FactoryConfigurator1"/>, this is invoked before the factory
53+
/// completes its setup, allowing custom adjustments for storage, caching, and other
54+
/// advanced ZoneTree features.
55+
/// </para>
56+
/// </summary>
57+
/// <remarks>
58+
/// This configurator applies specifically to data indexed by the record combined
59+
/// with the token, often used for efficient record deletion or secondary indexing.
60+
/// </remarks>
61+
public Action<
62+
ZoneTreeFactory<
63+
CompositeKeyOfRecordToken<TRecord, TToken>,
64+
byte>> FactoryConfigurator2
65+
{ get; set; }
66+
}

src/ZoneTree.FullTextSearch/SearchEngines/HashedSearchEngine.cs

+12-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
using ZoneTree.FullTextSearch.Tokenizer;
1111
using ZoneTree.FullTextSearch.Hashing;
1212
using System.Security.Cryptography;
13+
using ZoneTree.FullTextSearch.Model;
14+
using Tenray.ZoneTree.AbstractFileStream;
1315

1416
namespace ZoneTree.FullTextSearch.SearchEngines;
1517

@@ -35,6 +37,11 @@ public sealed class HashedSearchEngine<TRecord> : IDisposable
3537
/// </summary>
3638
readonly IHashCodeGenerator HashCodeGenerator;
3739

40+
/// <summary>
41+
/// The flag that describes if the instance is disposed.
42+
/// </summary>
43+
bool isDisposed;
44+
3845
/// <summary>
3946
/// Initializes a new instance of the <see cref="HashedSearchEngine{TRecord}"/> class.
4047
/// </summary>
@@ -44,21 +51,24 @@ public sealed class HashedSearchEngine<TRecord> : IDisposable
4451
/// <param name="wordTokenizer">The tokenizer used to split words. If null, a default tokenizer is used.</param>
4552
/// <param name="hashCodeGenerator">The hash code generator used to generate hash codes for the tokens. If null, a default generator is used.</param>
4653
/// <param name="blockCacheLifeTimeInMilliseconds">Defines the life time of cached blocks. Default is 1 minute.</param>
54+
/// <param name="advancedOptions">Advanced ZoneTree Options enabling customization of underlying ZoneTree instances.</param>
4755
public HashedSearchEngine(
4856
string dataPath = "data",
4957
bool useSecondaryIndex = false,
5058
IWordTokenizer wordTokenizer = null,
5159
IRefComparer<TRecord> recordComparer = null,
5260
IHashCodeGenerator hashCodeGenerator = null,
53-
long blockCacheLifeTimeInMilliseconds = 60_000)
61+
long blockCacheLifeTimeInMilliseconds = 60_000,
62+
AdvancedZoneTreeOptions<TRecord, ulong> advancedOptions = null)
5463
{
5564
HashCodeGenerator = hashCodeGenerator ?? new DefaultHashCodeGenerator();
5665
Index = new(
5766
dataPath,
5867
recordComparer,
5968
new UInt64ComparerAscending(),
6069
useSecondaryIndex,
61-
blockCacheLifeTimeInMilliseconds: blockCacheLifeTimeInMilliseconds);
70+
blockCacheLifeTimeInMilliseconds,
71+
advancedOptions);
6272
WordTokenizer =
6373
wordTokenizer ??
6474
new WordTokenizer(hashCodeGenerator: HashCodeGenerator);
@@ -413,8 +423,6 @@ public void Drop()
413423
Index.Drop();
414424
}
415425

416-
bool isDisposed;
417-
418426
/// <summary>
419427
/// Disposes the resources used by the search engine.
420428
/// </summary>

src/ZoneTree.FullTextSearch/Storage/RecordTable.cs

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Tenray.ZoneTree;
2+
using Tenray.ZoneTree.AbstractFileStream;
23

34
namespace ZoneTree.FullTextSearch;
45

@@ -34,6 +35,9 @@ public sealed class RecordTable<TRecord, TValue> : IDisposable where TRecord : u
3435
/// </summary>
3536
public bool IsDropped { get => isDropped; }
3637

38+
/// <summary>
39+
/// The flag that describes if the instance is dropped.
40+
/// </summary>
3741
bool isDropped;
3842

3943
/// <summary>
@@ -43,15 +47,17 @@ public sealed class RecordTable<TRecord, TValue> : IDisposable where TRecord : u
4347
/// <param name="factory1">Optional configuration action for the first ZoneTree factory.</param>
4448
/// <param name="factory2">Optional configuration action for the second ZoneTree factory.</param>
4549
/// <param name="blockCacheLifeTimeInMilliseconds">Defines the life time of cached blocks. Default is 1 minute.</param>
50+
/// <param name="fileStreamProvider">Optional custom file stream provider.</param>
4651
public RecordTable(
4752
string dataPath = "data",
4853
Action<ZoneTreeFactory<TRecord, TValue>> factory1 = null,
4954
Action<ZoneTreeFactory<TValue, TRecord>> factory2 = null,
50-
long blockCacheLifeTimeInMilliseconds = 60_000)
55+
long blockCacheLifeTimeInMilliseconds = 60_000,
56+
IFileStreamProvider fileStreamProvider = null)
5157
{
52-
var f1 = new ZoneTreeFactory<TRecord, TValue>()
58+
var f1 = new ZoneTreeFactory<TRecord, TValue>(fileStreamProvider)
5359
.SetDataDirectory($"{dataPath}/rectable1");
54-
var f2 = new ZoneTreeFactory<TValue, TRecord>()
60+
var f2 = new ZoneTreeFactory<TValue, TRecord>(fileStreamProvider)
5561
.SetDataDirectory($"{dataPath}/rectable2");
5662
factory1?.Invoke(f1);
5763
factory2?.Invoke(f2);

src/ZoneTree.FullTextSearch/ZoneTree.FullTextSearch.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<PrivateAssets>all</PrivateAssets>
3939
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
4040
</PackageReference>
41-
<PackageReference Include="ZoneTree" Version="1.8.4" />
41+
<PackageReference Include="ZoneTree" Version="1.8.5" />
4242
</ItemGroup>
4343

4444
<ItemGroup>

0 commit comments

Comments
 (0)