Пример #1
0
  protected FloatArrayPartition initScoreStore() {
    FloatArrayPartition p =
        new StaticFloatArrayPartition(elementStore.getIndexStart(), elementStore.capacity());

    try {
      if (scoreScanner != null) {
        long startTime = System.currentTimeMillis();

        ElementScoreHandler handler = new ElementScoreHandler(p);
        scoreScanner.scan(handler);

        for (int i = p.getIndexStart(), end = p.getIndexEnd(); i < end; i++) {
          float score = p.get(i);
          if (score < Score.MIN_SCORE_FLOAT) {
            score = Score.MIN_SCORE_FLOAT;
            p.set(i, score);
          }

          if (elementStore.hasIndex(i)) {
            E element = elementStore.getElement(i);
            if (element != null) {
              element.setScore(score);
            }
          }
        }

        long totalTime = System.currentTimeMillis() - startTime;
        logger.info(getName() + " load element scores: " + totalTime + " ms");
      }
    } catch (Exception e) {
      logger.warn(getName() + " faileld to load element scores", e);
    }

    return p;
  }
Пример #2
0
  @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;
  }
Пример #3
0
  @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;
  }