Skip to content

Commit

Permalink
storeBuild changed
Browse files Browse the repository at this point in the history
  • Loading branch information
hmarkc committed Aug 30, 2021
1 parent 99ed7a4 commit 7bbcd5f
Showing 1 changed file with 15 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,52 +249,45 @@ protected Query getRangeQuery(String field, String part1, String part2, boolean
}

@Override
public void storeBuild(final Run<?, ?> run, Document oldDoc) throws IOException {
public void storeBuild(final Run<?, ?> run) throws IOException {
try {
Document doc = new Document();
for (Field field : Field.values()) {
org.apache.lucene.document.Field.Store store = field.persist ? STORE : DONT_STORE;
Object fieldValue = field.getValue(run);
if (fieldValue == null && oldDoc != null) {
fieldValue = oldDoc.get(field.fieldName);
}
if (fieldValue != null) {

switch (FIELD_TYPE_MAP.get(field)) {
case LONG:
doc.add(new LongField(field.fieldName, ((Number) fieldValue).longValue(), store));
break;
case STRING:
doc.add(new StringField(field.fieldName, fieldValue.toString(), store));
break;
case TEXT:
doc.add(new TextField(field.fieldName, fieldValue.toString(), store));
break;
default:
throw new IllegalArgumentException("Don't know how to handle " + FIELD_TYPE_MAP.get(field));
case LONG:
doc.add(new LongField(field.fieldName, ((Number) fieldValue).longValue(), store));
break;
case STRING:
doc.add(new StringField(field.fieldName, fieldValue.toString(), store));
break;
case TEXT:
doc.add(new TextField(field.fieldName, fieldValue.toString(), store));
break;
default:
throw new IllegalArgumentException("Don't know how to handle " + FIELD_TYPE_MAP.get(field));
}
}
}

for (FreeTextSearchExtension extension : FreeTextSearchExtension.all()) {
try {
Object fieldValue = extension.getTextResult(run);
if (fieldValue == null && oldDoc != null) {
fieldValue = oldDoc.get(extension.getKeyword());
}
if (fieldValue != null) {
doc.add(new TextField(extension.getKeyword(), extension.getTextResult(run), (extension
.isPersist()) ? STORE : DONT_STORE));
}
} catch (Throwable t) {
//We don't want to crash the collection of log from other plugin extensions if we happen to add a plugin that crashes while collecting the logs.
System.out.println("CRASH: " + extension.getClass().getName() + ", " + extension.getKeyword());
t.printStackTrace();
LOGGER.warn("CRASH: " + extension.getClass().getName() + ", " + extension.getKeyword() + t);
}
}

dbWriter.addDocument(doc);
} finally {
updateReader();
dbWriter.commit();
}
}

Expand Down

0 comments on commit 7bbcd5f

Please sign in to comment.