private void queryNearest(SimilarityResult similarityResult, DescriptionManager manager,
			LSHVector vector, QueryNearest query, String filter,
			HashMap<LSHVector, List<VectorResult>> vecToResultsMap)
			throws ElasticException, LSHException {
		List<VectorResult> resultset = new ArrayList<>();
		int vectormax = query.vectormax;
		if (vectormax == 0) {
			vectormax = MAX_VECTOR_OVERALL; // Really means a very big limit
		}

		// Check to see if we've already queried for this vector before. If so, just grab
		// the results from the map.
		if (vecToResultsMap.containsKey(vector)) {
			resultset = vecToResultsMap.get(vector);
			similarityResult.setTotalCount(getTotalCount(resultset));
		}
		else {
			// Perform the query.
			similarityResult.setTotalCount((int) queryNearestVector(resultset, vector, query.thresh,
				query.signifthresh, vectormax));

			// Put the new results in the map so we can use them if another 
			// similar vector comes along.
			vecToResultsMap.put(vector, resultset);
		}

		int count = 0;

		for (VectorResult dresult : resultset) {
			if (count >= query.max) {
				break;
			}
			final SignatureRecord srec = manager.newSignature(dresult.vec, dresult.hitcount);
			JsonArray descres;
			descres = queryVectorIdMatch(dresult.vectorid, filter, query.max - count);
			if (descres == null) {
				throw new ElasticException(
					"Error querying vectorid: " + Long.toString(dresult.vectorid));
			}
			if (descres.size() == 0) {
				if (filter != null) {
					continue; // Filter may have eliminated all results
				}
				// Otherwise this is a sign of corruption in the database
				throw new ElasticException(
					"No functions matching vectorid: " + Long.toString(dresult.vectorid));
			}
			count += descres.size();
			convertDescriptionRows(similarityResult, descres, dresult, manager, srec);
		}
	}
Query the database for functions that are similar to the given feature vector
@param similarityResult receives the list of results and their similarity to the base vector
@param manager is the DescriptionManager container for the results
@param vector is the feature vector to match
@param query contains various thresholds for the query
@param filter specifies additional conditions functions (and exes) must meet after meeting sim/signif threshold
@param vecToResultsMap is a cache of VectorResult lists from previous queries
@throws ElasticException for communication problems with the server
@throws LSHException for problems adding new records to the container
Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/elastic/ElasticDatabase.java