} catch(Util.JsonParseRuntimeException e) {
throw new ApiException("InvalidBookmark", "Invalid compare JSON value in bookmark: "+e.getMessage());
}
}
Object scorePattern = options.get("score");
Iter iter = subService.query(bag, txnId, query, options);
if (scorePattern == null) {
return new SlicedIter(iter, offset, limit);
}
ScoreComponent scorer = parseScorePattern(scorePattern, ArrayBytes.EMPTY_BYTES);
while(iter.hasNext()) {
Object resultObject = iter.next();
double score;
DbResult dbResult = null;
if (resultObject instanceof DbResultMapView) {
dbResult = ((DbResultMapView)resultObject).getDbResult();
score = scorer.score(dbResult, minScore, maxScore);
} else {
score = scorer.scoreObject(resultObject, minScore, maxScore);
}
if (Double.isNaN(score)) continue;
if (score < minScore) continue;
if (score > maxScore) continue;
if (score == maxScore) {
if (dbResult.derefByKey(secondaryField).compareTo(secondaryValue) <= 0) continue;
}
// copy in an appropriate fashion
if (dbResult != null && dbResult instanceof QueryNodeDbResult) {
resultObject = new QueryNodeDbResultMarker((QueryNodeDbResult)dbResult);
// resultObject = dbResult.deepCopy();
} else {
resultObject = Util.jsonDecode(Util.jsonEncode(resultObject));
}
hits.offer(new HitRec(score, resultObject));
if (hits.size() > limit) {
hits.remove();
double newMinScore = hits.peek().score;
if (newMinScore > minScore) {
minScore = newMinScore;
Iter newIter = scorer.narrowScoreRange(minScore, maxScore, iter);
iter = newIter;
}
}
}
final int numHits = hits.size();