0

I have a question, I have a table with the following attributes  

pe_documento
pe_nombres      (given names)
pe_apellido_p   (father's surname)
pe_apellido_m   (mother's surname)

And I want to do a search from an input of a name or document number   I'm using Primefaces and Hibernate and database mysql This search must support such matches:

in the input:

Martín  

result:

Martin
martíN

in the input:

Donofrio

result:

D’onofrio
donofrio

in the input:

Juan (pe_nombres) Perez (pe_apellido_p or pe_apellido_m)

result:

Juan Antonio Mariscal Peres
Juan Ruperto Péres

As a temporary solution I did the following.

 StringTokenizer st = new StringTokenizer(posNombre);
 List<String> busqueda = new ArrayList<String>();
            while (st.hasMoreTokens()) { // este ciclo es para comprobar cuando
                                            // se
                                            // acaba de procesar tu cadena
                String palabra = st.nextToken();// esto lee la palabra siguiente
                                                // en
                                                // la cadena
                palabra = removeTildes(palabra);
                // cadenaBD = cadenaBD.replaceAll(" ", "");
                palabra = palabra.replaceAll("'", "");
                palabra = palabra.replaceAll("-", "");
                palabra = palabra.toLowerCase();
                busqueda.add(palabra);
            }
            List<Postulante> postulanteDB = postulanteDao.listarPostulante();
            listaCoincidenciasPostulantes = new ArrayList<Postulante>();
            String cadenaBD;

            for (Postulante p : postulanteDB) {
                cadenaBD = p.getPersona().getPeNombres() + " "
                        + p.getPersona().getPeApellidoP() + " "
                        + p.getPersona().getPeApellidoM();
                cadenaBD = removeTildes(cadenaBD);
                cadenaBD = cadenaBD.replaceAll(" ", "");
                cadenaBD = cadenaBD.replaceAll("'", "");
                cadenaBD = cadenaBD.replaceAll("-", "");
                cadenaBD = cadenaBD.toLowerCase();
                int contador = 0;
                int tamanio = busqueda.size();
                for (String b : busqueda) {
                    if (p.getPersona().getPeDocumento().indexOf(b) != -1) {                
                        listaCoincidenciasPostulantes.add(p);
                        break;
                    } else {
                        if (cadenaBD.indexOf(b) != -1) {
                            contador++;
                            if (tamanio == contador) {
                                listaCoincidenciasPostulantes.add(p);
                                break;
                            }
                        }
                    }
                }
            }  

I wonder if this search is optimal, thank you.

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
Zerart
  • 11
  • 2
  • 1
    I don't know if it will be of any help to you, but your question made me think of this question: http://stackoverflow.com/questions/3322152/java-getting-rid-of-accents-and-converting-them-to-regular-letters/ – David Conrad Sep 08 '14 at 23:46
  • Something similar but I do not think it's the right way to search the database. Since I bring data from the database and then concatenate and replacement the registers one by one. – Zerart Sep 09 '14 at 01:04

0 Answers0