using Lifti.Querying.QueryParts;
using Lifti.Tokenization;
using System.Collections.Generic;
using System.Threading.Tasks;
private static (int, string)[] data = new[] {
(1, "This is some text and seems to some"),
(2, "This one seems to be the one containing the match"),
(3, "It seems to me that this one won't work either"),
(4, "This ought to work too"),
static async Task Main(string[] args)
var index = new FullTextIndexBuilder<int>()
foreach (var entry in data)
await index.AddAsync(entry.Item1, entry.Item2);
PrintSearchResults(index, "\"* to *\"");
PrintSearchResults(index, "\"to *\"");
PrintSearchResults(index, "\"seems to *\"");
PrintSearchResults(index, "\"seems to be\"");
PrintSearchResults(index, "\"* to %e\"");
private static void PrintSearchResults(FullTextIndex<int> index, string queryText)
Console.WriteLine("query: " + queryText);
var query = index.ParseQuery(queryText);
Console.WriteLine(query);
foreach (var result in index.Search(query).CreateMatchPhrases(x => data.First(i => i.Item1 == x).Item2))
Console.Write($"{result.SearchResult.Key} ");
Console.WriteLine($"({result.SearchResult.Score})");
foreach (var fieldPhrase in result.FieldPhrases)
Console.Write($" {fieldPhrase.FoundIn}: ");
Console.WriteLine(string.Join(", ", fieldPhrase.Phrases.Select(x => $"\"{x}\"")));