Skip to content

Commit

Permalink
Merge branch 'issues/GH-6' of https://github.com/dotJEM/json-index2 i…
Browse files Browse the repository at this point in the history
…nto issues/GH-6
  • Loading branch information
jeme committed Sep 18, 2024
2 parents e30c918 + 1f62404 commit 9d2cf5e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using DotJEM.Json.Index2.Snapshots;
using DotJEM.ObservableExtensions.InfoStreams;
using DotJEM.Web.Scheduler;
using Lucene.Net.Search;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

Expand Down Expand Up @@ -41,6 +42,8 @@ public class JsonIndexSnapshotManager : IJsonIndexSnapshotManager
{
private readonly IJsonIndex index;
private readonly ISnapshotStrategy strategy;
//TODO: This binds us to a concrete idea (even though this is an interface).
// instead it would be preferred if we could provide an abstraction for what is needed.
private readonly IWebTaskScheduler scheduler;
private readonly IInfoStream<JsonIndexSnapshotManager> infoStream = new InfoStream<JsonIndexSnapshotManager>();

Expand Down
12 changes: 11 additions & 1 deletion src/DotJEM.Json.Index2/Storage/IIndexStorageProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Lucene.Net.Store;
using System;
using System.IO;
using Lucene.Net.Store;
using Directory = Lucene.Net.Store.Directory;

namespace DotJEM.Json.Index2.Storage;

Expand Down Expand Up @@ -32,5 +35,12 @@ public SimpleFsIndexStorageProvider(string path)

public void Delete()
{
//TODO: For now. But maybe there is cases where this actually makes sense to always have.
DirectoryInfo dir = new DirectoryInfo(path);
foreach (FileInfo file in dir.EnumerateFiles())
file.Delete();

foreach (DirectoryInfo directory in dir.EnumerateDirectories())
directory.Delete(true);
}
}
7 changes: 2 additions & 5 deletions src/DotJEM.Json.Index2/Storage/IJsonIndexStorageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public Directory Directory
{
if (directory != null)
return directory;

return directory = provider.Get();
}
}
Expand All @@ -51,8 +50,8 @@ public Directory Directory
public JsonIndexStorageManager(IJsonIndex index, IIndexStorageProvider provider)
{
this.provider = provider;
this.writerManager = new Lazy<IIndexWriterManager>(()=> new IndexWriterManager(index));
this.searcherManager = new Lazy<IIndexSearcherManager>(()=> new IndexSearcherManager(WriterManager, index.Configuration.Serializer));
this.writerManager = new(()=> new IndexWriterManager(index));
this.searcherManager = new(()=> new IndexSearcherManager(WriterManager, index.Configuration.Serializer));
}

public void Unlock()
Expand Down Expand Up @@ -82,8 +81,6 @@ public void Delete()
foreach (string file in directory.ListAll())
directory.DeleteFile(file);
provider.Delete();


}
}
}

0 comments on commit 9d2cf5e

Please sign in to comment.