Making a search engine in Unity

Hello,

I’ve been working for some time on an app that contains a lot of written text. This information was seperated into over 200 categories with each one having at least 3 blocks of text.
I would like to give the user the possibility to search for some keywords to find one of the text blocks since that is much easier to do than navigate over that many categories.

I have all those text blocks saved in a string[] element.

Here is an example:

string[0] = "This is the tutorial. Press A to jump and B to attack."
string[1] = "This area is known as the city of Dhismir, do not enter it without preparations."
string[2] = "This is the legendary sword of Thasburg, it doesn't belong to you. Let me tell you its story"

I could easily make a simple script that checks if the string contains the keywords, but I want my search engine to accept some errors by the user:

  1. Some words might be spelled differently by some users. The word “Thasburg” might be replaced by “Thusborg” or “thusburg”. This is the main problem since my app is full of words that are often spelled differently depending on the user.
  2. Some small words like “the” or “to” might be omitted but I don’t know how much I can omit while keeping the search accurate enough.

I’ve done some research but I couldn’t find a simple search engine that is integrated in unity.
I would like my app to be offline so I can’t use web based searches. I have found only a few tutorials about Linq in unity so I don’t really understand how to make a search engine with it. I have found an adaptation of Lucene for Unity on github but I’ve never used Lucene before and the unity version has got no example and almost no documentation.

If someone knows a working example or tutorial with unity that would be really nice. I would also appreciate some ideas about the functions that I can use to search the strings and on how to account for the user errors please.

Have anyone found anything about this please ?,Have anyone found something about this please ?

Try something like that:

  1. You need an InputField for start.

  2. Create a C# script on that InputField.

  3. Inside the Update of that code you check:

for (i = 0; i < yourTextsArray.Length; i++) { if (yourTextsArray*.Contains(yourInputField.text))* *{* *// add it to some List<string> itemsList }* *}* *// also note that it should be better for you to make that string[] of yours a* *// public static string[].* *//And before the part above you write something like:* *if (yourInputField.onValueChanged())* *{* *// reset the search -> itemsList = new List<string>(), i=0;* *// so when the user type another letter it resets the search.* *// you should also take a deeper look at InputField.onValueChanged().* *// Also note that: if you use TMP_InputField, the function is onValidateInput().* *}* *}*
This part is up to you how you want to show the results.
Also note that this technique is for real-time search, if you think this is too much for you or your project, and you want to make a “google search style”, so there the user needs to press enter to search, all you gotta do is to put that for loop in a function and call it when the user hits enter and you send to it the youInputField.text as the argument and then you don’t need that part when you reset the search.

There are a few ways to make the search faster, but first let’s see if you handle all of this and that it works for you.
Keep me updated on the subject.