Skip to content

Instantly share code, notes, and snippets.

Last active Apr 21, 2021
What would you like to do?
fuzzy text search with sorted results
using MongoDB.Entities;
using System.Linq;
using System.Threading.Tasks;
namespace TestApplication
public static class Program
public class Item : Entity
public FuzzyString Text { get; set; }
private static async Task Main()
await DB.InitAsync("test");
await DB.Index<Item>()
.Key(i => i.Text, KeyType.Text)
await new[] {
new Item { Text = "goggle"},
new Item { Text = "google"},
new Item { Text = "gogle"},
new Item { Text = "altavista"}
var result = await DB
.Match(Search.Fuzzy, "google")
var sortedItems = result
.SortByRelevance("google", i => i.Text)
.Select(x => x.Text.Value)
//result is: [google,goggle,gogle]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment