caio.co/de/cerberus

Expose indexWriter.forceMerge(1) as mergeSegments()

Id
a6f05d979e14a6eb8d8e4f74eb0c51405b65d74c
Author
Caio
Commit time
2018-12-05T16:16:14+01:00

Modified pom.xml

@@ -186,10 +186,8
<arguments>
<argument>-classpath</argument>
<classpath/>
- <argument>-Xmx256m</argument>
- <argument>-Xms256m</argument>
- <argument>-Xlog:gc</argument>
- <argument>-verbose:gc</argument>
+ <argument>-Xmx512m</argument>
+ <argument>-Xms512m</argument>
<argument>-Dlogback.configurationFile=src/test/resources/logback-test.xml</argument>
<argument>-Dcerberus.recipes.filename=tmp/document.jsonlines</argument>
<argument>-Dcerberus.recipes.datadir=tmp/hue</argument>

Modified src/main/java/co/caio/cerberus/Loader.java

@@ -39,6 +39,9
}
});
indexer.commit();
+ logger.info("Optimizing index for read-only usage");
+ indexer.mergeSegments();
logger.info("Done!");
+ indexer.close();
}
}

Modified src/main/java/co/caio/cerberus/model/Recipe.java

@@ -97,7 +97,7
return Optional.of(Environment.getObjectMapper().readValue(json, Recipe.class));
} catch (Exception e) {
LoggerFactory.getLogger(Recipe.class)
- .error("Failed to read json <{}> as <{}>", json, Recipe.class);
+ .error("Failed to read json <{}>", json, e);
return Optional.empty();
}
}
@@ -106,7 +106,7
try {
return Optional.of(Environment.getObjectMapper().writeValueAsString(recipe));
} catch (Exception e) {
- LoggerFactory.getLogger(Recipe.class).error("Failed to serialize {} to json", recipe);
+ LoggerFactory.getLogger(Recipe.class).error("Failed to serialize {} to json", recipe, e);
return Optional.empty();
}
}

Modified src/main/java/co/caio/cerberus/search/Indexer.java

@@ -26,6 +26,8

void commit() throws IOException;

+ void mergeSegments() throws IOException;
+
Searcher buildSearcher();

class Builder {
@@ -172,6 +174,11
@Override
public int numDocs() {
return indexWriter.numDocs();
+ }
+
+ @Override
+ public void mergeSegments() throws IOException {
+ indexWriter.forceMerge(1, true);
}

@Override