All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.browseengine.bobo.search.section.AndNode Maven / Gradle / Ivy

Go to download

Bobo is a Faceted Search implementation written purely in Java, an extension of Apache Lucene

The newest version!
/**
 * 
 */
package com.browseengine.bobo.search.section;

import java.io.IOException;

import org.apache.lucene.search.DocIdSetIterator;

/**
 * AND operator node for SectionSearchQueryPlan
 */
public class AndNode extends SectionSearchQueryPlan {
  protected SectionSearchQueryPlan[] _subqueries;

  public AndNode(SectionSearchQueryPlan[] subqueries) {
    _subqueries = subqueries;
    _curDoc = (subqueries.length > 0 ? -1 : DocIdSetIterator.NO_MORE_DOCS);
  }

  @Override
  public int fetchDoc(int targetDoc) throws IOException {
    if (_curDoc == DocIdSetIterator.NO_MORE_DOCS) {
      return _curDoc;
    }

    SectionSearchQueryPlan node = _subqueries[0];
    _curDoc = node.fetchDoc(targetDoc);
    targetDoc = _curDoc;

    int i = 1;
    while (i < _subqueries.length) {
      node = _subqueries[i];
      if (node._curDoc < targetDoc) {
        _curDoc = node.fetchDoc(targetDoc);
        if (_curDoc == DocIdSetIterator.NO_MORE_DOCS) {
          return _curDoc;
        }

        if (_curDoc > targetDoc) {
          targetDoc = _curDoc;
          i = 0;
          continue;
        }
      }
      i++;
    }
    _curSec = -1;
    return _curDoc;
  }

  @Override
  public int fetchSec(int targetSec) throws IOException {
    SectionSearchQueryPlan node = _subqueries[0];
    targetSec = node.fetchSec(targetSec);
    if (targetSec == SectionSearchQueryPlan.NO_MORE_SECTIONS) {
      _curSec = SectionSearchQueryPlan.NO_MORE_SECTIONS;
      return targetSec;
    }

    int i = 1;
    while (i < _subqueries.length) {
      node = _subqueries[i];
      if (node._curSec < targetSec) {
        _curSec = node.fetchSec(targetSec);
        if (_curSec == SectionSearchQueryPlan.NO_MORE_SECTIONS) {
          return _curSec;
        }

        if (_curSec > targetSec) {
          targetSec = _curSec;
          i = 0;
          continue;
        }
      }
      i++;
    }
    return _curSec;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy