Permalink
Browse files

Improvements to Lucene service exception handling.

  • Loading branch information...
GraylinKim committed Apr 30, 2012
1 parent 785ce5c commit fd739a9b087b7d44586dca78e644eda36efd1e2a
Showing with 73 additions and 50 deletions.
  1. +73 −50 src/main/java/gov/nysenate/openleg/services/Lucene.java
@@ -39,67 +39,90 @@ public boolean process(HashMap<String, Storage.Status> changeLog, Storage storag
IndexWriter indexWriter = lucene.newIndexWriter();
for(Entry<String, Storage.Status> entry : changeLog.entrySet()) {
- logger.debug("Indexing "+entry.getValue()+": "+entry.getKey());
- String key = entry.getKey();
- String otype = key.split("/")[1];
- String oid = key.split("/")[2];
- logger.debug(otype+", "+oid);
- if( entry.getValue() == Storage.Status.DELETED ) {
- if (otype.equals("agenda")) {
- // Meetings should cleaned up by their respective entries
- lucene.deleteDocuments(otype, oid, indexWriter);
-
- } else if(otype.equals("bill")) {
- lucene.deleteDocumentsByQuery("otype:action AND billno:" + oid, indexWriter);
- lucene.deleteDocumentsByQuery("otype:vote AND billno:" + oid, indexWriter);;
- lucene.deleteDocuments(otype, oid, indexWriter);
+ try {
+ logger.debug("Indexing "+entry.getValue()+": "+entry.getKey());
+ String key = entry.getKey();
+ String otype = key.split("/")[1];
+ String oid = key.split("/")[2];
+ logger.debug(otype+", "+oid);
+ if( entry.getValue() == Storage.Status.DELETED ) {
+ if(otype.equals("bill")) {
+ lucene.deleteDocumentsByQuery("otype:action AND billno:" + oid, indexWriter);
+ lucene.deleteDocumentsByQuery("otype:vote AND billno:" + oid, indexWriter);;
+ lucene.deleteDocuments(otype, oid, indexWriter);
+
+ } else {
+ // XML sub-documents should cleaned up by their respective log entries
+ lucene.deleteDocuments(otype, oid, indexWriter);
+ }
} else {
- lucene.deleteDocuments(otype, oid, indexWriter);
- }
+ Class<? extends ILuceneObject> objType = classMap.get(otype);
+ ILuceneObject obj = (ILuceneObject) storage.get(key, objType);
+ if (otype.equals("agenda")) {
+ Agenda agenda = (Agenda)obj;
+ for( Addendum addendum : agenda.getAddendums()) {
+ addendum.setAgenda(agenda);
+ for( Meeting meeting : addendum.getMeetings() ) {
+ try {
+ meeting.setAddendums(new ArrayList<Addendum>(Arrays.asList(addendum)));
+ meeting.setModified(agenda.getModified());
+ lucene.addDocument(meeting, serializers, indexWriter);
+ } catch (Exception e) {
+ logger.error("Error indexing: "+meeting.luceneOid(), e);
+ }
+ }
+ }
- } else {
- Class<? extends ILuceneObject> objType = classMap.get(otype);
- ILuceneObject obj = (ILuceneObject) storage.get(key, objType);
- if (otype.equals("agenda")) {
- Agenda agenda = (Agenda)obj;
- for( Addendum addendum : agenda.getAddendums()) {
- addendum.setAgenda(agenda);
- for( Meeting meeting : addendum.getMeetings() ) {
- meeting.setAddendums(new ArrayList<Addendum>(Arrays.asList(addendum)));
- meeting.setModified(agenda.getModified());
- lucene.addDocument(meeting, serializers, indexWriter);
+ } else if(otype.equals("bill")) {
+ Bill bill = (Bill)obj;
+
+ // Regenerate all the bill actions
+ lucene.deleteDocumentsByQuery("otype:action AND billno:" + bill.getSenateBillNo(), indexWriter);
+ if(bill.getActions() != null) {
+ for(Action be:bill.getActions()) {
+ try {
+ be.setModified(bill.getModified());
+ be.setBill(bill);
+ lucene.addDocument(be, serializers, indexWriter);
+ } catch (Exception e) {
+ // TODO: Something
+ logger.error("Error indexing: "+be.luceneOid(), e);
+ }
+ }
}
- }
- } else if(otype.equals("bill")) {
- Bill bill = (Bill)obj;
+ // Regenerate all the bill votes
+ lucene.deleteDocumentsByQuery("otype:vote AND billno:" + bill.getSenateBillNo(), indexWriter);
+ if(bill.getVotes() != null) {
+ for(Vote vote: bill.getVotes()) {
+ try {
+ vote.setModified(bill.getModified());
+ vote.setBill(bill);
+ lucene.addDocument(vote, serializers, indexWriter);
+ } catch(Exception e) {
+ //TODO: Something
+ logger.error("Error indexing: "+vote.luceneOid(), e);
+ }
+ }
+ }
- // Regenerate all the bill actions
- lucene.deleteDocumentsByQuery("otype:action AND billno:" + bill.getSenateBillNo(), indexWriter);
- if(bill.getActions() != null) {
- for(Action be:bill.getActions()) {
- be.setModified(bill.getModified());
- be.setBill(bill);
- lucene.addDocument(be, serializers, indexWriter);
+ try {
+ lucene.addDocument(bill, serializers, indexWriter);
+ } catch (Exception e) {
+ logger.error("Error indexing: "+bill.luceneOid(), e);
}
- }
- // Regenerate all the bill votes
- lucene.deleteDocumentsByQuery("otype:vote AND billno:" + bill.getSenateBillNo(), indexWriter);
- if(bill.getVotes() != null) {
- for(Vote vote: bill.getVotes()) {
- vote.setModified(bill.getModified());
- vote.setBill(bill);
- lucene.addDocument(vote, serializers, indexWriter);
+ } else {
+ try {
+ lucene.addDocument(obj, serializers, indexWriter);
+ } catch (Exception e) {
+ logger.error("Error indexing: "+obj.luceneOid(), e);
}
}
-
- lucene.addDocument(bill, serializers, indexWriter);
-
- } else {
- lucene.addDocument(obj, serializers, indexWriter);
}
+ } catch (Exception e) {
+ logger.error("Error processing entry: "+entry.getKey(), e);
}
}

0 comments on commit fd739a9

Please sign in to comment.