Package dovetaildb.bagindex

Source Code of dovetaildb.bagindex.BagIndexUtil

package dovetaildb.bagindex;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import dovetaildb.dbservice.DbServiceUtil;
import dovetaildb.dbservice.TermEncoder;
import dovetaildb.scan.AbstractScanner;
import dovetaildb.scan.Scanner;
import dovetaildb.scan.ScannerHeap;
import dovetaildb.scan.ScannerUtil;
import dovetaildb.util.Util;

public class BagIndexUtil {
 
  public static Scanner disjunctiveScannerFromTerms(byte[][] terms, BagIndex index, long revNum) {
    if (terms.length == 1) return index.fetchTd(terms[0], revNum);
    ArrayList<Scanner> scanners = new ArrayList<Scanner>();
    for(byte[] term : terms) {
      scanners.add(index.fetchTd(term, revNum));
    }
    return new ScannerHeap(scanners);
  }

  private static final long[] EMPTY_LONG_ARRAY = new long[]{};
 
  public static long[] getDocidsForIdTerms(byte[][] idTerms, BagIndex index, long revNum) {
    if (idTerms.length == 0) return EMPTY_LONG_ARRAY;
    long[] docIds = new long[idTerms.length];
    Scanner idScanner = disjunctiveScannerFromTerms(idTerms, index, revNum);
    Scanner delScanner = index.fetchDeletions(revNum);
    Scanner scanner = ScannerUtil.andNotScanner(idScanner, delScanner);
    while (scanner.next()) {
      long docId = scanner.doc();
      for(int i = 0; i < idTerms.length; i++) {
        if (scanner.knownToHaveTerm(idTerms[i]))
          docIds[i] = docId;
      }
    }
    return docIds;
  }

}
TOP

Related Classes of dovetaildb.bagindex.BagIndexUtil

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.