PreDashGames

Powerful assets to help you out in your projects, before you make the jump!

Getting Started

Thanks for using Search Lib. The goal of this document is to get you up and running as fast as possible. One of the primary goals for Search Lib is that it takes no time to get up and running.

Terms

A Basic Setup

To start you’ll need to decide on an IDistanceMetric, ISearchMethod, and an ISearchProvider. This requires a technical overview, so for now I’ll choose for you! Get ready for this mouthful of code.

ISearchProvider provider = new EditorSearchProvider<LinearSearch<WagnerFischerDamerauLevenshtein>>();

This creates a search provider for the editor, which uses a LinearSearch with WagnerFischerDamerauLevenshtein as the distance metric. Our focus now is to get you up and running.

Next we need to make some settings.

SearchMethodSettings settings = new SearchMethodSettings() 
{
    MaxDistance = int.MaxValue, // Sets the maximum distance to be included in the search results
};

Then we need to provide our search provider with a list of options to relay to the search method. This can be any IEnumerable. If you want to tie data to your strings, you can store everything in a dictionary.

Dictionary<string, Weapon> data = new Dictionary<string, Weapon>();

And finally we need to initialize the search provider.

provider.Initialize(data, settings);

Now we can search whatever we want!

List<SearchResult> results = provider.Search("sword");

The SearchResult struct contains the string and the distance from the query string. To get back the original Weapon object we can query the dictionary.

Weapon weapon = data[results[0].Option];

And that’s it! The flow for INonBlockingSearchProvider is slightly different. Instead of returning a List we get nothing, but you instead register for a callback on the provider.

provider.OnResultsReceived += (results) => {
    // Do something with the results
};

And an example for using monobehaviours at runtime can be found in the Examples folder. The API is similar, but adapted for monobehaviours.

Contact

If you need any help feel free to reach out to predashgames@gmail.com