Payloads are byte arrays stored with Terms on Fields.


Use Cases

/* TODO */

Searching For Payloads

/* TODO */

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)  |

    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.

  • No labels