Advertisement
Guest User

buscador lucene

a guest
Oct 29th, 2012
574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. public class Buscador {
  2.  
  3.     public static void main(String[] args) throws Exception {
  4.  
  5.         File NombreDirectorio = new File("c:/Temp/indice");
  6.         Directory directorio = FSDirectory.open(NombreDirectorio);
  7.         IndexSearcher Busca = new IndexSearcher(directorio);
  8.  
  9.         String CadenaABuscar = "hola";
  10.  
  11.         Analyzer analizador = new StandardAnalyzer(Version.LUCENE_31);
  12.  
  13.         QueryParser consultaEnBruto = new QueryParser(Version.LUCENE_31,
  14.                 "contenido", analizador);
  15.  
  16.         Query consulta = consultaEnBruto.parse(CadenaABuscar);
  17.  
  18.         TopDocs resultado = Busca.search(consulta, 10);
  19.  
  20.         System.out.println("Hemos obtenido " + resultado.totalHits
  21.                 + " resultados");
  22.         ScoreDoc[] arrayResultados = resultado.scoreDocs;
  23.  
  24.         for (int i = 0; i < arrayResultados.length; i++) {
  25.             Document doc = Busca.doc(arrayResultados[i].doc);
  26.             System.out.print("puntuacion --> " + arrayResultados[i].score
  27.                     + "   ");
  28.             System.out.println(doc.get("rutaArchivo"));
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement