title: Hibernate full text search custom order by
body: <p>We want to add custom order by to hibernate full text search,suppose we want to search the record based on location, if the location is "country,state,city</p>
  
  <p>Then we want to have the search with records in the top which are near to user</p>
  
  <p>We followed following links.</p>
  
  <p><a href="https://stackoverflow.com/questions/24033082/using-mysql-order-by-case-in-hibernate-criteria/24077763#24077763">using mysql &quot;order by case&quot; in hibernate criteria</a></p>
  
  <p>But the order by clause is not getting added when we add it to criteria object</p>
  
  <p>Sort is working only when we set to full Text Query object like below, here we can do only asc and desc, dynamic order by not.</p>
  
  <pre><code>Sort sort = new Sort( new SortField( "location", SortField.Type.STRING, false ) );
  fullTextQuery.setSort( sort );
  </code></pre>
  
  <p>It is geo location based search.</p>
  
  <p>we are storing the location value in mysql table column as "India,Karnataka,Bangalore"  suppose user from Bangalore logins we need to show the records which are from Bangalore first at the top.</p>
  
  <p>It would be helpful if we get some information regarding this, or any other way to achieve this problem.</p>
  
  <p>Thanks,
  Mohsin</p>