I want to search the contents in a forum especially forum questions
for example:
searchString = "Hibernate Session Configuration";
will give corresponding details in the Forum Questions
but all the words need not to be consecutive in the forum content and so i am storing the searching string in a java.util.Set
containing each word
String[] searchArray= searchString.toLowerCase().split(" ");
Set<String> searchSet = new HashSet<String>();
// searchSet contains words of searchString
for(String string : searchArray){
searchSet.add(string);
}
I written hibernate query as,
DetachedCriteria detachedCriteria = DetachedCriteria.forClass(ForumQuestion.class);
for(String searchUnitString : searchSet)
{
detachedCriteria= detachedCriteria.add(Restrictions.disjunction().add(Restrictions.ilike("forumQuestion", "%"+searchUnitString+"%")));
}
return template.findByCriteria(detachedCriteria);
But this query is not working properly.. it just take the last Restrictions
ignoring the previous Restrictions
!
In this example, it will consider only for '%Configuration%' but my need is '%Hibernate%' or '%Session%' or '%Configuratoin%' together
Note: if I query for each word, then database hit will be high