Hi again,
I found a possible solution using like query vector the average of every image's feature vector.
What do you think about it?
private void handleMultipleIdSearch_IDlike(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException, InstantiationException, IllegalAccessException {
SolrIndexSearcher searcher = req.getSearcher();
String[] r = req.getParams().get("M_id").split("&");
double[] vector = new double["your_dimension"];
double[] tmp = new double[
"your_dimension" ];
Query query = null;
String tmpParamField = req.getParams().get("field", "cl_ha");
if (!tmpParamField.endsWith("_ha"))
tmpParamField += "_ha";
final String paramField = tmpParamField;
GlobalFeature queryFeature = (GlobalFeature) FeatureRegistry.getClassForHashField(paramField).newInstance();
numberOfQueryTerms = req.getParams().getDouble("accuracy", DEFAULT_NUMBER_OF_QUERY_TERMS);
numberOfCandidateResults = req.getParams().getInt("candidates", DEFAULT_NUMBER_OF_CANDIDATES);
useMetricSpaces = req.getParams().getBool("ms", DEFAULT_USE_METRIC_SPACES);
int paramRows = req.getParams().getInt("rows", defaultNumberOfResults);
rsp.add("QueryField", paramField);
rsp.add("QueryFeature", queryFeature.getClass().getName());
for (String string : r) {
int queryDocId = searcher.getFirstMatch(new Term("id", string));
if (queryDocId > -1) {
BinaryDocValues binaryValues = new RandomAccessBinaryDocValues(() -> {
try {
return MultiDocValues.getBinaryValues(searcher.getIndexReader(), FeatureRegistry.getFeatureFieldName(paramField));
} catch (IOException e) {
throw new RuntimeException("BinaryDocValues problem.", e);
}
});
if (binaryValues == null)
rsp.add("Error", "Could not find the DocValues of the query document. Are they in the index? Id: " + string);
BytesRef bvBytesRef = getBytesRef(binaryValues, queryDocId);
queryFeature.setByteArrayRepresentation(bvBytesRef.bytes, bvBytesRef.offset, bvBytesRef.length);
tmp = queryFeature.getFeatureVector();
for (int i = 0; i < vector.length; i++)
vector[i] += tmp[i];
} else {
rsp.add("Error", "Did not find an image with the given id " + string);
}
}
for (int i = 0; i < vector.length; i++)
vector[i] /= (double)r.length;
rsp.add("vector", Arrays.toString(vector));
try {
if (!useMetricSpaces) {
HashTermStatistics.addToStatistics(searcher, paramField);
int[] hashes = BitSampling.generateHashes(vector);
query = createQuery(hashes, paramField, numberOfQueryTerms);
} else {
rsp.add("Error", "Feature not supported by MetricSpaces: " + queryFeature.getClass().getSimpleName());
}
doSearch(req, rsp, searcher, paramField, paramRows, getFilterQueries(req), query, queryFeature);
} catch (Exception e) {
rsp.add("Error", "There was an error with your search: " + e.getMessage());
}
}