Skip to content

Commit

Permalink
minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorsten Marx committed Sep 14, 2023
1 parent 04142a5 commit ae51475
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
target/
.vscode
.vscode
nbactions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
Expand All @@ -48,6 +49,7 @@
*
* @author t.marx
*/
@Slf4j
public class LuceneIndexAdapter extends AbstractIndexAdapter<LuceneIndexConfiguration> {

LuceneIndex luceneIndex;
Expand Down Expand Up @@ -101,6 +103,7 @@ public LuceneIndex getIndex() {

@Override
public void close() throws Exception {
log.debug("close lucene index adapter");
scheduler.shutdown();
queueWorker.stop();
queueWorkerThread.interrupt();
Expand All @@ -123,8 +126,14 @@ public void open() throws IOException {
luceneIndex.open();

scheduler.scheduleWithFixedDelay(() -> {
luceneIndex.commit();
}, 1, 1, TimeUnit.SECONDS);
try {
log.debug("commit index");
luceneIndex.commit();
log.debug("commited");
} catch (Exception e) {
log.error("", e);
}
}, 1, 10, TimeUnit.SECONDS);

queueWorker = new PausableThread(true) {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import lombok.extern.slf4j.Slf4j;
import org.apache.lucene.document.Document;
import org.apache.lucene.facet.FacetsConfig;
import org.apache.lucene.index.IndexWriter;
Expand All @@ -40,6 +41,7 @@
*
* @author t.marx
*/
@Slf4j
public class LuceneIndex {

private IndexWriter writer;
Expand Down Expand Up @@ -87,10 +89,9 @@ public void deleteDocuments (Query query) throws IOException {
public void commit() {
try {
writer.commit();
writer.maybeMerge();
searcherManager.maybeRefresh();
} catch (IOException ex) {
Logger.getLogger(LuceneIndex.class.getName()).log(Level.SEVERE, null, ex);
log.error("", ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

import com.github.thmarx.mongo.search.adapter.IndexAdapter;
import com.github.thmarx.mongo.search.index.commands.Command;
import com.github.thmarx.mongo.search.index.indexer.Initializer;
import com.github.thmarx.mongo.search.index.indexer.Updater;
import com.github.thmarx.mongo.trigger.CollectionTrigger;
import com.github.thmarx.mongo.trigger.DatabaseTrigger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ public void execute(final IndexAdapter indexAdapter, final MongoDatabase databas
log.error("error clearing collection", e);
}
log.debug("index collection " + collection);
log.debug(dbCol.countDocuments() + " documents to index");
dbCol.find(Filters.empty()).forEach((document) -> {
try {
indexAdapter.indexDocument(database.getName(), collection, document);
} catch (IOException e) {
log.error("error indexing document", e);
}
});

log.debug("collection indexed");
}
});

Expand Down

0 comments on commit ae51475

Please sign in to comment.