Java Lucene 3.6.2搜索桌面应用程序
我有一个使用lucene 3.6.2库的桌面应用程序 在java derby数据库中搜索多个字段。 当输入一个单词进行搜索时,lucene系统返回 与单词匹配。另一方面,当我输入一个字符串 lucene返回的不是一个完整的单词,而是一个较大单词的一部分 与字符串不匹配 例如: “national”返回可用的匹配项 但是字符串“natio”不会返回任何结果 我希望能够输入一个字符串 “natio”则lucene将返回所有“natio*”作为匹配结果 下面是应用程序的代码片段Java Lucene 3.6.2搜索桌面应用程序,java,lucene,derby,Java,Lucene,Derby,我有一个使用lucene 3.6.2库的桌面应用程序 在java derby数据库中搜索多个字段。 当输入一个单词进行搜索时,lucene系统返回 与单词匹配。另一方面,当我输入一个字符串 lucene返回的不是一个完整的单词,而是一个较大单词的一部分 与字符串不匹配 例如: “national”返回可用的匹配项 但是字符串“natio”不会返回任何结果 我希望能够输入一个字符串 “natio”则lucene将返回所有“natio*”作为匹配结果 下面是应用程序的代码片段 this is a t
this is a the code that creates the lucene in-memory director
Directory index = new RAMDirectory();
StandardAnalyzer analyzer = new StandardAnalyzer(matchVersion);
IndexWriterConfig IWConfig = new IndexWriterConfig(Version.LUCENE_36, analyzer);
IndexWriter iw = new IndexWriter(index,IWConfig) ;
//Connection to DB
con = DriverManager.getConnection(host, uName, uPass);
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
String sql = "SELECT * FROM APP.REGISTRY";
rs = stmt.executeQuery(sql);
//creating the docuetns
rs.beforeFirst();
while(rs.next()) {
doc = new Document();
doc.add(new Field("subject",rs.getString("SUBJECT"),Field.Store.YES,Field.Index.ANALYZED));
doc.add(new Field("letter_from",rs.getString("LETTER_FROM"),Field.Store.YES,Field.Index.ANALYZED));
iw.addDocument(doc);
}
//Oen the index
IndexReader ir = IndexReader.open(index);
//create the searcher object
IndexSearcher searcher = new IndexSearcher(ir);
QueryParser queryParser = new MultiFieldQueryParser(Version.LUCENE_36,
new String[]{"subject","letter_from","remarks","office_dispatched_to"}, analyzer);
Query query = queryParser.parse(qString);
检查链接谢谢,我想我拿到了solution@faisalabdulai,您可以在此处发布解决方案,并自己接受它作为答案。在StackOverflow.com上这样做是合法的,实际上这是被鼓励的。