@Override public synchronized boolean index(E element) throws Exception { int elemId = element.getElementId(); if (!elementStore.hasIndex(elemId)) { return false; } // Set element score if (scoreStore.hasIndex(elemId) && element.getScore() == 0) { element.setScore(scoreStore.get(elemId)); } // Check if prefixes changed boolean prefixChanged = false; E oldElement = elementStore.getElement(elemId); if (oldElement == null || !Arrays.equals(element.getTerms(), oldElement.getTerms())) { prefixChanged = true; } // Update elementStore, filterStore long scn = element.getTimestamp(); long elemFilter = bloomFilter.computeIndexFilter(element); filterStore.set(elemId, elemFilter); elementStore.setElement(elemId, element, scn); // Update connectionsStore upon prefix changes if (prefixChanged) { updateConnectionStore(oldElement, element); } // Persist connectionsStore if elementStore is persisted if (elementStore.getHWMark() == elementStore.getLWMark()) { connectionsStore.persist(); } // Logging if (logger.isDebugEnabled()) { logger.debug(getName() + " indexed element " + element); } else { logger.info(getName() + " indexed element " + element.getElementId()); } return true; }
@Override public boolean index(E element) throws Exception { ensureOpen(); writeLock.lock(); try { int elemId = element.getElementId(); if (!elementStore.hasIndex(elemId)) { return false; } // Set element score if (scoreStore.hasIndex(elemId) && element.getScore() == 0) { element.setScore(scoreStore.get(elemId)); } // Check if prefixes changed boolean prefixChanged = false; E oldElement = elementStore.getElement(elemId); if (oldElement == null || !Arrays.equals(element.getTerms(), oldElement.getTerms())) { prefixChanged = true; } // Update elementStore, filterStore long scn = element.getTimestamp(); long elemFilter = bloomFilter.computeIndexFilter(element); filterStore.set(elemId, elemFilter); elementStore.setElement(elemId, element, scn); // Update connectionsStore upon prefix changes if (prefixChanged) { updateConnectionStore(oldElement, element); } } finally { writeLock.unlock(); } // Logging if (logger.isInfoEnabled()) { logger.info(getName() + " indexed element " + element.getElementId()); } return true; }