javapythonlucenepylucene

Overriding DefaultSimilarity's scorePayload method doesn't work in pulucene


I want to use payload in pylucene, justlike the java code in this article. The python snippet is:

class PayloadSimilarity(PythonDefaultSimilarity):

    def scorePayload(self, docId, start, end, payload): # this never execute
        return PayloadHelper.decodeFloat(payload.bytes, end) 

But it doesn't work. The method scorePayload is never invoked. Payload of word is still 1, not the value I set in the document.

The same code in java works fine:

class PayloadSimilarity extends DefaultSimilarity {

    @Override
    public float scorePayload(int docId, int start, int end,  BytesRef payload) {
        return PayloadHelper.decodeFloat(payload.bytes, end);
    }
}

I wrote the python code according to this link. Full python code is there


Solution

  • After read the document of jcc, I solved this by myself. This problem is the same as this one.

    My solution is:

    Add some code to this file pylucene/java/org/apache/pylucene/search/similarities/PythonDefaultSimilarity.java:

    import org.apache.lucene.util.BytesRef;
    public native float scorePayload(int docId, int start, int end, BytesRef payload);