Skip to content

Instantly share code, notes, and snippets.

@maephisto
Last active January 3, 2016 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maephisto/8433263 to your computer and use it in GitHub Desktop.
Save maephisto/8433263 to your computer and use it in GitHub Desktop.
Simple Custom Similarity for Payloads (Solr/Lucene)
import org.apache.lucene.analysis.payloads.PayloadHelper;
import org.apache.lucene.search.similarities.DefaultSimilarity;
import org.apache.lucene.util.BytesRef;
public class CustomSolrSimilarity extends DefaultSimilarity {
@Override
public float scorePayload(int doc, int start, int end, BytesRef payload) {
if (payload != null) {
return PayloadHelper.decodeFloat(payload.bytes);;
}
return 1.0f;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment