Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package interfaz; import java.io.IOException; import org.apache.lucene.document.Document; import org.apache.lucene.facet.FacetResult; import org.apache.lucene.facet.Facets; import org.apache.lucene.facet.FacetsCollector; import org.apache.lucene.facet.taxonomy.TaxonomyReader; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.TopDocs; /** * * @author Javi */ public class resultados extends javax.swing.JFrame { private TopDocs td; private IndexSearcher is; private FacetsCollector fc; private TaxonomyReader tr; /** * Creates new form resultados */ public resultados() { initComponents(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { buttonGroup1 = new javax.swing.ButtonGroup(); buttonGroup2 = new javax.swing.ButtonGroup(); resultado = new javax.swing.JScrollPane(); resultados = new javax.swing.JTextArea(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); resultados.setColumns(20); resultados.setRows(5); resultado.setViewportView(resultados); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout .createSequentialGroup().addGap(20, 20, 20).addComponent(resultado, javax.swing.GroupLayout.PREFERRED_SIZE, 911, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(33, Short.MAX_VALUE))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout .createSequentialGroup().addGap(19, 19, 19).addComponent(resultado, javax.swing.GroupLayout.PREFERRED_SIZE, 507, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(32, Short.MAX_VALUE))); pack(); }// </editor-fold>//GEN-END:initComponents public void setTD_and_searcher(TopDocs td, IndexSearcher is) throws IOException { this.td = td; this.is = is; String result = ""; for (ScoreDoc sd : td.scoreDocs) { Document d = is.doc(sd.doc); result += "Titulo: " + d.get("Title") + "\n\tAutor: " + d.get("Authors") + "\n\tAo: " + d.get("Year") + "\n"; //System.out.println(sd.score+"year: "+d.get("Year")+" "+"Libro: "+d.get("Title")); } if (result.equals("")) result = "No hay resultados"; resultados.setText(result); } public void setTD_searcher_taxoReader_facetsCollector(TopDocs td, IndexSearcher is, TaxonomyReader tr, FacetsCollector fc) throws IOException { this.td = td; this.is = is; this.tr = tr; this.fc = fc; String result = ""; for (ScoreDoc sd : td.scoreDocs) { Document d = is.doc(sd.doc); //int score=ScoreDoc.score; result += "Titulo: " + d.get("Title") + "\n\tAutor: " + d.get("Authors") + "\n\tAo: " + d.get("Year") + "\n"; //System.out.println(sd.score+"year: "+d.get("Year")+" "+"Libro: "+d.get("Title")); } if (result.equals("")) result = "No hay resultados"; resultados.setText(result); /*String[] categorias = {"Authors", "Author keywords", "Index keywords"}; FacetResult[] dimensiones = new FacetResult[3]; FacetsCollector[] fcs = {new FacetsCollector(), new FacetsCollector(), new FacetsCollector(), new FacetsCollector()}; TopDocs[] tds = {null, null, null, null}; Facets[] facets = {null, null, null, null};*/ } /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(resultados.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(resultados.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(resultados.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(resultados.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new resultados().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.ButtonGroup buttonGroup1; private javax.swing.ButtonGroup buttonGroup2; private javax.swing.JScrollPane resultado; private javax.swing.JTextArea resultados; // End of variables declaration//GEN-END:variables }