Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Grigory · Jul 04, 2013 at 09:27 AM · propertiessearchautocomplete

Research within objects by property

Hello,

I have different objects on a level, each of them having custom properties like "firstname","job","sex". I would like to create a search bar, so if a player types something in it, it would check for all objects' properties to see if there are some matches and to return matching objects.

For exemple, typing "Ma" in the research should return names of every object that has "Male" as sex, or "Marketer" as job or "Mary" as name, etc.

I believe that for the research I just have to do a loop that checks values of each object properties and, if there's a match, returs the object's name. But how could I workaround approximate matches like "Ma" -> "Mary" and "Mory" -> "Mary"?

Comment
Add comment · Show 1
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 Grigory · Jul 04, 2013 at 12:35 PM 0
Share

I guess I will use tags to tag every concerned object as "searchable", then each time a user types a letter in the searchbar, I will do a loop that looks for those properties' values to compare them to the user typed keyword.

Inside the lopp, I will have to perform an "Affinity check" function that would return true for searches like "$$anonymous$$a = $$anonymous$$ary".

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by jovino · Jul 04, 2013 at 01:02 PM

The first case "Ma" -> "Mary" can be found with a simple string.Contains or Regex.Match

The second, "Mory" -> "Mary", needs something more complex. Please, look the first answer here, it should put you on the road.

If you have too may objetcs to search, I don't recommend you relying only on reflection for make the property search, I think is best to have some type of cache for the values of the properties which will be searched.

You can, for example, store the values in a Dictionary<string, object> in the property setter of the involved classes.

Comment
Add comment · Show 5 · 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 Grigory · Jul 04, 2013 at 01:18 PM 0
Share

Thank you for the first case, Thank you for the second yet I just had read few articles about Levenshtein so I was already on the good way.

Concerning the optimization: I don't kinow if I understood well, but do you suggest to create a side "container" that should store a kind of database like "Object - Property1 value - property 2 value, etc"?

Thank you much

avatar image jovino · Jul 04, 2013 at 02:12 PM 0
Share

I was thinking something like this, but your idea of a static container it's a good one for me too:

 using System.Collections.Generic;
 
 interface ISearchable
 {
     object SearchValue(object valueToSearch);    
 }
 
 public class SearchableObject : ISearchable
 {
     private Dictionary<string,object> properties;    
     public SearchableObject ()
     {
         properties = new  Dictionary<string,object>();
     }
     
     public object SearchValue (object valueToSearch)
     {
         if(valueToSearch as string == null)
             return null;
          foreach(object propValue in properties.Values)
         {
             if(propValue.ToString().Contains(valueToSearch as string))
                 return propValue;
         }
         return null;
     }
     protected void SetValue(string propName, object propValue)
     {
         if(this.properties.Contains$$anonymous$$ey(propName))
             this.properties[propName] = propValue;
         else
             this.properties.Add(propName, propValue);    
     }
 }
 
 public class Car : SearchableObject
 {
     private float engine;
     public float Engine
     {
         get { return engine; }
         set
         {
             SetValue("engine", value);
             engine = value;
         }
     }    
 }
avatar image Grigory · Jul 04, 2013 at 02:18 PM 0
Share

Thank you much, it will go really fast for me from now.

avatar image Grigory · Jul 11, 2013 at 09:29 AM 0
Share

Still don't know how to thank you enough, I just reached the supersonic speed in my project's development :)

avatar image jovino · Jul 11, 2013 at 12:39 PM 0
Share

Enough to know it was helpful to you. You are welcome :)

avatar image
0

Answer by Styxxx · Jul 04, 2013 at 02:40 PM

with regard to the "mory->mary" part, take a look at SoundEx (the instructions will be available online). Soundex is an algorithm that takes a string and removes the vowels and doubled letters, and converts the remaining letters into a special string which you store in a separate property to the original string.

Then, when the user searches, you do the same thing to his search term and compare that to the stored soundex strings as well as doing your standard .contains check on the real strings. e.g. "Mary" and "Mory" both soundex to "M600"

It's a well established system, and there are standard c# functions for doing it, I don't know if they're available in unity or whether you might have to write your own (its not hard)

Comment
Add comment · 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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 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

Related Questions

Restricting input field to predefined words 1 Answer

How to expose script properties in C# ? 3 Answers

What built-in shader properties are there? 0 Answers

Making a paper like object on Unity. 2 Answers

Photon JoinRandomRoom customGameProperties? Load proper scene 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