Fuse.NET
Fuse.NET copied to clipboard
Not working
I tried running the example on the readme but it is returning all the items in the list. All the score are the same " 1.0000001E-06"
I changed the search pattern value and still got the same output constantly.

public struct Book
{
public string title;
public string author;
}
static void Main(string[] args)
{
try
{
var input = new List<Book>();
input.Add(new Book
{
title = "The Code of The Wooster",
author = "Bob James"
});
input.Add(new Book
{
title = "The Wooster Code",
author = "Rick Martin"
});
input.Add(new Book
{
title = "The Code",
author = "Jimmy Charles"
});
input.Add(new Book
{
title = "Old Man's War",
author = "John Scalzi"
});
input.Add(new Book
{
title = "The Lock Artist",
author = "Steve Hamilton"
});
var opt = new FuseOptions();
opt.includeMatches = true;
opt.includeScore = true;
// opt.getFn = (source, path) =>
// {
// Console.WriteLine(source);
// return "Halmiton";
// if (source != null)
// {
// return source.GetType().GetProperty(path)?.GetValue(source, null) ?? source;
// }
//
// return source;
// };
// Here we search through a list of `Book` types but you could search through just a list of strings.
var fuse = new Fuse<Book>(input, opt);
fuse.AddKey("title");
fuse.AddKey("author");
var output = fuse.Search("charles");
output.ForEach((a) =>
{
Console.WriteLine(a.item.title + ": " + a.item.author);
Console.WriteLine("Score: " + a.score);
if (a.matches != null)
{
a.matches.ForEach((b) =>
{
Console.WriteLine("{Match}");
Console.WriteLine(b.key + ": " + b.value + " (Indicies: " + b.indicies.Count + ")");
});
}
Console.WriteLine("******************************************");
Console.WriteLine();
});
}
catch (Exception e)
{
Console.WriteLine(e);
Console.ReadLine();
// throw;
}
Console.ReadLine();
}