Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Search fuction in JSP

 
Pan Niko
Ranch Hand
Posts: 86
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, i have to build a search fuction in my website. In main page(JSP) i have a text field and a submit button. When button clicked, user should transfer to goods list (JSP) where all my goods retrieved from store(XML). I have stuck at the point where only goods with name similar to the keyword should be displyed. (ex. If user insert "to" in main page, goods list page should present "Tomatoes" and "Toaster" or if insert "apples" only "Apples")

Any help???
Thank you
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is the data stored? If it's in a DB, then SQL covers this case (read up on the LIKE operator and the LOWERCASE/UPPERCASE functions). If the data is in files, then using a library like Lucene may help.
 
Pan Niko
Ranch Hand
Posts: 86
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As i said, i have a xml file and stored all my datas there. Sorry but im a lil bit fresh, what is Lucene library
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see, I misinterpreted the mention of XML. You can use one of the XML APIs (maybe SAX or DOM; and possibly XPath) to iterate through all goods and perform some appropriate string operations to do the comparison. Something like nameOfGood.toLowerCase().indexOf(userInput.toLowerCase()) != -1.

As to Lucene, a web search will find its home page (which has extensive documentation) quickly; it's not like that's a common word.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic