public async IAsyncEnumerable <SearchResult> SearchAsync(string query, [EnumeratorCancellation] CancellationToken cancellationToken) { await foreach (var result in _index.Search(query, cancellationToken).WithCancellation(cancellationToken)) { if (Guid.TryParse(result.DocumentReference, out _)) { yield return new SearchResult { DocumentReference = result.DocumentReference } } } ; }
public async Task BuilderCanIncludeTokenPositions() { Index index = await Index.Build(async builder => { builder.MetadataAllowList.Add("position"); builder.AddField("href", 3); builder.AddField("title", 2); builder.AddField("body", 1); await builder.Add(new Document { { "id", "me" }, { "href", "http://bertrandleroy.net" }, { "title", "Bertrand" }, { "body", "I am developer." } }); }); Result developer = (await index.Search("developer").ToList()).Single(); Assert.Equal(new Slice(5, 10), (Slice?)developer.MatchData.Posting["develop"]["body"]["position"].Single()); }