Hi Dmitry,

I think, it is activated by PayloadTermQuery.

Ahmet



On Friday, April 24, 2015 2:51 PM, Dmitry Kan <solrexp...@gmail.com> wrote:
Hi,


Using the approach here
http://lucidworks.com/blog/getting-started-with-payloads/ I have
implemented my own PayloadSimilarity class. When debugging the code I have
noticed, that the scorePayload method is never called. What could be wrong?


[code]

class PayloadSimilarity extends DefaultSimilarity {
    @Override
    public float scorePayload(int doc, int start, int end, BytesRef payload) {
        float payloadValue = PayloadHelper.decodeFloat(payload.bytes);
        System.out.println("payloadValue = " + payloadValue);
        return payloadValue;
    }
}

[/code]


Here is how the similarity is injected during indexing:

[code]

PayloadEncoder encoder = new FloatEncoder();
IndexWriterConfig indexWriterConfig = new
IndexWriterConfig(Version.LUCENE_4_10_4, new
PayloadAnalyzer(encoder));
payloadSimilarity = new PayloadSimilarity();
indexWriterConfig.setSimilarity(payloadSimilarity);
IndexWriter writer = new IndexWriter(dir, indexWriterConfig);

[/code]


and during searching:

[code]

IndexReader indexReader = DirectoryReader.open(dir);
IndexSearcher searcher = new IndexSearcher(indexReader);
searcher.setSimilarity(payloadSimilarity);

TermQuery termQuery = new TermQuery(new Term("body", "dogs"));
termQuery.setBoost(1.1f);
TopDocs topDocs = searcher.search(termQuery, 10);
printResults(searcher, termQuery, topDocs);


[/code]

-- 
Dmitry Kan
Luke Toolbox: http://github.com/DmitryKey/luke
Blog: http://dmitrykan.blogspot.com
Twitter: http://twitter.com/dmitrykan
SemanticAnalyzer: www.semanticanalyzer.info

Reply via email to