开发学院软件开发Java 深入浅出 jackrabbit 二 索引概览 阅读

深入浅出 jackrabbit 二 索引概览

 2009-09-17 00:00:00 来源:WEB开发网   
核心提示: 既然知道了index的入口,不妨让我们来看一下SearchManager中索引的入口方法onEvent() Java代码publicvoidonEvent(EventIteratorevents){//nodesthatneedtoberemovedfromtheindex.finalSetre

既然知道了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."); 
    } 
  }

上一页  1 2 3 4  下一页

Tags:深入浅出 jackrabbit 索引

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接