我有一个桌面应用程序,它使用 lucene 3.6.2 库来搜索 java derby 数据库中的多个字段。当输入一个词进行搜索时,lucene 系统会返回该词的匹配项。另一方面,当我输入一个不是完整单词而是一个较大单词的字符串时,lucene 不会返回与该字符串匹配的内容。
例如:“national”返回可用的匹配项
但是字符串“natio”不返回任何结果。
我希望能够输入一个字符串
"natio" 然后 lucene 将返回所有 "natio*" 作为匹配结果。
下面是应用程序的代码片段。
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);