Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Apr 23, 2021 at 09:44 AM by programer786.
avatar image
0
Question by programer786 · Apr 01, 2020 at 10:01 PM · search

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.

Comment
Add comment · Show 14
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Pangamini · Apr 01, 2020 at 08:30 PM 0
Share

I don't really see how this topic is in any way related to Unity. You are asking about an algorithm that's entirely about string processing. Perhaps you'd have more luck on StackOverflow?

avatar image programer786 Pangamini · Apr 01, 2020 at 08:33 PM 0
Share

Thanks for replying I'm using unity for this project and was hoping that there is maybe a tutorial/asset/example available for unity. I was also hoping that maybe someone got Lucene to work on Unity and could tell me how he did it or knows another similiar library.

avatar image Pangamini programer786 · Apr 01, 2020 at 08:49 PM 0
Share

Is that a .net or c++ library? Edit: Yes there seems to be a .net port. In that case, get / build a DLL of the library with the correct .net version and copy it to the assets folder somewhere. It will be imported and available to your scripting

Show more comments
avatar image albasket5 · Apr 21, 2021 at 09:13 AM 0
Share

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

avatar image Pangamini albasket5 · Apr 21, 2021 at 02:39 PM 1
Share

Try googling 'string distance'

1 Reply

  • Sort: 
avatar image
0

Answer by gigos22 · Apr 21, 2021 at 03:14 PM

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[i].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.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image programer786 · Apr 21, 2021 at 10:47 PM 0
Share

Hello, I meant something that is a bit more forgiving, as mentioned in the original post:

"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."

avatar image gigos22 programer786 · Apr 22, 2021 at 07:22 AM 0
Share

Dang.. So everything I wrote was a waste uh..

Well making the search engine "forgiving" means you need to create a script that manages that forgiveness. Since it looks like you know your fair share of program$$anonymous$$g I'm just gonna give you guide lines.

In that kind of script you can break down a string and check if some letters are in it, that indicates to a desired word.

It is basically pre-programmed for a specific chunk of words.

Really it shouldn't be much if it's only a few words.

avatar image programer786 gigos22 · Apr 22, 2021 at 10:22 AM 0
Share

Yeah I found a solution using the Lucene library.

Show more comments

Follow this Question

Answers Answers and Comments

127 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

searching a text file for a player-input string 0 Answers

How can I eliminate searching for a struct corresponding to the collider returned by OnCollisionEnter() 3 Answers

How Expensive is Find function? 3 Answers

Search for the index in an array of a customised class 1 Answer

Select texture list 2021 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges