Lucene中如何将Payload信息写入索引,如何从索引中读取Payload信息?

我的payload信息是String,如何把String写入到payload,及读出payload信息求源代码... 我的payload信息是String,如何把String写入到payload,及读出payload信息
求源代码
展开
 我来答
1039725910
2015-01-29 · TA获得超过318个赞
知道小有建树答主
回答量:364
采纳率:100%
帮助的人:266万
展开全部

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在设置权值?谢谢
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式