/** Closes and deletes the input files. */ private void close() { str.close(); dat.close(); files.delete(); filed.delete(); sizes.delete(); }
@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; }
@Override public int textLen(final int pre, final boolean text) { final long o = textOff(pre); if (number(o)) return numDigits((int) o); final DataAccess da = text ? texts : values; final int l = da.readNum(o & IO.OFFCOMP - 1); // compressed: next number contains number of compressed bytes return compressed(o) ? da.readNum() : l; }
@Override public synchronized void flush(final boolean all) { try { table.flush(all); if (all) { write(); texts.flush(); values.flush(); if (textIndex != null) ((DiskValues) textIndex).flush(); if (attrIndex != null) ((DiskValues) attrIndex).flush(); } } catch (final IOException ex) { Util.stack(ex); } }
@Override public synchronized void close() { if (closed) return; closed = true; try { write(); table.close(); texts.close(); values.close(); close(IndexType.TEXT); close(IndexType.ATTRIBUTE); close(IndexType.FULLTEXT); } catch (final IOException ex) { Util.stack(ex); } }
/** * Returns next token. * * @return byte[] token */ private byte[] token() { if (tp[tp.length - 1] == ptok) return EMPTY; if (tp[ntl] == ptok || ntl == 0) { ++ctl; while (tp[ctl] == -1) ++ctl; ntl = ctl + 1; while (tp[ntl] == -1) ++ntl; } if (ctl == tp.length) return EMPTY; final byte[] t = str.readBytes(ptok, ctl); // skip pointer size = str.read4(str.cursor() + 5); // position will always fit in an integer... ptok = (int) str.cursor(); return t; }
@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); } }
/** * 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(); }
/** Checks if more tokens are found. */ void next() { if (wasted) return; tok = token(); if (tok.length == 0) { wasted = true; prv = NOINTS; pov = NOINTS; close(); } else { prv = new int[size]; pov = new int[size]; for (int j = 0; j < size; ++j) { prv[j] = dat.readNum(); pov[j] = dat.readNum(); } } }