private synchronized void reIndex() throws IOException {
UseCase ucReIndex = MonitorFactory.startUseCase("reIndex()");
// build a dictionary (from the spell package)
log.debug("Starting to reindex SYN index.");
IndexAccessor synonymAccessor = synonym.getSynonymLocation().getAccessor();
IndexWriter synonymWriter = synonymAccessor.getWriter();
Collection<CRResolvableBean> objectsToIndex = null;
try {
if (rp == null) {
throw new CRException("FATAL ERROR", "RequestProcessor not available");
}
// and get the current rule
String rule = (String) config.get(RULE_KEY);
if (rule == null) {
rule = "";
}
if (rule.length() == 0 || rule == null) {
rule = "1 == 1";
}
try {
CRRequest req = new CRRequest();
req.setRequestFilter(rule);
status.setCurrentStatusString("SYN Get objects to update " + "in the index ...");
objectsToIndex = getObjectsToUpdate(req, rp, true, null);
} catch (Exception e) {
log.error("ERROR while cleaning SYN index", e);
}
if (objectsToIndex == null) {
log.debug("SYN Rule returned no objects to index. Skipping...");
return;
}
status.setObjectCount(objectsToIndex.size());
log.debug("SYN index job with " + objectsToIndex.size() + " objects to index.");
String descriptorName = (String) config.get(DESCRIPTOR_NAME_KEY);
String synonymName = (String) config.get(SYNONYM_NAME_KEY);
status.setCurrentStatusString("Starting to index slices.");
int objCount = 0;
try {
for (Iterator<CRResolvableBean> iterator = objectsToIndex.iterator(); iterator.hasNext();) {
CRResolvableBean bean = iterator.next();
iterator.remove();
objCount++;
String descriptorValue = bean.getString(descriptorName);
String synonymValue = bean.getString(synonymName);
if (descriptorValue != null && synonymValue != null) {
descriptorValue = descriptorValue.toLowerCase();
if (synonymValue != null) {
synonymValue = synonymValue.toLowerCase();
}
Document doc = new Document();
doc.add(new Field("Deskriptor", descriptorValue, Field.Store.YES, Field.Index.NOT_ANALYZED));
doc.add(new Field("Synonym", synonymValue, Field.Store.YES, Field.Index.NOT_ANALYZED));
synonymWriter.addDocument(doc);
log.debug("WRITE SYN " + objCount + " " + descriptorValue + " " + synonymValue);
synonymWriter.commit();
log.debug("Number of actual Synonym: " + synonymWriter.numDocs());
}
}
} finally {
// if documents where added to the index create a reopen file and
// optimize the writer
log.debug("Number of indexed Synonyms finished: " + synonymWriter.numDocs());
synonymAccessor.release(synonymWriter);
}
log.debug("Finished reindexing synonym index.");
ucReIndex.stop();
} catch (Exception e) {