提交 3c5a9b62 authored 作者: Thomas Mueller's avatar Thomas Mueller

Lucene fulltext search: creating an index is now faster if the table already…

Lucene fulltext search: creating an index is now faster if the table already contains data. Thanks a lot to Angel Leon from the FrostWire Team for the patch!
上级 403d624a
......@@ -325,8 +325,9 @@ public class FullTextLucene extends FullText {
for (int i = 0; i < columnCount; i++) {
row[i] = rs.getObject(i + 1);
}
existing.fire(conn, null, row);
existing.insert(row, false);
}
existing.commitIndex();
}
private static void removeIndexFiles(Connection conn) throws SQLException {
......@@ -547,7 +548,7 @@ public class FullTextLucene extends FullText {
// update
if (hasChanged(oldRow, newRow, indexColumns)) {
delete(oldRow);
insert(newRow);
insert(newRow, true);
}
} else {
// delete
......@@ -555,7 +556,7 @@ public class FullTextLucene extends FullText {
}
} else if (newRow != null) {
// insert
insert(newRow);
insert(newRow, true);
}
}
......@@ -576,12 +577,26 @@ public class FullTextLucene extends FullText {
// ignore
}
public void commitIndex() throws SQLException {
try {
indexAccess.writer.commit();
// recreate Searcher with the IndexWriter's reader.
indexAccess.searcher.close();
indexAccess.reader.close();
IndexReader reader = indexAccess.writer.getReader();
indexAccess.reader = reader;
indexAccess.searcher = new IndexSearcher(reader);
} catch (IOException e) {
throw convertException(e);
}
}
/**
* Add a row to the index.
*
* @param row the row
*/
protected void insert(Object[] row) throws SQLException {
protected void insert(Object[] row, boolean commitIndex) throws SQLException {
/*## LUCENE2 ##
String query = getQuery(row);
Document doc = new Document();
......@@ -645,6 +660,7 @@ public class FullTextLucene extends FullText {
Field.Index.ANALYZED));
try {
indexAccess.writer.addDocument(doc);
if (commitIndex) {
indexAccess.writer.commit();
// recreate Searcher with the IndexWriter's reader.
indexAccess.searcher.close();
......@@ -652,6 +668,7 @@ public class FullTextLucene extends FullText {
IndexReader reader = indexAccess.writer.getReader();
indexAccess.reader = reader;
indexAccess.searcher = new IndexSearcher(reader);
}
} catch (IOException e) {
throw convertException(e);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论