The attached patch is a suggestion to the H2 developer.
We decided to use the Lucene features in our project, currently
FullTextLucene.java will trigger the adding and indexing of each document
per row (indexAccess.writer.commit()), this is way too slow if you have
existing data.
This patch, instead gives a boolean parameter to the insert() method, so
that you can decide wether or not you want this indexing happening.
Once you're done, you can invoke a new method we've added called
commitIndex() [you can rename that to whatever makes more sense to you if
this name is not proper]
Basically, it doesn't make sense to trigger lucene's indexing mechanism for
each existing row, at least not in our UI driven app.
If this is not the right place to submit this patch, please let me know, or
if you know the developer it'd be great if he/she would get this email.
Cheers from the FrostWire Team.
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/h2-database/-/NYJRRpgMMGoJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/h2-database?hl=en.
--- FullTextLucene.txt 2011-11-09 12:40:41.000000000 -0500
+++ FullTextLucene2.txt 2011-11-09 12:42:05.000000000 -0500
@@ -325,8 +325,10 @@
for (int i = 0; i < columnCount; i++) {
row[i] = rs.getObject(i + 1);
}
- existing.fire(conn, null, row);
+ //existing.fire(conn, null, row);
+ existing.insert(row, false);
}
+ existing.commitIndex();
}
private static void removeIndexFiles(Connection conn) throws SQLException {
@@ -547,7 +549,7 @@
// update
if (hasChanged(oldRow, newRow, indexColumns)) {
delete(oldRow);
- insert(newRow);
+ insert(newRow, true);
}
} else {
// delete
@@ -555,7 +557,7 @@
}
} else if (newRow != null) {
// insert
- insert(newRow);
+ insert(newRow, true);
}
}
@@ -575,13 +577,27 @@
public void remove() {
// 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,13 +661,15 @@
Field.Index.ANALYZED));
try {
indexAccess.writer.addDocument(doc);
- 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);
+ if (commitIndex) {
+ 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);
}