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