I am trying to create a search menu that can search both headings and subheadings. For example, if you search “sword” then the sword heading would show up, and the list of all the swords underneath it as subheadings. If you search armor then all the armor would show up underneath. Also, if you search “katana” for example then you see the subheading “katana” with the heading “sword” above it.
What you want was sometimes known as a combo-box, today its behavior is refined to a widget known as a “search box”. (The design was popularized by Apple.)
Essentially, it has two parts to the solution: 1) the input field where the user is free to type, 2) a list that can instantly shorten (or highlight) the selected items.
The second element is the actual workhorse of the system, and the logic controller above the two should employ a search algorithm to quickly find the elements for display. Whereas the input field is just that, a basic input field, although you might want to upgrade it as well, for example if you want it to auto-complete the input text (i.e. you start typing “kat” and “katana” is already suggested).
Now there are millions of ways to make the actual visual list. If you just want a pop up display of items that come up as you type, then it’s not that hard to do because it can simply spawn some UI prefabs that are then fed with the data that came from the search algorithm.
There are several ways you could do the search algorithm. In your specification you stated you would like a single result (that’s my understanding), but it should conserve the hierarchy of the original data set (with headings and subheadings).
In general, an as-you-type search algorithm should be incredibly fast. Because the data set is typically static (for this use case), then insertion/deletion doesn’t matter that much, but when looking up entries the user shouldn’t perceive or feel any lag while typing (and this response shouldn’t grow with data size). Depending on the size of your data set, you might want to look into dictionaries, tries (something I’d personally use), and asynchronous programming (more as a concept; it could be as well just event-driven).
To conserve the hierarchy, your original data set should be defined in such a way so that the hierarchical relationships are known beforehand. Then you need to have a way of flattening this structure before searching (the most logical way would be to have this data already flat, with additional hierarchical relationships adjoined to each item). Then after you get your search result, you analyze the relationships and include the relevant entries in your result.
Thanks, man. I do feel like this is way over my head. I know how to make a simple search engine from watching a youtube video with only the items showing up. But i can’t figure out the headings. Any chance there’s more documentation on this?
Well if that part is bothering you, then it is way over your head. It’s too much text for me to try to break it for you, but on the other hand it’s too trivial to even bother, and I really don’t want to sound mean, but hierarchical lists are textbook problems, not really something you need a forum for, unless you want to see a specific implementation in Unity, which is quite honestly a lot of work just to illustrate, due to serialization and everything. I tried yesterday to build a little mockup, but after about half an hour of work, I decided against it. I’m sorry that I don’t have as much time as I used to have last year. But then again, I do like having a regular job that pays me well, so there’s that. Commerce does run opposite to education it seems and they say ‘those who can’t, teach’.
You can try tackling this problem for yourself, and if you have a specific question, I’ll be glad to help.