mikegoatly / lifti

A lightweight full text indexer for .NET
MIT License
181 stars 9 forks source link

Q: is possible to fetch the whole document by Id? #86

Closed tiago-soczek closed 9 months ago

tiago-soczek commented 9 months ago

Hello!

Is it possible to obtain the complete document by ID? When getting the results, I would like to have all the fields and values in the document, not just the ones that matched (FieldMatches).

mikegoatly commented 9 months ago

Hi @tiago-soczek!

There's nothing built in - there's a general expectation that you'll still be able to query the original source text/object that was used to construct the index.

For example, when you're extracting matched phrases from search results, you're required to pass a delegate that returns the original:

foreach (var result in await results.CreateMatchPhrasesAsync(i => books.First(x => x.BookId == i)))
{
    Console.WriteLine($"{result.SearchResult.Key} ({result.SearchResult.Score})");

    foreach (var fieldPhrase in result.FieldPhrases)
    {
        Console.Write($"  {fieldPhrase.FoundIn}: ");
        Console.WriteLine(string.Join(", ", fieldPhrase.Phrases.Select(x => $"\"{x}\"")));
    }
}

One of the objectives of indexing like this is to reduce the overall memory requirements of searching across all the items - storing the the original in memory would defeat that.

tiago-soczek commented 9 months ago

Thanks @mikegoatly, got it! I'll change my implementation here!