Skip to content

tommysor/SimplifiedSearch

Repository files navigation

License: MIT Quality Gate Status

SimplifiedSearch

Simple way to add ranked fuzzy matching search.
For when you have up to a few thousand products, locations or similar and want to add a search that most users will see as smart, with minimal work.

Intended use case

Searching through lists of short phrases like country names or the subject line in emails.
Data in databases must first be loaded into memory in order to be searched.

.NET support

Tested with: .NETFramework4.8, net8.0

Quickstart

Install

Nuget
> dotnet add package SimplifiedSearch

Code

Use extension method .SimplifiedSearchAsync(searchTerm, propertyToSearchLambda).
propertyToSearchLambda is optional. When missing, all properties will be searched (or the value, if the value is string, Enum, int, etc).

using SimplifiedSearch;

IList<Country> countries = GetListOfCountries();
IList<Country> matches = await countries.SimplifiedSearchAsync("thaiwan", x => x.CountryName);
foreach (var country in matches)
{
    Console.WriteLine(country.CountryName);
}
// output:
// Taiwan
// Thailand

Customization

New in version 1.3.0.

// Create searcher with custom selection of final result.
public class MyCustomSelector : SimplifiedSearch.SearchPipelines.ResultSelectors.IResultSelector
{
    public IList<T> Run<T>(IList<SimilarityRankItem<T>> rankedList) => ...
}
SimplifiedSearchFactory.Instance.Add("MyCustomSearcher",
    c => c.ResultSelector = new MyCustomSelector());
var simplifiedSearch = SimplifiedSearchFactory.Instance.Create("MyCustomSearcher");
var searchResults = await simplifiedSearch.SimplifiedSearchAsync(list, "searchTerm");

// Override the default searcher, also used by the extension methods.
SimplifiedSearchFactory.Instance.Add(SimplifiedSearchFactory.DefaultName,
    c => c.ResultSelector = new MyCustomSelector());
var searchResults = await list.SimplifiedSearchAsync("searchTerm");

Acknowledgements

Inspiration

Lucenenet is the main inspiration for SimplifiedSearch.
SimplifiedSearch was originally started with the goal of delivering similar results to a spesific setup of Lucene analyzer and query.

Enablers

Provides the distance calculation needed for fuzzy search.
License: MIT https://github.com/DanHarltey/Fastenshtein/blob/master/LICENSE.

Provides the ascii folding needed to match accented characters to their ascii approximate equivalent (â, å, à, á, ä ≈ a).
License: MIT https://github.com/thecoderok/Unidecode.NET/blob/master/LICENSE.

Contributing

Bug reports, feature requests and pull requests are welcome.

  • The focus of the project is in making the simple use case work well, not on supporting many special cases.
  • For significant changes, make an issue for discussion before putting significant work into the change.
  • Follow the established code format.