Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about indexing objects  RSS feed

 
George Lin
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,


I want to use indexing technology to speed up searching operation of my application. I have found that Java built-in type Hashtable can only have one key for each object. But my requirement is that an object can have multiple keys for an object. For example, the objects may be arranged in the following model,

Object (key1, key2, value)

and the related instances maybe

John ("male", "single", <personal information of John> )
Smith ("male", "married", <personal information of Smith> )

When given key1 (or key2, or key1 and key2 altogether), I want to find out matched objects. For example, when given "male", John and Smith are both matched. When given "single", only John is matched. When given "female" and "single", no records are matched.


Thanks in advance,
George

[ March 21, 2005: Message edited by: George Lin ]
[ March 21, 2005: Message edited by: George Lin ]
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've never heard the phrase "indexing technology" before, but I think I have a pretty good idea of what you are trying to do here. I can think of several ways to accomplish it. Probably the simplest approach would be to create multiple parallel Maps, one for each key you wish to use.

Another possibility is to create a custom class to use as the key. You can then obtain the keys with a call to Map.keySet() and iterate over them to find the matches for a particular query. For more details about using Map and other classes in the Collections framework, you should look at the Collections trail in Sun's Java Tutorial.

You may also want to look into storing your data in a relational database. Performing such searches with SQL is nearly trivial, once you know the syntax. You can also use SQL and access other database services within a Java program using JDBC. For an introduction to JDBC, check out the JDBC trail.

I hope this helps get you thinking about ways to solve your problem. Please come back with more questions as you continue working on this.

Layne
 
George Lin
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Layne,


Originally posted by Layne Lund:

Another possibility is to create a custom class to use as the key. You can then obtain the keys with a call to Map.keySet() and iterate over them to find the matches for a particular query. For more details about using Map and other classes in the Collections framework, you should look at the Collections trail in Sun's Java Tutorial.


Your ideas are great! I am very interested in the creating a custom class as the key solution in your reply. I am wondering how to design the solution to be flexible enough to be reusable in other similar applications. Could you help?


regards,
George
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!