Comments (3)
Ok, thanks for hints, interesting stuff!
from lifti.
@Jacknq There's nothing built into the index implicitly and no current plans - it's not something I'd considered to be honest.
Off the top of my head, the most pragmatic way to do this would be with some sort of wrapper around a Dictionary
of indexes, each key being a different partition - that's probably something that could be managed outside of the framework itself in the short term.
from lifti.
Something like this (completely untested!)
using Lifti;
using Lifti.Serialization.Binary;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
public class ShardedIndex
{
private static readonly BinarySerializer<int> serializer = new BinarySerializer<int>();
private readonly Dictionary<string, FullTextIndex<int>> indexShards = new Dictionary<string, FullTextIndex<int>>();
private readonly SemaphoreSlim syncObject = new SemaphoreSlim(1);
public async Task<FullTextIndex<int>> GetIndexAsync(string partitionKey, CancellationToken cancellationToken = default)
{
if (!await syncObject.WaitAsync(TimeSpan.FromSeconds(1), cancellationToken))
{
throw new Exception("Timeout waiting for lock");
}
try
{
if (!indexShards.TryGetValue(partitionKey, out var index))
{
// Create the index for this shard
index = new FullTextIndexBuilder<int>()
// e.g. shard peristance using the partition key as the file name
.WithIndexModificationAction(async (idx) =>
{
using (var fileStream = File.OpenWrite($"{partitionKey}.dat"))
{
await serializer.SerializeAsync(idx, fileStream);
}
})
.Build();
// Deserialize initial state, if appropriate
var serializedFile = new FileInfo($"{partitionKey}.dat");
if (serializedFile.Exists)
{
using (var stream = serializedFile.OpenRead())
{
await serializer.DeserializeAsync(index, stream);
}
}
// Store the index for the next access
indexShards[partitionKey] = index;
}
return index;
}
finally
{
syncObject.Release();
}
}
}
There may be a more optimal solution - just food for thought, more than anything.
from lifti.
Related Issues (20)
- Suggestion: custom stemmers HOT 2
- Search for words with a `=` character HOT 5
- Escaped characters in LIFTI query syntax HOT 1
- Q: is possible to fetch the whole document by Id? HOT 2
- Refresh documentation HOT 20
- Split IdPool and ItemStore HOT 1
- Consider switching to using ValueTask across the library HOT 1
- Operaterrors as a text HOT 3
- Standardize terminology
- Track source object type against a document's metadata
- Add a "not contains" query operator
- v6 documentation changes
- Create a standardised way of rehydrating an index from a serializer
- Write up implementing a custom serializer
- Apply field and document filtering when collecting results from IndexNavigator HOT 1
- Add README.md to nuget package
- Execution plans
- Consider dropping support for netstandard2
- How to nest queries? HOT 2
- Sign nuget package HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lifti.