Java 类org.apache.lucene.index.Payload 实例源码

项目:fangorn    文件:JsonSentenceParser.java   
private Payload getVarDiffPayload(byte[] bytes) {
    byte[] finalbytes = bytes;
    ByteOps.PosMid pm = byteOps.int4ToDiffVarBytes(intbuffer, bytes);
    if (pm.position < 8) {
        int numberOfBytes;
        if (pm.mid) {
            numberOfBytes = pm.position + 1;
        } else {
            numberOfBytes = pm.position;
        }
        finalbytes = new byte[numberOfBytes];
        System.arraycopy(bytes, 0, finalbytes, 0, numberOfBytes);
    }
    final Payload payload = new Payload(finalbytes);
    return payload;
}
项目:fangorn    文件:TreebankSentenceTokenizer.java   
/**
 * This is where the order of the elements in the current token decides
 * the position within the position increment field in lucene token
 * 
 * @return
 */
public Payload getPayload() {
    // if (!(r < 256 && l < 256) && r < 1024 && l < 1024 && p < 512)
    // {
    // byte[] v = new byte[] { (byte) (r & 255), (byte) (l & 255),
    // (byte) (h & 255), (byte) (p & 255), (byte) (((r & 768) >>> 4)
    // |
    // ((l & 768) >>> 6) | ((p & 256) >>> 8)) };
    // }
    if (!(h < 256 && l < 256 && r < 256 && p < 256)) {
        throw new OverflowException(
                "Exceeded allocated space for payload l=" + l + " r="
                        + r + " p=" + p + " h=" + h);
    }

    byte[] v = new byte[] { (byte) (r & 255), (byte) (l & 255),
            (byte) (h & 255), (byte) (p & 255) };

    return new Payload(v);
}
项目:fangorn    文件:FastStringParser.java   
public Token next(Token token) {
    if (currentPos == 0) return null;
    if (tokenPos <= currentPos) {
        token.setTermBuffer(sentence, textPositions[2 * tokenPos],
                textPositions[2 * tokenPos + 1]
                        - textPositions[2 * tokenPos]);
        Payload p = new Payload();
        byte[] b = new byte[4];
        b[0] = (byte) ((payloads[tokenPos] >>> 16) & 255);
        b[1] = (byte) ((payloads[tokenPos] >>> 24) & 255);
        b[2] = (byte) ((payloads[tokenPos] >>> 8) & 255);
        b[3] = (byte) (payloads[tokenPos] & 255);
        p.setData(b);
        token.setPayload(p);
        tokenPos++;
        return token;
    }
    return null;
}
项目:fangorn    文件:Node.java   
public Payload getPayload() {
    if (!(depth < 256 && left < 256 && right < 256 && parentId < 256)) {
        throw new OverflowException(
                "Exceeded allocated space for payload l=" + left + " r="
                        + right + " p=" + parentId + " d=" + depth);
    }

    byte[] v = new byte[] { (byte) (right & 255), (byte) (left & 255),
            (byte) (depth & 255), (byte) (parentId & 255) };

    return new Payload(v);

}
项目:fangorn    文件:FastStringParserTest.java   
private void assertPayload(int left, int right, int depth, int parent) {
    final Payload payload = token.getPayload();
    assertEquals(left, payload.byteAt(1));
    assertEquals(right, payload.byteAt(0));
    assertEquals(depth, payload.byteAt(2));
    assertEquals(parent, payload.byteAt(3));
}
项目:fangorn    文件:String2NodesParserTest.java   
private void assertPayload(Token token, int right, int left, int depth,
        int parent) {
    Payload payload = token.getPayload();
    assertEquals(right, payload.byteAt(0));
    assertEquals(left, payload.byteAt(1));
    assertEquals(depth, payload.byteAt(2));
    assertEquals(parent, payload.byteAt(3));
}
项目:fangorn    文件:JsonSentenceParser.java   
public Token next(Token token) {
    boolean nameFound = nameMatcher.find();
    boolean indexFound = indexMatcher.find();
    if (nameFound && indexFound) {
        final int nstart = nameMatcher.start();
        final int nend = nameMatcher.end();
        final int indexOfEscapedQuotes = jsonSentence.indexOf("\\\"", nstart
                + BEFORE_CONST);
        if (indexOfEscapedQuotes != -1
                && indexOfEscapedQuotes < nend - AFTER_CONST) {
            String str = jsonSentence.substring(nstart + BEFORE_CONST, nend
                    - AFTER_CONST);
            str = str.replace("\\\"", "\"");
            token.setTermBuffer(str);
        } else {
            token.setTermBuffer(jsonSentence, nstart + BEFORE_CONST,
                    nameMatcher.end() - AFTER_CONST - nstart - BEFORE_CONST);
        }
        String index = jsonSentence.substring(indexMatcher.start()
                + BEFORE_CONST, indexMatcher.end() - AFTER_CONST);
        String[] split = index.split("_");
        for (int i = 0; i < 4; i++) {
            intbuffer[i] = Integer.parseInt(split[i]);
            if (intbuffer[i] > 255) {
                throw new OverflowException(
                        "Exceeded payload size for element " + i + " = "
                                + intbuffer[i]);
            }
            buffer[i] = (byte) (intbuffer[i] & 255);
        }
        if (compressPayload) {
            byte[] bytes = new byte[8];
            try {
                token.setPayload(getVarDiffPayload(bytes));
            } catch (ArrayIndexOutOfBoundsException e) {
                throw new OverflowException(
                        "Exceeded payload size for element ");

            }
        } else {
            token.setPayload(new Payload(buffer.clone()));
        }

        // if (compressPayload) {
        // byte[] bytes = new byte[8];
        // try {
        // token.setPayload(getVarDiffPayload(bytes));
        // }catch (ArrayIndexOutOfBoundsException e) {
        // bytes = new byte[16];
        // try {
        // token.setPayload(getVarDiffPayload(bytes));
        // } catch(ArrayIndexOutOfBoundsException ee) {
        // throw new
        // OverflowException("Exceeded payload size for element ");
        // }
        // }
        //              
        // } else {
        // for (int i = 0; i < 4; i++) {
        // if(intbuffer[i] > 255) {
        // throw new OverflowException("Exceeded payload size for element "
        // + i + " = " + intbuffer[i]);
        // }
        // buffer[i] = (byte) (intbuffer[i] & 255);
        // }
        // token.setPayload(new Payload(buffer.clone()));
        // }
        return token;
    }
    return null;
}
项目:t4f-data    文件:BulletinPayloadsFilter.java   
BulletinPayloadsFilter(TokenStream in, float warningBoost) {
  super(in);
  payloadAttr = addAttribute(PayloadAttribute.class);
  termAtt = addAttribute(TermAttribute.class);
  boostPayload = new Payload(PayloadHelper.encodeFloat(warningBoost));
}