lucene问题

索引已经建立,但就是检索不到数据。hits.length()一直为0

public Hits search(String queryString) {
Hits hits = null;

try {

File file = new File(indexPath);

Directory directory = FSDirectory.getDirectory(file);

IndexSearcher searcher = new IndexSearcher(directory);

String[] fields = { "CUSTOMERID", "SHIPNAME", "SHIPCITY",
"SHIPCOUNTRY" };
MultiFieldQueryParser mQueryPaser = new MultiFieldQueryParser(
fields, getAnalyzer());

Query query = mQueryPaser.parse(queryString);

hits = searcher.search(query);

} catch (Exception e) {
//do something here
}

return hits;
}

public void doIndex(String sql) {

try {

IndexWriter writer = new IndexWriter(indexPath, getAnalyzer(), true);

ResultSet rs = luceneDB.getResult(sql);

while (rs.next()) {
Document doc = new Document();
doc.add(new Field("CUSTOMERID", rs.getString("CUSTOMERID"),
Field.Store.YES, Field.Index.TOKENIZED));
doc.add(new Field("SHIPNAME", rs.getString("SHIPNAME"),
Field.Store.YES, Field.Index.TOKENIZED));
doc.add(new Field("SHIPCITY", rs.getString("SHIPCITY"),
Field.Store.YES, Field.Index.TOKENIZED));
doc.add(new Field("SHIPCOUNTRY", rs.getString("SHIPCOUNTRY"),
Field.Store.YES, Field.Index.TOKENIZED));

writer.addDocument(doc);
}
writer.optimize();
writer.close();

} catch (CorruptIndexException ce) {
System.out.println(ce.getMessage());
} catch (IOException ie) {
System.out.println(ie.getMessage());
} catch (SQLException se) {
System.out.println(se.getMessage());
}
}


public Analyzer getAnalyzer() {
return new StandardAnalyzer();
}

你可能感兴趣的:(sql,IE,Lucene)