Exemple #1
0
  @Override
  public synchronized byte[] info(final MainOptions options) {
    final TokenBuilder tb = new TokenBuilder();
    final long l = inX.length() + inY.length() + inZ.length();
    tb.add(LI_NAMES).add(data.meta.ftinclude).add(NL);
    tb.add(LI_SIZE + Performance.format(l, true) + NL);

    final IndexStats stats = new IndexStats(options.get(MainOptions.MAXSTAT));
    addOccs(stats);
    stats.print(tb);
    return tb.finish();
  }
Exemple #2
0
  /**
   * Constructor, initializing the index structure.
   *
   * @param data data reference
   * @throws IOException I/O Exception
   */
  public FTIndex(final Data data) throws IOException {
    super(data, true);

    // cache token length index
    inY = new DataAccess(data.meta.dbfile(DATAFTX + 'y'));
    inZ = new DataAccess(data.meta.dbfile(DATAFTX + 'z'));
    inX = new DataAccess(data.meta.dbfile(DATAFTX + 'x'));
    tp = new int[data.meta.maxlen + 3];
    final int tl = tp.length;
    for (int i = 0; i < tl; ++i) tp[i] = -1;
    int is = inX.readNum();
    while (--is >= 0) {
      int p = inX.readNum();
      final int r;
      if (p < tl) {
        r = inX.read4();
      } else {
        // legacy issue (7.0.2 -> 7.1)
        r = p << 24 | (inX.read1() & 0xFF) << 16 | (inX.read1() & 0xFF) << 8 | inX.read1() & 0xFF;
        p = p >> 8 | 0x40;
      }
      tp[p] = r;
    }
    tp[tl - 1] = (int) inY.length();
  }
Exemple #3
0
  @Override
  protected long index(final int pre, final int id, final byte[] value, final int kind) {
    final DataAccess store;
    final TokenObjMap<IntList> map;
    if (kind == ATTR) {
      store = values;
      map = meta.attrindex ? atvBuffer : null;
    } else {
      store = texts;
      // don't index document names
      map = meta.textindex && kind != DOC ? txtBuffer : null;
    }

    // add text to map to index later
    if (meta.updindex && map != null && value.length <= meta.maxlen) {
      IntList ids = map.get(value);
      if (ids == null) {
        ids = new IntList(1);
        map.put(value, ids);
      }
      ids.add(id);
    }

    // add text to text file
    // inline integer value...
    final long v = toSimpleInt(value);
    if (v != Integer.MIN_VALUE) return v | IO.OFFNUM;

    // store text
    final long off = store.length();
    final byte[] val = COMP.get().pack(value);
    store.writeToken(off, val);
    return val == value ? off : off | IO.OFFCOMP;
  }
Exemple #4
0
  @Override
  protected void updateText(final int pre, final byte[] value, final int kind) {
    final boolean text = kind != ATTR;

    if (meta.updindex) {
      // update indexes
      final int id = id(pre);
      final byte[] oldval = text(pre, text);
      final DiskValues index = (DiskValues) (text ? textIndex : attrIndex);
      // don't index document names
      if (index != null && kind != DOC) index.replace(oldval, value, id);
    }

    // reference to text store
    final DataAccess store = text ? texts : values;
    // file length
    final long len = store.length();

    // new entry (offset or value)
    final long v = toSimpleInt(value);
    if (v != Integer.MIN_VALUE) {
      // inline integer value
      textOff(pre, v | IO.OFFNUM);
    } else {
      // text to be stored (possibly packed)
      final byte[] val = COMP.get().pack(value);
      // old entry (offset or value)
      final long old = textOff(pre);

      // find text store offset
      final long off;
      if (number(old)) {
        // numeric entry: append new entry at the end
        off = len;
      } else {
        // text size (0 if value will be inlined)
        final int vl = val.length;
        off = store.free(old & IO.OFFCOMP - 1, vl + Num.length(vl));
      }

      store.writeToken(off, val);
      textOff(pre, val == value ? off : off | IO.OFFCOMP);
    }
  }
Exemple #5
0
 /**
  * Constructor, initializing the index structure.
  *
  * @param data data
  * @param prefix prefix
  * @throws IOException I/O exception
  */
 FTList(final Data data, final int prefix) throws IOException {
   files = data.meta.dbfile(DATAFTX + prefix + 'y');
   filed = data.meta.dbfile(DATAFTX + prefix + 'z');
   str = new DataAccess(files);
   dat = new DataAccess(filed);
   tp = new int[data.meta.maxlen + 3];
   final int tl = tp.length;
   for (int t = 0; t < tl; t++) tp[t] = -1;
   sizes = data.meta.dbfile(DATAFTX + prefix + 'x');
   try (final DataAccess li = new DataAccess(sizes)) {
     int is = li.readNum();
     while (--is >= 0) {
       final int p = li.readNum();
       tp[p] = li.read4();
     }
     tp[tl - 1] = (int) str.length();
   }
   next();
 }