File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

search algorithm help

 
Frank king
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a database includes list of book names and price.

when key in a book name, system will return its selling price.

however, if user keyed in name wrongly, for exmaple. "risl management" instead of real name "risk management", my system won't know how to handle this type of problem.

another problem is : if user doesn't key in the full name of the book, how the system could know which book the user is looking fot?

any search algorithm can solve this kinds of problems??

thanks, waiting for your help asap.
 
Arnaud Burlet
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !

Well, about spelling mistakes correction, that's not an easy thing to do, you may be interrested by a course I followed 2 years ago :
spell checking You'll find an easy algorithm in there...

and about the 2nd point, that's not too hard, create a list of all the words contained in book titles, and associate them full book names containing the word in question. This is certainly not the best idea, but just a starting point...

Arnaud
 
Ben Wood
Ranch Hand
Posts: 342
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frank,

What do you mean by database? For example, if you are talking about connecting to relational database using JDBC you can experiment with LIKE in your SQL queries. If the system doesn't find an exact match you can do some other queries after splitting the query up...

e.g. "Risl Management", also search on "Risl" and "Management"

Query on whole string returns no results, so split it up into individual words (using StringTokenizer maybe ?) and try each one, then output something like "sorry, the title you searched for was not found...here are some possible matches"

again, not perfect, but quite easy to implement
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's an alternative approach using an in-memory index instead of database queries: Ternary Search Tree. The demo applet matches a list of words as you type leading characters, so as you type "RIS" you see "RISK" fairly near the top.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic