50,542
社区成员
发帖
与我相关
我的任务
分享
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class StringTest extends JFrame implements ActionListener{
private String s;
public static void main(String[] args) throws Exception {
StringTest test = new StringTest();
StringTest test1 = new StringTest("lucene");
//test.indexSearcher("lucene");
}
public StringTest(){
}
public StringTest(String s){
this.s = s;
JFrame frame = new JFrame();
frame.setSize(100, 100);
JButton button = new JButton("查询");
button.addActionListener(this);
frame.add(button);
}
public void indexSearcher(String s)throws Exception{
QueryParser paser = new QueryParser("content",new StandardAnalyzer());
Query query = paser.parse(s);
Searcher searcher = new IndexSearcher(INDEX_STORE_PATH);
Hits hit = searcher.search(query);
for(int i=0;i<hit.length();i++)
{
Document d = hit.doc(i);
String dname = d.get("path");
System.out.println(dname+" ");
}
}
public void actionPerformed(ActionEvent e) {
try {
this.indexSearcher(s);
} catch (Exception e1) {
e1.printStackTrace();
}
}
}