|
@@ -113,11 +113,14 @@ internal class WarcIndexManager : IAssemblyInjectSingleton, IAssemblyInjectSyncS
|
|
|
private FileDescriptor? _currentFileDescriptor;
|
|
|
private float? _currentProgress;
|
|
|
|
|
|
+ private readonly SortedList<string, WarcIndexEntry> _indexedEntries = new();
|
|
|
+
|
|
|
public WarcIndexManager(IEventBus eventBus)
|
|
|
{
|
|
|
_eventBus = eventBus;
|
|
|
_eventBus.Subscript<WarcIndexerLoadRequestEvent>(obj => _ = LoadIndexAsync(obj.FileDescriptor));
|
|
|
_eventBus.Subscript<WarcIndexerStatusRequestEvent>(_ => PublishStatus());
|
|
|
+ _eventBus.Subscript<WarcIndexerQueryRequestEvent>(DoQuery);
|
|
|
}
|
|
|
|
|
|
private void PublishStatus() => _eventBus.Publish(new WarcIndexerStatusEvent(_isWorking, _queue.Reader.Count, _currentFileDescriptor, _currentProgress));
|
|
@@ -144,7 +147,14 @@ internal class WarcIndexManager : IAssemblyInjectSingleton, IAssemblyInjectSyncS
|
|
|
var (url, type) = indexContent.Urls[i];
|
|
|
batch.Add(new WarcIndexEntry(fd, indexContent.Offsets[i], type, url));
|
|
|
}
|
|
|
- _eventBus.Publish(new WarcIndexerLoadedEvent(batch));
|
|
|
+
|
|
|
+ lock (_indexedEntries)
|
|
|
+ {
|
|
|
+ foreach (var item in batch)
|
|
|
+ {
|
|
|
+ _indexedEntries.Add(item.Url, item);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
if (indexContent.Offsets.Last() + indexContent.LastEntrySize == len)
|
|
|
{
|
|
@@ -155,6 +165,18 @@ internal class WarcIndexManager : IAssemblyInjectSingleton, IAssemblyInjectSyncS
|
|
|
} while (true);
|
|
|
}
|
|
|
|
|
|
+ private void DoQuery(WarcIndexerQueryRequestEvent obj)
|
|
|
+ {
|
|
|
+ lock (_indexedEntries)
|
|
|
+ {
|
|
|
+ IEnumerable<WarcIndexEntry> source = _indexedEntries.Values;
|
|
|
+ if (obj.Filter != null) source = source.Where(obj.Filter);
|
|
|
+ var resultSet = source.Skip(obj.PageSize * (obj.PageNumber - 1)).Take(obj.PageSize).ToArray();
|
|
|
+ var result = new WarcIndexerQueryResultEvent(obj.EventId, resultSet, _indexedEntries.Count);
|
|
|
+ _eventBus.Publish(result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void Start()
|
|
|
{
|
|
|
Task.Run(async () =>
|
|
@@ -239,11 +261,4 @@ internal class WarcIndexManager : IAssemblyInjectSingleton, IAssemblyInjectSyncS
|
|
|
}
|
|
|
|
|
|
public void Stop() => _cancellationTokenSource.Cancel();
|
|
|
-
|
|
|
- public enum IndexingState
|
|
|
- {
|
|
|
- NotIndexed,
|
|
|
- PartIndexed,
|
|
|
- CompletelyIndexed
|
|
|
- }
|
|
|
}
|