@Override public float score() throws IOException { assert docID() != NO_MORE_DOCS; if (binaryDocValues == null) { AtomicReader atomicReader = (AtomicReader) reader; binaryDocValues = atomicReader.getBinaryDocValues(luceneFieldName); } try { BytesRef bytesRef = binaryDocValues.get(docID()); LireFeature docFeature = lireFeature.getClass().newInstance(); docFeature.setByteArrayRepresentation(bytesRef.bytes); float distance = lireFeature.getDistance(docFeature); float score; if (Float.compare(distance, 1.0f) <= 0) { // distance less than 1, consider as same image score = 2f - distance; } else { score = 1 / distance; } return score * boost; } catch (Exception e) { throw new ElasticsearchImageProcessException("Failed to calculate score", e); } }
@Override public void collect(int doc) throws IOException { OsmObject object; BytesRef bytesRef = new BytesRef(10); context.reader().getBinaryDocValues("class_value").get(doc, bytesRef); if (class_nodeByteRef.bytesEquals(bytesRef)) { object = getNode(context.reader().getNumericDocValues("node.identity_value").get(doc)); } else if (class_wayByteRef.bytesEquals(bytesRef)) { object = getWay(context.reader().getNumericDocValues("way.identity_value").get(doc)); } else if (class_relationByteRef.bytesEquals(bytesRef)) { object = getRelation(context.reader().getNumericDocValues("relation.identity_value").get(doc)); } else { throw new RuntimeException(); } searchResults.put(object, scorer.score()); }