⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lucenesearcher.java

📁 java编写的lucene环境下的搜多引擎的源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                    .addComponent(jLabel4)                    .addComponent(jButton6)                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))        );        jList1.setModel(model1);        jScrollPane1.setViewportView(jList1);        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());        getContentPane().setLayout(layout);        layout.setHorizontalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(layout.createSequentialGroup()                .addContainerGap()                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 428, Short.MAX_VALUE)                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)                        .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)                        .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))        );        layout.setVerticalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(layout.createSequentialGroup()                .addContainerGap()                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                .addGap(18, 18, 18)                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                .addGap(18, 18, 18)                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE)                .addContainerGap())        );        pack();    }// </editor-fold>//GEN-END:initComponents    private void addMouseEvent() {        jList1.addMouseListener(new MouseAdapter() {            public void mouseClicked(MouseEvent e) {                if (e.getClickCount() == 2) {                    String str = jList1.getSelectedValue().toString();                    int index = str.indexOf("    ") + 4;                    if (index == 3) {                        return;                    } else {                        str = str.substring(index);                        try {                            Runtime.getRuntime().exec("cmd /c \"" + str + "\"");                        } catch (IOException ex) {                            System.out.println(ex);                        }                    }                                   }            }        });    }private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed// TODO add your handling code here:    model1.removeAllElements();    dataDir = jTextField1.getText();    indexDir1 = jTextField2.getText();    if (dataDir.compareTo("") == 0) {        JOptionPane.showMessageDialog(this, "请选择数据源文件夹", "错误", JOptionPane.ERROR_MESSAGE);    } else if (indexDir1.compareTo("") == 0) {        JOptionPane.showMessageDialog(this, "请选择索引文件夹", "错误", JOptionPane.ERROR_MESSAGE);    } else {        final LuceneSearcher ref = this;        new Thread() {            public void run() {                new CreateIndex(indexDir1, dataDir);                JOptionPane.showMessageDialog(ref, "索引建立完成", "提示", JOptionPane.INFORMATION_MESSAGE);            }        }.start();    }    }//GEN-LAST:event_jButton3ActionPerformedprivate void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed// TODO add your handling code here:    model1.removeAllElements();    indexDir2 = jTextField3.getText();    keyWords = jTextField4.getText();    if (indexDir2.compareTo("") == 0) {        JOptionPane.showMessageDialog(this, "请选择索引文件夹", "错误", JOptionPane.ERROR_MESSAGE);    } else if (keyWords.compareTo("") == 0) {        JOptionPane.showMessageDialog(this, "请输入搜索关键字", "错误", JOptionPane.ERROR_MESSAGE);    } else {        final LuceneSearcher ls = this;        new Thread() {            public void run() {                if (jRadioButton1.isSelected() && jRadioButton3.isSelected()) {                    new IndexSearch(indexDir2, keyWords, false, 0);                } else if (jRadioButton1.isSelected() && jRadioButton4.isSelected()) {                    new IndexSearch(indexDir2, keyWords, true, 0);                } else if (jRadioButton2.isSelected() && jRadioButton3.isSelected()) {                    new IndexSearch(indexDir2, keyWords, false, 1);                } else if (jRadioButton2.isSelected() && jRadioButton4.isSelected()) {                    new IndexSearch(indexDir2, keyWords, true, 1);                }            }        }.start();    }}//GEN-LAST:event_jButton6ActionPerformedprivate void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed// TODO add your handling code here:    try {        JFileChooser fileChooser = new JFileChooser();        fileChooser.setFileSelectionMode(fileChooser.DIRECTORIES_ONLY);        int n = fileChooser.showOpenDialog(this.getContentPane());        if (n == fileChooser.APPROVE_OPTION) {            jTextField1.setText(fileChooser.getSelectedFile().getPath());        }    } catch (Exception e) {        System.out.println(e);    }}//GEN-LAST:event_jButton1ActionPerformedprivate void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed// TODO add your handling code here:    try {        JFileChooser fileChooser = new JFileChooser();        fileChooser.setFileSelectionMode(fileChooser.DIRECTORIES_ONLY);        int n = fileChooser.showOpenDialog(this.getContentPane());        if (n == fileChooser.APPROVE_OPTION) {            jTextField2.setText(fileChooser.getSelectedFile().getPath());        }    } catch (Exception ex) {        System.out.println(ex);    }}//GEN-LAST:event_jButton2ActionPerformedprivate void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed// TODO add your handling code here:    try {        JFileChooser fileChooser = new JFileChooser();        fileChooser.setFileSelectionMode(fileChooser.DIRECTORIES_ONLY);        int n = fileChooser.showOpenDialog(this.getContentPane());        if (n == fileChooser.APPROVE_OPTION) {            jTextField3.setText(fileChooser.getSelectedFile().getPath());        }    } catch (Exception ex) {        ex.printStackTrace();    }}//GEN-LAST:event_jButton4ActionPerformed    /**     * @param args the command line arguments     */    public static void main(String args[]) {        java.awt.EventQueue.invokeLater(new Runnable() {            public void run() {                final LuceneSearcher luceneSearcher = new LuceneSearcher();                luceneSearcher.setVisible(true);                PrintStream ps = new PrintStream(new OutputStream() {                    final int LENGTH = 256;                    byte[] bb = new byte[LENGTH];                    int p = 0;                    public void write(int b) throws IOException {                                               if (b == 10 || b == 13) {                            flush();                        } else {                            bb[p++] = (byte) b;                        }                    }                    public void flush() throws IOException {                        if (p == 0) return;                        String str = new String(bb, 0, p);                        luceneSearcher.model1.addElement(str);                        int lastIndex = luceneSearcher.model1.getSize();                        Rectangle rect=luceneSearcher.jList1.getCellBounds(lastIndex-1,lastIndex-1);                        luceneSearcher.jScrollPane1.getViewport().scrollRectToVisible(rect);                         p = 0;                    }                }, true);                System.setOut(ps);            }        });    }    // Variables declaration - do not modify//GEN-BEGIN:variables    private javax.swing.ButtonGroup buttonGroup1;    private javax.swing.ButtonGroup buttonGroup2;    private javax.swing.JButton jButton1;    private javax.swing.JButton jButton2;    private javax.swing.JButton jButton3;    private javax.swing.JButton jButton4;    private javax.swing.JButton jButton6;    private javax.swing.JLabel jLabel1;    private javax.swing.JLabel jLabel2;    private javax.swing.JLabel jLabel3;    private javax.swing.JLabel jLabel4;    private javax.swing.JLabel jLabel5;    private javax.swing.JLabel jLabel6;    private javax.swing.JList jList1;    private javax.swing.JPanel jPanel1;    private javax.swing.JPanel jPanel2;    private javax.swing.JRadioButton jRadioButton1;    private javax.swing.JRadioButton jRadioButton2;    private javax.swing.JRadioButton jRadioButton3;    private javax.swing.JRadioButton jRadioButton4;    private javax.swing.JScrollPane jScrollPane1;    private javax.swing.JTextField jTextField1;    private javax.swing.JTextField jTextField2;    private javax.swing.JTextField jTextField3;    private javax.swing.JTextField jTextField4;    // End of variables declaration//GEN-END:variables}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -