Lucene中如何将Payload信息写入索引,如何从索引中读取Payload信息?
求源代码 展开
Payloads are byte arrays stored with Terms on Fields.
See https://issues.apache.org/jira/browse/LUCENE-755
Use Cases
Searching For Payloads
Scoring Payloads
Scoring payloads involves overriding the Similarity.scorePayload() method. For example, if one has implemented storing a Float payload, it could be used for scoring in the following way:
public float scorePayload(byte [] payload, int offset, int length) {
assert length == 4;
int accum = ((payload[0+offset]&0xff)) |
((payload[1+offset]&0xff)<<8) |
((payload[2+offset]&0xff)<<16) |
((payload[3+offset]&0xff)<<24);
return Float.intBitsToFloat(accum);
}
Don't forget to activate your Similarity implementation using IndexSearcher.setSimilarity(). Also, note that even then not all queries will actually make use of your method. For example, you will need to use BoostingTermQuery instead of TermQuery. QueryParser currently (Lucene 2.3.2) always uses TermQuery and you will need to extend QueryParser and overwrite getFieldQuery().
Note, that is just one possible way of scoring a payload. Payloads are application specific. For example payload Token Filters see the payload package in the contrib/Analysis module.
嗯,很好。我想问问,那payload是一个字节数组,那么能不能把string变成一个字节数组,然后存放在payload中,但是这种情况下,在searcher的时候,能不能根据string给相应的term在设置权值?谢谢