0

I want to create a hibernate query using hql or criteria to get all permutations of a word, for the word elepahant i want to get:

  • eliphant
  • ilephant
  • iliphant
  • elefant

at first i assumed that "%" + "elepahant" + "%" could do the work but in fact it only returns any word that starts with any letter and ends with any letter and containing elephant in-between, but i want to get all the word reseambles like the example above, so what are the possible ways to do that?

Eslam Hamdy
  • 7,126
  • 27
  • 105
  • 165

2 Answers2

0

Have a look at Hibernate Search, Lucene, Spell Checker. I don't think you can do such things with simple SQL.
http://docs.jboss.org/hibernate/search/4.3/reference/en-US/html/

Alex
  • 11,451
  • 6
  • 37
  • 52
0

A very simple solution is to use a denormalized field with the word sorted alphabetically like this:

word   sorted_word
apple  aelpp
kitty  iktty

And just compare the sorted word against that column.

Ziul
  • 883
  • 1
  • 13
  • 24