diff --git a/6/src/main/java/com/traveltime/plugin/solr/cache/RequestCache.java b/6/src/main/java/com/traveltime/plugin/solr/cache/RequestCache.java index 082482f..8f3d2ab 100755 --- a/6/src/main/java/com/traveltime/plugin/solr/cache/RequestCache.java +++ b/6/src/main/java/com/traveltime/plugin/solr/cache/RequestCache.java @@ -7,7 +7,7 @@ import java.util.Map; public abstract class RequestCache

extends FastLRUCache { - public static String NAME = "traveltime"; + public static final String NAME = "traveltime"; public abstract TravelTimes getOrFresh(P key); diff --git a/6/src/main/java/com/traveltime/plugin/solr/query/TravelTimeScorer.java b/6/src/main/java/com/traveltime/plugin/solr/query/TravelTimeScorer.java index dc5c49c..45cf688 100644 --- a/6/src/main/java/com/traveltime/plugin/solr/query/TravelTimeScorer.java +++ b/6/src/main/java/com/traveltime/plugin/solr/query/TravelTimeScorer.java @@ -32,11 +32,10 @@ class TravelTimeScorer extends Scorer { - private DocIdSetIterator it; + private final DocIdSetIterator it; private int doc = -1; private final float queryWeight; private final NumericDocValues docValues; - private final int limit; // Stored as a double so conversion from int to double does not have to be // done every time the score is calculated. private final double limitAsDouble; @@ -44,7 +43,6 @@ class TravelTimeScorer extends Scorer { protected TravelTimeScorer(int limit, TravelTimes travelTimes, Weight weight, float queryWeight, NumericDocValues docValues, DocIdSetIterator docs) { super(weight); - this.limit = limit; this.limitAsDouble = limit; this.travelTimes = travelTimes; this.queryWeight = queryWeight; diff --git a/7/src/main/java/com/traveltime/plugin/solr/cache/RequestCache.java b/7/src/main/java/com/traveltime/plugin/solr/cache/RequestCache.java index 082482f..8f3d2ab 100755 --- a/7/src/main/java/com/traveltime/plugin/solr/cache/RequestCache.java +++ b/7/src/main/java/com/traveltime/plugin/solr/cache/RequestCache.java @@ -7,7 +7,7 @@ import java.util.Map; public abstract class RequestCache

extends FastLRUCache { - public static String NAME = "traveltime"; + public static final String NAME = "traveltime"; public abstract TravelTimes getOrFresh(P key); diff --git a/7/src/main/java/com/traveltime/plugin/solr/query/TravelTimeScorer.java b/7/src/main/java/com/traveltime/plugin/solr/query/TravelTimeScorer.java index 9dca69e..feb48df 100644 --- a/7/src/main/java/com/traveltime/plugin/solr/query/TravelTimeScorer.java +++ b/7/src/main/java/com/traveltime/plugin/solr/query/TravelTimeScorer.java @@ -32,11 +32,10 @@ class TravelTimeScorer extends Scorer { - private DocIdSetIterator it; + private final DocIdSetIterator it; private int doc = -1; private final float boost; private final NumericDocValues docValues; - private final int limit; // Stored as a double so conversion from int to double does not have to be // done every time the score is calculated. private final double limitAsDouble; @@ -44,7 +43,6 @@ class TravelTimeScorer extends Scorer { protected TravelTimeScorer(int limit, TravelTimes travelTimes, Weight weight, float boost, NumericDocValues docValues) { super(weight); - this.limit = limit; this.limitAsDouble = limit; this.travelTimes = travelTimes; this.boost = boost; @@ -71,34 +69,6 @@ private float score(int travelTime) { return travelTime == -1.0 ? 0.0f : (float) (boost * (limitAsDouble / (limitAsDouble + travelTime))); } - /** - * Inverting the score computation is very hard due to all potential - * rounding errors, so we binary search the maximum travel time. The - * limit is set to 1 second. - */ - private int computeMaxTravelTime(float minScore, int previousMaxTravelTime) { - assert score(0) >= minScore; - if (score(previousMaxTravelTime) >= minScore) { - // minScore did not decrease enough to require an update to the max travel time - return previousMaxTravelTime; - } - assert score(previousMaxTravelTime) < minScore; - int min = 0, max = previousMaxTravelTime; - // invariant: score(min) >= minScore && score(max) < minScore - while (max - min > 1) { - int mid = (min + max) / 2; - float score = score(mid); - if (score >= minScore) { - min = mid; - } else { - max = mid; - } - } - assert score(min) >= minScore; - assert min == limit || score(min + 1) < minScore; - return min; - } - @Override public float score() throws IOException { long encodedDocumentCoordinate = docValues.longValue(); diff --git a/7/src/main/java/com/traveltime/plugin/solr/query/TraveltimeSearchQuery.java b/7/src/main/java/com/traveltime/plugin/solr/query/TraveltimeSearchQuery.java index 4d27411..5e73a5f 100755 --- a/7/src/main/java/com/traveltime/plugin/solr/query/TraveltimeSearchQuery.java +++ b/7/src/main/java/com/traveltime/plugin/solr/query/TraveltimeSearchQuery.java @@ -140,15 +140,16 @@ public Explanation explain(LeafReaderContext context, int doc) throws IOExceptio float score = travelTime == -1 ? 0.0f : (float) (boost * (limitAsDouble / (limitAsDouble + travelTime))); Coordinates queryOrigin = params.getOrigin(); - return Explanation.match(score, - params.getTransportMode() + " score, computed as, when present, boost * limit / (limit + travelTime), otherwise 0.0, from:", - Explanation.match(boost, "weight"), - Explanation.match(limit, "maximum travel time"), - Explanation.match(queryOrigin.getLat().floatValue(), "query lat"), - Explanation.match(queryOrigin.getLng().floatValue(), "query lon"), - Explanation.match((float)documentLat, "document lat"), - Explanation.match((float)documentLon, "document lon"), - Explanation.match(travelTime, "travel time") + return Explanation.match( + score, + params.getTransportMode() + " score, computed as, when present, boost * limit / (limit + travelTime), otherwise 0.0, from:", + Explanation.match(boost, "weight"), + Explanation.match(limit, "maximum travel time"), + Explanation.match(queryOrigin.getLat().floatValue(), "query lat"), + Explanation.match(queryOrigin.getLng().floatValue(), "query lon"), + Explanation.match((float) documentLat, "document lat"), + Explanation.match((float) documentLon, "document lon"), + Explanation.match(travelTime, "travel time") ); } diff --git a/8/src/main/java/com/traveltime/plugin/solr/cache/RequestCache.java b/8/src/main/java/com/traveltime/plugin/solr/cache/RequestCache.java index 43faeda..ec1df12 100755 --- a/8/src/main/java/com/traveltime/plugin/solr/cache/RequestCache.java +++ b/8/src/main/java/com/traveltime/plugin/solr/cache/RequestCache.java @@ -7,7 +7,7 @@ import java.util.Map; public abstract class RequestCache

extends FastLRUCache { - public static String NAME = "traveltime"; + public static final String NAME = "traveltime"; public abstract TravelTimes getOrFresh(P key); diff --git a/8/src/main/java/com/traveltime/plugin/solr/query/TraveltimeSearchQuery.java b/8/src/main/java/com/traveltime/plugin/solr/query/TraveltimeSearchQuery.java index 2380a2c..e42dff8 100755 --- a/8/src/main/java/com/traveltime/plugin/solr/query/TraveltimeSearchQuery.java +++ b/8/src/main/java/com/traveltime/plugin/solr/query/TraveltimeSearchQuery.java @@ -140,15 +140,16 @@ public Explanation explain(LeafReaderContext context, int doc) throws IOExceptio float score = travelTime == -1 ? 0.0f : (float) (boost * (limitAsDouble / (limitAsDouble + travelTime))); Coordinates queryOrigin = params.getOrigin(); - return Explanation.match(score, - params.getTransportMode() + " score, computed as, when present, boost * limit / (limit + travelTime), otherwise 0.0, from:", - Explanation.match(boost, "weight"), - Explanation.match(limit, "maximum travel time"), - Explanation.match(queryOrigin.getLat(), "query lat"), - Explanation.match(queryOrigin.getLng(), "query lon"), - Explanation.match(documentLat, "document lat"), - Explanation.match(documentLon, "document lon"), - Explanation.match(travelTime, "travel time") + return Explanation.match( + score, + params.getTransportMode() + " score, computed as, when present, boost * limit / (limit + travelTime), otherwise 0.0, from:", + Explanation.match(boost, "weight"), + Explanation.match(limit, "maximum travel time"), + Explanation.match(queryOrigin.getLat(), "query lat"), + Explanation.match(queryOrigin.getLng(), "query lon"), + Explanation.match(documentLat, "document lat"), + Explanation.match(documentLon, "document lon"), + Explanation.match(travelTime, "travel time") ); } diff --git a/9/src/main/java/com/traveltime/plugin/solr/cache/FuzzyTimeFilterRequestCache.java b/9/src/main/java/com/traveltime/plugin/solr/cache/FuzzyTimeFilterRequestCache.java index 69c1a01..2235d16 100755 --- a/9/src/main/java/com/traveltime/plugin/solr/cache/FuzzyTimeFilterRequestCache.java +++ b/9/src/main/java/com/traveltime/plugin/solr/cache/FuzzyTimeFilterRequestCache.java @@ -10,7 +10,7 @@ public class FuzzyTimeFilterRequestCache extends RequestCache args; @Override - public Object init(Map args, Object persistence, CacheRegenerator regenerator) { + public Object init(Map args, Object persistence, CacheRegenerator regenerator) { this.args = args; return super.init(args, persistence, regenerator); } diff --git a/9/src/main/java/com/traveltime/plugin/solr/cache/RequestCache.java b/9/src/main/java/com/traveltime/plugin/solr/cache/RequestCache.java index fde2d84..2f03a52 100755 --- a/9/src/main/java/com/traveltime/plugin/solr/cache/RequestCache.java +++ b/9/src/main/java/com/traveltime/plugin/solr/cache/RequestCache.java @@ -7,7 +7,7 @@ import java.util.Map; public abstract class RequestCache

extends CaffeineCache { - public static String NAME = "traveltime"; + public static final String NAME = "traveltime"; public abstract TravelTimes getOrFresh(P key); diff --git a/9/src/main/java/com/traveltime/plugin/solr/query/TraveltimeQueryParameters.java b/9/src/main/java/com/traveltime/plugin/solr/query/TraveltimeQueryParameters.java index 366b830..16d3592 100755 --- a/9/src/main/java/com/traveltime/plugin/solr/query/TraveltimeQueryParameters.java +++ b/9/src/main/java/com/traveltime/plugin/solr/query/TraveltimeQueryParameters.java @@ -37,7 +37,7 @@ public int getTravelTime() { private static T findByNameOrError(String what, String name, Function> finder) { val result = finder.apply(name); - if (!result.isPresent()) { + if (result.isEmpty()) { throw new IllegalArgumentException(String.format("Couldn't find a %s with the name %s", what, name)); } else { return result.get(); diff --git a/9/src/main/java/com/traveltime/plugin/solr/query/TraveltimeSearchQuery.java b/9/src/main/java/com/traveltime/plugin/solr/query/TraveltimeSearchQuery.java index 17e67bd..5a43d00 100755 --- a/9/src/main/java/com/traveltime/plugin/solr/query/TraveltimeSearchQuery.java +++ b/9/src/main/java/com/traveltime/plugin/solr/query/TraveltimeSearchQuery.java @@ -36,7 +36,6 @@ import org.apache.solr.search.SolrIndexSearcher; import java.io.IOException; -import java.util.Set; @AllArgsConstructor @EqualsAndHashCode(callSuper = false) @@ -132,15 +131,16 @@ public Explanation explain(LeafReaderContext context, int doc) throws IOExceptio float score = travelTime == -1 ? 0.0f : (float) (boost * (limitAsDouble / (limitAsDouble + travelTime))); Coordinates queryOrigin = params.getOrigin(); - return Explanation.match(score, - params.getTransportMode() + " score, computed as, when present, boost * limit / (limit + travelTime), otherwise 0.0, from:", - Explanation.match(boost, "weight"), - Explanation.match(limit, "maximum travel time"), - Explanation.match(queryOrigin.getLat(), "query lat"), - Explanation.match(queryOrigin.getLng(), "query lon"), - Explanation.match(documentLat, "document lat"), - Explanation.match(documentLon, "document lon"), - Explanation.match(travelTime, "travel time") + return Explanation.match( + score, + params.getTransportMode() + " score, computed as, when present, boost * limit / (limit + travelTime), otherwise 0.0, from:", + Explanation.match(boost, "weight"), + Explanation.match(limit, "maximum travel time"), + Explanation.match(queryOrigin.getLat(), "query lat"), + Explanation.match(queryOrigin.getLng(), "query lon"), + Explanation.match(documentLat, "document lat"), + Explanation.match(documentLon, "document lon"), + Explanation.match(travelTime, "travel time") ); }