深入浅出 jackrabbit 二 索引概览
2009-09-17 00:00:00 来源:WEB开发网既然知道了index的入口,不妨让我们来看一下SearchManager中索引的入口方法onEvent()
Java代码
public void onEvent(EventIterator events) {
// nodes that need to be removed from the index.
final Set removedNodes = new HashSet();
// nodes that need to be added to the index.
final Map addedNodes = new HashMap();
// property events
List propEvents = new ArrayList();
while (events.hasNext()) {
EventImpl e = (EventImpl) events.nextEvent();
if (!isExcluded(e)) {
long type = e.getType();
if (type == Event.NODE_ADDED) {
addedNodes.put(e.getChildId(), e);
// quick'n dirty fix for JCR-905
if (e.isExternal()) {
removedNodes.add(e.getChildId());
}
} else if (type == Event.NODE_REMOVED) {
removedNodes.add(e.getChildId());
} else {
propEvents.add(e);
}
}
}
// sort out property events
for (int i = 0; i < propEvents.size(); i++) {
EventImpl e = (EventImpl) propEvents.get(i);
NodeId nodeId = e.getParentId();
if (e.getType() == Event.PROPERTY_ADDED) {
if (addedNodes.put(nodeId, e) == null) {
// only property added
// need to re-index
removedNodes.add(nodeId);
} else {
// the node where this prop belongs to is also new
}
} else if (e.getType() == Event.PROPERTY_CHANGED) {
// need to re-index
addedNodes.put(nodeId, e);
removedNodes.add(nodeId);
} else {
// property removed event is only generated when node still exists
addedNodes.put(nodeId, e);
removedNodes.add(nodeId);
}
}
NodeStateIterator addedStates = new NodeStateIterator() {
//创建需要add的node iterator
…………….
};
NodeIdIterator removedIds = new NodeIdIterator() {
……………………
};
if (removedNodes.size() > 0 || addedNodes.size() > 0) {
try {
handler.updateNodes(removedIds, addedStates);
} catch (RepositoryException e) {
log.error("Error indexing node.", e);
} catch (IOException e) {
log.error("Error indexing node.", e);
}
}
if (log.isDebugEnabled()) {
log.debug("onEvent: indexing finished in "
+ String.valueOf(System.currentTimeMillis() - time)
+ " ms.");
}
}
Tags:深入浅出 jackrabbit 索引
编辑录入:爽爽 [复制链接] [打 印]- ››深入浅出实战攻防恶意PDF文档
- ››深入浅出ShellExecute
- ››深入浅出URL编码
- ››深入浅出Java多线程程序设计
- ››深入浅出 jackrabbit 八 索引合并(上)
- ››深入浅出 jackrabbit 九 索引合并(下)
- ››深入浅出 jackrabbit 十 redolog 和 recovery.doc...
- ››深入浅出 jackrabbit 十一 jackrabbit改进要点
- ››深入浅出 jackrabbit 十二 key-value存储系统
- ››深入浅出 jackrabbit 十三 查询之AST和QT
- ››深入浅出 jackrabbit 一
- ››深入浅出 jackrabbit 二 索引概览
更多精彩
赞助商链接