This is Venkat. Currently iam working on a search functionality in my project. I want to search for the data in the database. I want to search on the keywords(comma seperated data) column. I want to perform a wild card search on that data.
Ex: if the database column contains "java, j2EE, jms, javas".
If my search criteria is " j* " then above record should be retrieved. Also if my search criteria is " java? " then also above record should be retrieved.
I have gone through lucene API, but it seems to be ocean. I want to implement it ASAP. As iam developing a product it should support for any of these ( MS-SQL and Oracle ) servers.
Iam using struts1.2 Framework.
Please suggest me a simple API that can achieve my requirement.
Thanks in Advance for your time, Venkat [ August 25, 2008: Message edited by: Venkata Guru ]
Just a note, but wildcard searches can really hurt performance in a lot of database systems so be careful how much access users have to such searches. For example, many search systems set a minimum number of characters for a search to 4 to prevent too many records from being searched/returned.
I too have similar issue with wild card search. I have a textbox. So If you enter a* it should hit the database and retrieve the values which starts with 'a' using like condition. But what is my problem is when I enter a* the string which I am sending is an a* so the like condition doesn't searches for 'a' it is searching 'a*' . This is becoming problem for me. Can any one help me on this.
Well, you wouldn't use a textbox (no matter what you mean by that) to implement a wild-card search. You would use SQL to do that. And if you still don't know what the correct wild-card character is, that's in this topic too.
You can replace non-SQL wildcards into SQL wildcards using the usual String methods. It's really not hard to transform "a*" into "a%". You should think what you would want to do when you input "a%" though - should that also be a wildcard search or should that be a search for a literal "a%"? In the latter case you need to apply a bit more escaping.
Hibernate is integerated with Apache Lucene, and you can use Hibernate to do full text searches using HQL without really knowing about how Lucene works. You might want to go through the documentation.
Basically what you need to is add some annotations to you entities. When you persist the entities using Hibernate, it updates the Lucene index in the background. You can control how the data gets indexed using the annotations. TO search you need to use a special Query class that hibernate implements that allows you to search the Lucene index. This Query API is very similar to the normal Query API and returns you a List of entities. This way you don't need to learn the Lucene API, and you get the full power of inverted index implemented in Lucene. Look at the linked documentation. It has some examples.