本文整理汇总了Java中org.apache.lucene.analysis.tokenattributes.PayloadAttribute.setPayload方法的典型用法代码示例。如果您正苦于以下问题:Java PayloadAttribute.setPayload方法的具体用法?Java PayloadAttribute.setPayload怎么用?Java PayloadAttribute.setPayload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.analysis.tokenattributes.PayloadAttribute
的用法示例。
在下文中一共展示了PayloadAttribute.setPayload方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setAttributes
import org.apache.lucene.analysis.tokenattributes.PayloadAttribute; //导入方法依赖的package包/类
protected void setAttributes(String token, float payload) {
CharTermAttribute termAtt = this.getAttribute(CharTermAttribute.class);
termAtt.setEmpty();
termAtt.append(token);
termAtt.setLength(token.length());
PayloadAttribute payloadAtt = this.getAttribute(PayloadAttribute.class);
byte[] bytes = PayloadHelper.encodeFloat(payload);
payloadAtt.setPayload(new BytesRef(bytes));
}
示例2: appendPayloads
import org.apache.lucene.analysis.tokenattributes.PayloadAttribute; //导入方法依赖的package包/类
private void appendPayloads(String[] tags, int length) {
for (int i = 0; i < length; i++) {
AttributeSource attrs = tokenAttrs.get(i);
if (tags[i] != null) {
try {
PayloadAttribute payloadAtt = attrs.hasAttribute(PayloadAttribute.class) ? attrs.getAttribute(PayloadAttribute.class) : attrs.addAttribute(PayloadAttribute.class);
BytesRef bytesRef = new BytesRef(tags[i].toUpperCase(Locale.getDefault()).getBytes("UTF-8"));
payloadAtt.setPayload(bytesRef);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
}
}
示例3: incrementToken
import org.apache.lucene.analysis.tokenattributes.PayloadAttribute; //导入方法依赖的package包/类
@Override
public boolean incrementToken() throws IOException {
if (input.incrementToken()) {
PayloadAttribute payloadAtt = getAttribute(PayloadAttribute.class);
if (payloadAtt != null) {
payloadAtt.setPayload(null);
}
return true;
}
return false;
}
示例4: createState
import org.apache.lucene.analysis.tokenattributes.PayloadAttribute; //导入方法依赖的package包/类
private static AttributeSource.State createState(AttributeSource a, Tok state, int tokenEnd) {
a.clearAttributes();
CharTermAttribute termAtt = a.addAttribute(CharTermAttribute.class);
char[] tokChars = state.token.toString().toCharArray();
termAtt.copyBuffer(tokChars, 0, tokChars.length);
int tokenStart = tokenEnd - state.token.length();
for (Entry<String, String> e : state.attr.entrySet()) {
String k = e.getKey();
if (k.equals("i")) {
// position increment
int incr = Integer.parseInt(e.getValue());
PositionIncrementAttribute posIncr = a.addAttribute(PositionIncrementAttribute.class);
posIncr.setPositionIncrement(incr);
} else if (k.equals("s")) {
tokenStart = Integer.parseInt(e.getValue());
} else if (k.equals("e")) {
tokenEnd = Integer.parseInt(e.getValue());
} else if (k.equals("y")) {
TypeAttribute type = a.addAttribute(TypeAttribute.class);
type.setType(e.getValue());
} else if (k.equals("f")) {
FlagsAttribute flags = a.addAttribute(FlagsAttribute.class);
int f = Integer.parseInt(e.getValue(), 16);
flags.setFlags(f);
} else if (k.equals("p")) {
PayloadAttribute p = a.addAttribute(PayloadAttribute.class);
byte[] data = hexToBytes(e.getValue());
if (data != null && data.length > 0) {
p.setPayload(new BytesRef(data));
}
} else {
// unknown attribute
}
}
// handle offset attr
OffsetAttribute offset = a.addAttribute(OffsetAttribute.class);
offset.setOffset(tokenStart, tokenEnd);
State resState = a.captureState();
a.clearAttributes();
return resState;
}
示例5: addPayloadAttribute
import org.apache.lucene.analysis.tokenattributes.PayloadAttribute; //导入方法依赖的package包/类
public void addPayloadAttribute(PayloadAttribute attribute, MWEMetadata ctx) {
String data = MWEMetadata.serialize(ctx);
attribute.setPayload(new BytesRef(data));
}