From 4cba261ea266c9c1e3eabb6d9bc79023b8de2080 Mon Sep 17 00:00:00 2001 From: Marcin Januszkiewicz Date: Tue, 27 Aug 2024 14:04:22 +0200 Subject: [PATCH 01/24] Bump sdk version --- build.gradle | 2 +- common/build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 70eb954..d656bf6 100644 --- a/build.gradle +++ b/build.gradle @@ -35,7 +35,7 @@ configure(subprojects - common) { implementation(common) { exclude group: 'org.apache.logging.log4j' } - implementation('com.traveltime:traveltime-sdk-java:1.7.0') { + implementation('com.traveltime:traveltime-sdk-java:1.7.2') { exclude group: 'com.fasterxml.jackson.core' exclude group: 'org.locationtech.jts' } diff --git a/common/build.gradle b/common/build.gradle index d5b080e..ee34a92 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -17,7 +17,7 @@ compileJava { } dependencies { - implementation('com.traveltime:traveltime-sdk-java:1.7.0') { + implementation('com.traveltime:traveltime-sdk-java:1.7.2') { exclude group: 'com.fasterxml.jackson.core' exclude group: 'org.locationtech.jts' } From 8c2af7240b0afa908f4b0ddd2b05c1f4e726d5c8 Mon Sep 17 00:00:00 2001 From: Marcin Januszkiewicz Date: Wed, 28 Aug 2024 16:21:19 +0200 Subject: [PATCH 02/24] Implement distance querios for version 7.10 --- .../elasticsearch/TraveltimePlugin.java | 2 + .../query/TraveltimeFetchPhase.java | 15 ++++-- .../query/TraveltimeQueryBuilder.java | 14 ++++- .../query/TraveltimeQueryParser.java | 4 +- .../query/TraveltimeSearchQuery.java | 3 +- .../elasticsearch/query/TraveltimeWeight.java | 53 ++++++++++++++----- .../plugin/elasticsearch/ProtoFetcher.java | 34 +++++++++++- .../plugin/elasticsearch/TraveltimeCache.java | 3 +- .../query/TraveltimeQueryParameters.java | 1 + .../plugin/elasticsearch/util/Util.java | 12 ++++- 10 files changed, 116 insertions(+), 25 deletions(-) diff --git a/7.10/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java b/7.10/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java index 9243e37..690201c 100644 --- a/7.10/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java +++ b/7.10/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java @@ -47,6 +47,7 @@ public class TraveltimePlugin extends Plugin implements SearchPlugin { private void cleanUpAndReschedule(ThreadPool threadPool, TimeValue cleanupSeconds) { TraveltimeCache.INSTANCE.cleanUp(); + TraveltimeCache.DISTANCE.cleanUp(); threadPool.scheduleUnlessShuttingDown(cleanupSeconds, "generic", () -> cleanUpAndReschedule(threadPool, cleanupSeconds)); } @@ -57,6 +58,7 @@ public Collection createComponents(Client client, ClusterService cluster Integer cacheSize = CACHE_SIZE.get(environment.settings()); TraveltimeCache.INSTANCE.setUp(cacheSize, cacheExpiry); + TraveltimeCache.DISTANCE.setUp(cacheSize, cacheExpiry); cleanUpAndReschedule(threadPool, cleanupSeconds); return super.createComponents(client, clusterService, threadPool, resourceWatcherService, scriptService, xContentRegistry, environment, nodeEnvironment, namedWriteableRegistry, indexNameExpressionResolver, repositoriesServiceSupplier); diff --git a/7.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/7.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 5441cf5..393d983 100644 --- a/7.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/7.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -45,6 +45,7 @@ public FetchSubPhaseProcessor getProcessor(FetchContext fetchContext) { if (traveltimeQuery == null) return null; TraveltimeQueryParameters params = traveltimeQuery.getParams(); final String output = traveltimeQuery.getOutput(); + final String distanceOutput = traveltimeQuery.getDistanceOutput(); FieldFetcher fieldFetcher = FieldFetcher.create(fetchContext.mapperService(), fetchContext.searchLookup(), List.of(new FieldAndFormat(params.getField(), null))); @@ -59,10 +60,18 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if(!output.isEmpty()) { + Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if (tt >= 0) { + hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + } + } - if (tt >= 0) { - hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + if(!distanceOutput.isEmpty()) { + Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + if (td >= 0) { + hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); + } } } }; diff --git a/7.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/7.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index 2c008ec..d54d801 100644 --- a/7.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/7.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -36,6 +36,8 @@ public class TraveltimeQueryBuilder extends AbstractQueryBuilder prefilterParser = (p, c) -> AbstractQueryBuilder.parseInnerQueryBuilder(p); @@ -36,9 +37,10 @@ public class TraveltimeQueryParser implements QueryParser qb.setMode(findByNameOrError("transportation mode", s, Util::findModeByName)), mode); queryParser.declareString((qb, s) -> qb.setCountry(findByNameOrError("country", s, Util::findCountryByName)), country); - queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("country", s, Util::findRequestTypeByName)), requestType); + queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("request mode", s, Util::findRequestTypeByName)), requestType); queryParser.declareObject(TraveltimeQueryBuilder::setPrefilter, prefilterParser, prefilter); queryParser.declareString(TraveltimeQueryBuilder::setOutput, output); + queryParser.declareString(TraveltimeQueryBuilder::setDistanceOutput, distanceOutput); queryParser.declareRequiredFieldSet(field.toString()); queryParser.declareRequiredFieldSet(origin.toString()); diff --git a/7.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java b/7.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java index d359c2e..c68eab1 100644 --- a/7.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java +++ b/7.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java @@ -16,6 +16,7 @@ public class TraveltimeSearchQuery extends Query { private final TraveltimeQueryParameters params; private final Query prefilter; private final String output; + private final String distanceOutput; private final URI appUri; private final String appId; private final String apiKey; @@ -45,7 +46,7 @@ public Query rewrite(IndexReader reader) throws IOException { if (newPrefilter == prefilter) { return super.rewrite(reader); } else { - return new TraveltimeSearchQuery(params, newPrefilter, output, appUri, appId, apiKey); + return new TraveltimeSearchQuery(params, newPrefilter, output, distanceOutput, appUri, appId, apiKey); } } } diff --git a/7.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java b/7.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java index 701b099..efc8e7c 100644 --- a/7.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java +++ b/7.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java @@ -122,22 +122,49 @@ public Scorer scorer(LeafReaderContext context) throws IOException { val pointToTime = new Long2IntOpenHashMap(valueArray.size()); - val results = protoFetcher.getTimes( - ttQuery.getParams().getOrigin(), - decodedArray, - ttQuery.getParams().getLimit(), - ttQuery.getParams().getMode(), - ttQuery.getParams().getCountry(), - ttQuery.getParams().getRequestType() - ); - - for (int index = 0; index < results.size(); index++) { - if(results.get(index) >= 0) { - pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + if (ttQuery.getParams().isIncludeDistance()) { + val pointToDistance = new Long2IntOpenHashMap(valueArray.size()); + + val mode = Util.unsafeCastToDistanceTransportation(ttQuery.getParams().getMode()); + + val timeDistance = protoFetcher.getTimesAndDistances( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + mode, + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + val times = timeDistance.getLeft(); + val distances = timeDistance.getRight(); + + for (int index = 0; index < times.size(); index++) { + if (times.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), times.get(index).intValue()); + pointToDistance.put(valueArray.getLong(index), distances.get(index).intValue()); + } + } + + TraveltimeCache.DISTANCE.add(ttQuery.getParams(), pointToDistance); + } else { + val results = protoFetcher.getTimes( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + ttQuery.getParams().getMode(), + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + for (int index = 0; index < results.size(); index++) { + if (results.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + } } } - if(hasOutput) { + if (hasOutput) { TraveltimeCache.INSTANCE.add(ttQuery.getParams(), pointToTime); } diff --git a/common/src/main/java/com/traveltime/plugin/elasticsearch/ProtoFetcher.java b/common/src/main/java/com/traveltime/plugin/elasticsearch/ProtoFetcher.java index 2b313b0..3460cc8 100644 --- a/common/src/main/java/com/traveltime/plugin/elasticsearch/ProtoFetcher.java +++ b/common/src/main/java/com/traveltime/plugin/elasticsearch/ProtoFetcher.java @@ -4,15 +4,16 @@ import com.traveltime.sdk.TravelTimeSDK; import com.traveltime.sdk.auth.TravelTimeCredentials; import com.traveltime.sdk.dto.common.Coordinates; +import com.traveltime.sdk.dto.requests.TimeFilterFastProtoDistanceRequest; import com.traveltime.sdk.dto.requests.TimeFilterFastProtoRequest; import com.traveltime.sdk.dto.requests.proto.Country; import com.traveltime.sdk.dto.requests.proto.RequestType; -import com.traveltime.sdk.dto.requests.proto.Transportation; import com.traveltime.sdk.dto.responses.TimeFilterFastProtoResponse; import com.traveltime.sdk.dto.responses.errors.IOError; import com.traveltime.sdk.dto.responses.errors.ResponseError; import com.traveltime.sdk.dto.responses.errors.TravelTimeError; import lombok.val; +import org.apache.commons.lang3.tuple.Pair; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -51,7 +52,7 @@ public ProtoFetcher(URI uri, String id, String key, Supplier permiss api = Util.elevate(builder::build, permissionSupplier); } - public List getTimes(Coordinates origin, List destinations, int limit, Transportation mode, Country country, RequestType requestType) { + public List getTimes(Coordinates origin, List destinations, int limit, com.traveltime.sdk.dto.requests.proto.Transportation mode, Country country, RequestType requestType) { if(destinations.isEmpty()) { return Collections.emptyList(); } @@ -80,4 +81,33 @@ public List getTimes(Coordinates origin, List destinations ); } + public Pair, List> getTimesAndDistances(Coordinates origin, List destinations, int limit, com.traveltime.sdk.dto.requests.protodistance.Transportation mode, Country country, RequestType requestType) { + if (destinations.isEmpty()) { + return Pair.of(Collections.emptyList(), Collections.emptyList()); + } + + val fastProto = + TimeFilterFastProtoDistanceRequest + .builder() + .country(country) + .transportation(mode) + .originCoordinate(origin) + .destinationCoordinates(destinations) + .travelTime(limit) + .requestType(requestType) + .build(); + + + log.info(String.format("Fetching %d destinations", destinations.size())); + val result = Util.time(log, () -> Util.elevate(() -> api.sendProtoBatched(fastProto), permissionSupplier)); + + return result.fold( + err -> { + logError(err); + throw new RuntimeException(err.getMessage()); + }, + resp -> Pair.of(resp.getTravelTimes(), resp.getDistances()) + ); + } + } diff --git a/common/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimeCache.java b/common/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimeCache.java index 9f97d8f..a20b47c 100644 --- a/common/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimeCache.java +++ b/common/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimeCache.java @@ -14,7 +14,8 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; public enum TraveltimeCache { - INSTANCE; + INSTANCE, + DISTANCE; private static final class LockedMap { private final ReadWriteLock lock = new ReentrantReadWriteLock(); diff --git a/common/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParameters.java b/common/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParameters.java index 685aeda..39bf977 100644 --- a/common/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParameters.java +++ b/common/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParameters.java @@ -15,4 +15,5 @@ public class TraveltimeQueryParameters { @With private final Transportation mode; @With private final Country country; @With private final RequestType requestType; + @With private final boolean includeDistance; } diff --git a/common/src/main/java/com/traveltime/plugin/elasticsearch/util/Util.java b/common/src/main/java/com/traveltime/plugin/elasticsearch/util/Util.java index 6f115ba..a615864 100644 --- a/common/src/main/java/com/traveltime/plugin/elasticsearch/util/Util.java +++ b/common/src/main/java/com/traveltime/plugin/elasticsearch/util/Util.java @@ -19,8 +19,8 @@ private Util() { throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); } - public static Optional findModeByName(String name) { - return Arrays.stream(Transportation.Modes.values()).filter(it -> it.getValue().equals(name)).findFirst(); + public static Optional findModeByName(String name) { + return Arrays.stream(com.traveltime.sdk.dto.requests.proto.Transportation.Modes.values()).filter(it -> it.getValue().equals(name)).findFirst(); } public static Optional findCountryByName(String name) { @@ -31,6 +31,14 @@ public static Optional findRequestTypeByName(String name) { return Arrays.stream(RequestType.values()).filter(it -> it.name().equals(name)).findFirst(); } + public static boolean canUseDistance(com.traveltime.sdk.dto.requests.proto.Transportation transportation) { + return transportation != com.traveltime.sdk.dto.requests.proto.Transportation.Modes.PUBLIC_TRANSPORT; + } + + public static com.traveltime.sdk.dto.requests.protodistance.Transportation unsafeCastToDistanceTransportation(com.traveltime.sdk.dto.requests.proto.Transportation transportation) { + return new com.traveltime.sdk.dto.requests.protodistance.Transportation.Custom(transportation.getValue(), transportation.getCode()); + } + public static A time(Logger logger, Supplier expr) { val startTime = System.currentTimeMillis(); val res = expr.get(); From ac8bae64f8d40c08aba1ff6de8675afe76d18268 Mon Sep 17 00:00:00 2001 From: Marcin Januszkiewicz Date: Wed, 28 Aug 2024 16:41:11 +0200 Subject: [PATCH 03/24] Implement distance querios for version 7.11 --- .../elasticsearch/TraveltimePlugin.java | 2 + .../query/TraveltimeFetchPhase.java | 15 ++++-- .../query/TraveltimeQueryBuilder.java | 14 ++++- .../query/TraveltimeQueryParser.java | 4 +- .../query/TraveltimeSearchQuery.java | 3 +- .../elasticsearch/query/TraveltimeWeight.java | 53 ++++++++++++++----- 6 files changed, 71 insertions(+), 20 deletions(-) diff --git a/7.11/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java b/7.11/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java index 9243e37..690201c 100644 --- a/7.11/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java +++ b/7.11/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java @@ -47,6 +47,7 @@ public class TraveltimePlugin extends Plugin implements SearchPlugin { private void cleanUpAndReschedule(ThreadPool threadPool, TimeValue cleanupSeconds) { TraveltimeCache.INSTANCE.cleanUp(); + TraveltimeCache.DISTANCE.cleanUp(); threadPool.scheduleUnlessShuttingDown(cleanupSeconds, "generic", () -> cleanUpAndReschedule(threadPool, cleanupSeconds)); } @@ -57,6 +58,7 @@ public Collection createComponents(Client client, ClusterService cluster Integer cacheSize = CACHE_SIZE.get(environment.settings()); TraveltimeCache.INSTANCE.setUp(cacheSize, cacheExpiry); + TraveltimeCache.DISTANCE.setUp(cacheSize, cacheExpiry); cleanUpAndReschedule(threadPool, cleanupSeconds); return super.createComponents(client, clusterService, threadPool, resourceWatcherService, scriptService, xContentRegistry, environment, nodeEnvironment, namedWriteableRegistry, indexNameExpressionResolver, repositoriesServiceSupplier); diff --git a/7.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/7.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 38597d4..2e2eaec 100644 --- a/7.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/7.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -45,6 +45,7 @@ public FetchSubPhaseProcessor getProcessor(FetchContext fetchContext) { if (traveltimeQuery == null) return null; TraveltimeQueryParameters params = traveltimeQuery.getParams(); final String output = traveltimeQuery.getOutput(); + final String distanceOutput = traveltimeQuery.getDistanceOutput(); FieldFetcher fieldFetcher = FieldFetcher.create(fetchContext.getQueryShardContext(), fetchContext.searchLookup(), List.of(new FieldAndFormat(params.getField(), null))); @@ -59,10 +60,18 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if(!output.isEmpty()) { + Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if (tt >= 0) { + hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + } + } - if (tt >= 0) { - hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + if(!distanceOutput.isEmpty()) { + Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + if (td >= 0) { + hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); + } } } }; diff --git a/7.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/7.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index 36ddb61..be01bc0 100644 --- a/7.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/7.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -36,6 +36,8 @@ public class TraveltimeQueryBuilder extends AbstractQueryBuilder prefilterParser = (p, c) -> AbstractQueryBuilder.parseInnerQueryBuilder(p); @@ -36,9 +37,10 @@ public class TraveltimeQueryParser implements QueryParser qb.setMode(findByNameOrError("transportation mode", s, Util::findModeByName)), mode); queryParser.declareString((qb, s) -> qb.setCountry(findByNameOrError("country", s, Util::findCountryByName)), country); - queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("country", s, Util::findRequestTypeByName)), requestType); + queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("request mode", s, Util::findRequestTypeByName)), requestType); queryParser.declareObject(TraveltimeQueryBuilder::setPrefilter, prefilterParser, prefilter); queryParser.declareString(TraveltimeQueryBuilder::setOutput, output); + queryParser.declareString(TraveltimeQueryBuilder::setDistanceOutput, distanceOutput); queryParser.declareRequiredFieldSet(field.toString()); queryParser.declareRequiredFieldSet(origin.toString()); diff --git a/7.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java b/7.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java index d359c2e..c68eab1 100644 --- a/7.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java +++ b/7.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java @@ -16,6 +16,7 @@ public class TraveltimeSearchQuery extends Query { private final TraveltimeQueryParameters params; private final Query prefilter; private final String output; + private final String distanceOutput; private final URI appUri; private final String appId; private final String apiKey; @@ -45,7 +46,7 @@ public Query rewrite(IndexReader reader) throws IOException { if (newPrefilter == prefilter) { return super.rewrite(reader); } else { - return new TraveltimeSearchQuery(params, newPrefilter, output, appUri, appId, apiKey); + return new TraveltimeSearchQuery(params, newPrefilter, output, distanceOutput, appUri, appId, apiKey); } } } diff --git a/7.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java b/7.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java index 701b099..efc8e7c 100644 --- a/7.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java +++ b/7.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java @@ -122,22 +122,49 @@ public Scorer scorer(LeafReaderContext context) throws IOException { val pointToTime = new Long2IntOpenHashMap(valueArray.size()); - val results = protoFetcher.getTimes( - ttQuery.getParams().getOrigin(), - decodedArray, - ttQuery.getParams().getLimit(), - ttQuery.getParams().getMode(), - ttQuery.getParams().getCountry(), - ttQuery.getParams().getRequestType() - ); - - for (int index = 0; index < results.size(); index++) { - if(results.get(index) >= 0) { - pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + if (ttQuery.getParams().isIncludeDistance()) { + val pointToDistance = new Long2IntOpenHashMap(valueArray.size()); + + val mode = Util.unsafeCastToDistanceTransportation(ttQuery.getParams().getMode()); + + val timeDistance = protoFetcher.getTimesAndDistances( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + mode, + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + val times = timeDistance.getLeft(); + val distances = timeDistance.getRight(); + + for (int index = 0; index < times.size(); index++) { + if (times.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), times.get(index).intValue()); + pointToDistance.put(valueArray.getLong(index), distances.get(index).intValue()); + } + } + + TraveltimeCache.DISTANCE.add(ttQuery.getParams(), pointToDistance); + } else { + val results = protoFetcher.getTimes( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + ttQuery.getParams().getMode(), + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + for (int index = 0; index < results.size(); index++) { + if (results.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + } } } - if(hasOutput) { + if (hasOutput) { TraveltimeCache.INSTANCE.add(ttQuery.getParams(), pointToTime); } From 5baa6580409ae57112250aa0ef6922fb4c3be3ef Mon Sep 17 00:00:00 2001 From: Marcin Januszkiewicz Date: Wed, 28 Aug 2024 16:43:22 +0200 Subject: [PATCH 04/24] Implement distance querios for version 7.12 --- .../plugin/elasticsearch/TraveltimePlugin.java | 2 ++ .../elasticsearch/query/TraveltimeFetchPhase.java | 15 ++++++++++++--- .../query/TraveltimeQueryBuilder.java | 11 +++++++++-- .../query/TraveltimeQueryParser.java | 4 +++- .../query/TraveltimeSearchQuery.java | 3 ++- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/7.12/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java b/7.12/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java index 9243e37..690201c 100644 --- a/7.12/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java +++ b/7.12/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java @@ -47,6 +47,7 @@ public class TraveltimePlugin extends Plugin implements SearchPlugin { private void cleanUpAndReschedule(ThreadPool threadPool, TimeValue cleanupSeconds) { TraveltimeCache.INSTANCE.cleanUp(); + TraveltimeCache.DISTANCE.cleanUp(); threadPool.scheduleUnlessShuttingDown(cleanupSeconds, "generic", () -> cleanUpAndReschedule(threadPool, cleanupSeconds)); } @@ -57,6 +58,7 @@ public Collection createComponents(Client client, ClusterService cluster Integer cacheSize = CACHE_SIZE.get(environment.settings()); TraveltimeCache.INSTANCE.setUp(cacheSize, cacheExpiry); + TraveltimeCache.DISTANCE.setUp(cacheSize, cacheExpiry); cleanUpAndReschedule(threadPool, cleanupSeconds); return super.createComponents(client, clusterService, threadPool, resourceWatcherService, scriptService, xContentRegistry, environment, nodeEnvironment, namedWriteableRegistry, indexNameExpressionResolver, repositoriesServiceSupplier); diff --git a/7.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/7.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 13843d0..6691849 100644 --- a/7.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/7.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -45,6 +45,7 @@ public FetchSubPhaseProcessor getProcessor(FetchContext fetchContext) { if (traveltimeQuery == null) return null; TraveltimeQueryParameters params = traveltimeQuery.getParams(); final String output = traveltimeQuery.getOutput(); + final String distanceOutput = traveltimeQuery.getDistanceOutput(); FieldFetcher fieldFetcher = FieldFetcher.create(fetchContext.getSearchExecutionContext(), List.of(new FieldAndFormat(params.getField(), null))); @@ -59,10 +60,18 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if(!output.isEmpty()) { + Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if (tt >= 0) { + hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + } + } - if (tt >= 0) { - hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + if(!distanceOutput.isEmpty()) { + Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + if (td >= 0) { + hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); + } } } }; diff --git a/7.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/7.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index 13aaf3d..0d83e1c 100644 --- a/7.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/7.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -36,6 +36,8 @@ public class TraveltimeQueryBuilder extends AbstractQueryBuilder prefilterParser = (p, c) -> AbstractQueryBuilder.parseInnerQueryBuilder(p); @@ -36,9 +37,10 @@ public class TraveltimeQueryParser implements QueryParser qb.setMode(findByNameOrError("transportation mode", s, Util::findModeByName)), mode); queryParser.declareString((qb, s) -> qb.setCountry(findByNameOrError("country", s, Util::findCountryByName)), country); - queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("country", s, Util::findRequestTypeByName)), requestType); + queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("request mode", s, Util::findRequestTypeByName)), requestType); queryParser.declareObject(TraveltimeQueryBuilder::setPrefilter, prefilterParser, prefilter); queryParser.declareString(TraveltimeQueryBuilder::setOutput, output); + queryParser.declareString(TraveltimeQueryBuilder::setDistanceOutput, distanceOutput); queryParser.declareRequiredFieldSet(field.toString()); queryParser.declareRequiredFieldSet(origin.toString()); diff --git a/7.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java b/7.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java index d359c2e..c68eab1 100644 --- a/7.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java +++ b/7.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java @@ -16,6 +16,7 @@ public class TraveltimeSearchQuery extends Query { private final TraveltimeQueryParameters params; private final Query prefilter; private final String output; + private final String distanceOutput; private final URI appUri; private final String appId; private final String apiKey; @@ -45,7 +46,7 @@ public Query rewrite(IndexReader reader) throws IOException { if (newPrefilter == prefilter) { return super.rewrite(reader); } else { - return new TraveltimeSearchQuery(params, newPrefilter, output, appUri, appId, apiKey); + return new TraveltimeSearchQuery(params, newPrefilter, output, distanceOutput, appUri, appId, apiKey); } } } From 6938c1ad7e612d98dc5b42a3e76daa15076c69a8 Mon Sep 17 00:00:00 2001 From: Marcin Januszkiewicz Date: Wed, 28 Aug 2024 16:43:50 +0200 Subject: [PATCH 05/24] Implement distance querios for version 7.13 --- .../plugin/elasticsearch/TraveltimePlugin.java | 2 ++ .../elasticsearch/query/TraveltimeFetchPhase.java | 15 ++++++++++++--- .../query/TraveltimeQueryBuilder.java | 11 +++++++++-- .../query/TraveltimeQueryParser.java | 4 +++- .../query/TraveltimeSearchQuery.java | 3 ++- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/7.13/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java b/7.13/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java index 9243e37..690201c 100644 --- a/7.13/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java +++ b/7.13/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java @@ -47,6 +47,7 @@ public class TraveltimePlugin extends Plugin implements SearchPlugin { private void cleanUpAndReschedule(ThreadPool threadPool, TimeValue cleanupSeconds) { TraveltimeCache.INSTANCE.cleanUp(); + TraveltimeCache.DISTANCE.cleanUp(); threadPool.scheduleUnlessShuttingDown(cleanupSeconds, "generic", () -> cleanUpAndReschedule(threadPool, cleanupSeconds)); } @@ -57,6 +58,7 @@ public Collection createComponents(Client client, ClusterService cluster Integer cacheSize = CACHE_SIZE.get(environment.settings()); TraveltimeCache.INSTANCE.setUp(cacheSize, cacheExpiry); + TraveltimeCache.DISTANCE.setUp(cacheSize, cacheExpiry); cleanUpAndReschedule(threadPool, cleanupSeconds); return super.createComponents(client, clusterService, threadPool, resourceWatcherService, scriptService, xContentRegistry, environment, nodeEnvironment, namedWriteableRegistry, indexNameExpressionResolver, repositoriesServiceSupplier); diff --git a/7.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/7.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 13843d0..6691849 100644 --- a/7.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/7.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -45,6 +45,7 @@ public FetchSubPhaseProcessor getProcessor(FetchContext fetchContext) { if (traveltimeQuery == null) return null; TraveltimeQueryParameters params = traveltimeQuery.getParams(); final String output = traveltimeQuery.getOutput(); + final String distanceOutput = traveltimeQuery.getDistanceOutput(); FieldFetcher fieldFetcher = FieldFetcher.create(fetchContext.getSearchExecutionContext(), List.of(new FieldAndFormat(params.getField(), null))); @@ -59,10 +60,18 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if(!output.isEmpty()) { + Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if (tt >= 0) { + hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + } + } - if (tt >= 0) { - hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + if(!distanceOutput.isEmpty()) { + Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + if (td >= 0) { + hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); + } } } }; diff --git a/7.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/7.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index 13aaf3d..0d83e1c 100644 --- a/7.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/7.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -36,6 +36,8 @@ public class TraveltimeQueryBuilder extends AbstractQueryBuilder prefilterParser = (p, c) -> AbstractQueryBuilder.parseInnerQueryBuilder(p); @@ -36,9 +37,10 @@ public class TraveltimeQueryParser implements QueryParser qb.setMode(findByNameOrError("transportation mode", s, Util::findModeByName)), mode); queryParser.declareString((qb, s) -> qb.setCountry(findByNameOrError("country", s, Util::findCountryByName)), country); - queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("country", s, Util::findRequestTypeByName)), requestType); + queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("request mode", s, Util::findRequestTypeByName)), requestType); queryParser.declareObject(TraveltimeQueryBuilder::setPrefilter, prefilterParser, prefilter); queryParser.declareString(TraveltimeQueryBuilder::setOutput, output); + queryParser.declareString(TraveltimeQueryBuilder::setDistanceOutput, distanceOutput); queryParser.declareRequiredFieldSet(field.toString()); queryParser.declareRequiredFieldSet(origin.toString()); diff --git a/7.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java b/7.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java index d359c2e..c68eab1 100644 --- a/7.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java +++ b/7.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java @@ -16,6 +16,7 @@ public class TraveltimeSearchQuery extends Query { private final TraveltimeQueryParameters params; private final Query prefilter; private final String output; + private final String distanceOutput; private final URI appUri; private final String appId; private final String apiKey; @@ -45,7 +46,7 @@ public Query rewrite(IndexReader reader) throws IOException { if (newPrefilter == prefilter) { return super.rewrite(reader); } else { - return new TraveltimeSearchQuery(params, newPrefilter, output, appUri, appId, apiKey); + return new TraveltimeSearchQuery(params, newPrefilter, output, distanceOutput, appUri, appId, apiKey); } } } From 191816cd5d7d75818386a6832587e8afe69567da Mon Sep 17 00:00:00 2001 From: Marcin Januszkiewicz Date: Wed, 28 Aug 2024 16:44:05 +0200 Subject: [PATCH 06/24] Implement distance querios for version 7.14 --- .../plugin/elasticsearch/TraveltimePlugin.java | 2 ++ .../elasticsearch/query/TraveltimeFetchPhase.java | 15 ++++++++++++--- .../query/TraveltimeQueryBuilder.java | 11 +++++++++-- .../query/TraveltimeQueryParser.java | 4 +++- .../query/TraveltimeSearchQuery.java | 3 ++- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/7.14/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java b/7.14/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java index 4094846..25439cb 100644 --- a/7.14/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java +++ b/7.14/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java @@ -47,6 +47,7 @@ public class TraveltimePlugin extends Plugin implements SearchPlugin { private void cleanUpAndReschedule(ThreadPool threadPool, TimeValue cleanupSeconds) { TraveltimeCache.INSTANCE.cleanUp(); + TraveltimeCache.DISTANCE.cleanUp(); threadPool.scheduleUnlessShuttingDown(cleanupSeconds, "generic", () -> cleanUpAndReschedule(threadPool, cleanupSeconds)); } @@ -57,6 +58,7 @@ public Collection createComponents(Client client, ClusterService cluster Integer cacheSize = CACHE_SIZE.get(environment.settings()); TraveltimeCache.INSTANCE.setUp(cacheSize, cacheExpiry); + TraveltimeCache.DISTANCE.setUp(cacheSize, cacheExpiry); cleanUpAndReschedule(threadPool, cleanupSeconds); return super.createComponents(client, clusterService, threadPool, resourceWatcherService, scriptService, xContentRegistry, environment, nodeEnvironment, namedWriteableRegistry, indexNameExpressionResolver, repositoriesServiceSupplier); diff --git a/7.14/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/7.14/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 13843d0..6691849 100644 --- a/7.14/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/7.14/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -45,6 +45,7 @@ public FetchSubPhaseProcessor getProcessor(FetchContext fetchContext) { if (traveltimeQuery == null) return null; TraveltimeQueryParameters params = traveltimeQuery.getParams(); final String output = traveltimeQuery.getOutput(); + final String distanceOutput = traveltimeQuery.getDistanceOutput(); FieldFetcher fieldFetcher = FieldFetcher.create(fetchContext.getSearchExecutionContext(), List.of(new FieldAndFormat(params.getField(), null))); @@ -59,10 +60,18 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if(!output.isEmpty()) { + Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if (tt >= 0) { + hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + } + } - if (tt >= 0) { - hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + if(!distanceOutput.isEmpty()) { + Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + if (td >= 0) { + hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); + } } } }; diff --git a/7.14/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/7.14/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index 13aaf3d..0d83e1c 100644 --- a/7.14/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/7.14/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -36,6 +36,8 @@ public class TraveltimeQueryBuilder extends AbstractQueryBuilder prefilterParser = (p, c) -> AbstractQueryBuilder.parseInnerQueryBuilder(p); @@ -36,9 +37,10 @@ public class TraveltimeQueryParser implements QueryParser qb.setMode(findByNameOrError("transportation mode", s, Util::findModeByName)), mode); queryParser.declareString((qb, s) -> qb.setCountry(findByNameOrError("country", s, Util::findCountryByName)), country); - queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("country", s, Util::findRequestTypeByName)), requestType); + queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("request mode", s, Util::findRequestTypeByName)), requestType); queryParser.declareObject(TraveltimeQueryBuilder::setPrefilter, prefilterParser, prefilter); queryParser.declareString(TraveltimeQueryBuilder::setOutput, output); + queryParser.declareString(TraveltimeQueryBuilder::setDistanceOutput, distanceOutput); queryParser.declareRequiredFieldSet(field.toString()); queryParser.declareRequiredFieldSet(origin.toString()); diff --git a/7.14/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java b/7.14/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java index d359c2e..c68eab1 100644 --- a/7.14/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java +++ b/7.14/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java @@ -16,6 +16,7 @@ public class TraveltimeSearchQuery extends Query { private final TraveltimeQueryParameters params; private final Query prefilter; private final String output; + private final String distanceOutput; private final URI appUri; private final String appId; private final String apiKey; @@ -45,7 +46,7 @@ public Query rewrite(IndexReader reader) throws IOException { if (newPrefilter == prefilter) { return super.rewrite(reader); } else { - return new TraveltimeSearchQuery(params, newPrefilter, output, appUri, appId, apiKey); + return new TraveltimeSearchQuery(params, newPrefilter, output, distanceOutput, appUri, appId, apiKey); } } } From e29f4464409d2166d862d84e3da551355c6b1efe Mon Sep 17 00:00:00 2001 From: Marcin Januszkiewicz Date: Wed, 28 Aug 2024 16:44:16 +0200 Subject: [PATCH 07/24] Implement distance querios for version 7.15 --- .../plugin/elasticsearch/TraveltimePlugin.java | 2 ++ .../elasticsearch/query/TraveltimeFetchPhase.java | 15 ++++++++++++--- .../query/TraveltimeQueryBuilder.java | 11 +++++++++-- .../query/TraveltimeQueryParser.java | 4 +++- .../query/TraveltimeSearchQuery.java | 3 ++- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/7.15/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java b/7.15/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java index 4094846..25439cb 100644 --- a/7.15/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java +++ b/7.15/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java @@ -47,6 +47,7 @@ public class TraveltimePlugin extends Plugin implements SearchPlugin { private void cleanUpAndReschedule(ThreadPool threadPool, TimeValue cleanupSeconds) { TraveltimeCache.INSTANCE.cleanUp(); + TraveltimeCache.DISTANCE.cleanUp(); threadPool.scheduleUnlessShuttingDown(cleanupSeconds, "generic", () -> cleanUpAndReschedule(threadPool, cleanupSeconds)); } @@ -57,6 +58,7 @@ public Collection createComponents(Client client, ClusterService cluster Integer cacheSize = CACHE_SIZE.get(environment.settings()); TraveltimeCache.INSTANCE.setUp(cacheSize, cacheExpiry); + TraveltimeCache.DISTANCE.setUp(cacheSize, cacheExpiry); cleanUpAndReschedule(threadPool, cleanupSeconds); return super.createComponents(client, clusterService, threadPool, resourceWatcherService, scriptService, xContentRegistry, environment, nodeEnvironment, namedWriteableRegistry, indexNameExpressionResolver, repositoriesServiceSupplier); diff --git a/7.15/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/7.15/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 13843d0..6691849 100644 --- a/7.15/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/7.15/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -45,6 +45,7 @@ public FetchSubPhaseProcessor getProcessor(FetchContext fetchContext) { if (traveltimeQuery == null) return null; TraveltimeQueryParameters params = traveltimeQuery.getParams(); final String output = traveltimeQuery.getOutput(); + final String distanceOutput = traveltimeQuery.getDistanceOutput(); FieldFetcher fieldFetcher = FieldFetcher.create(fetchContext.getSearchExecutionContext(), List.of(new FieldAndFormat(params.getField(), null))); @@ -59,10 +60,18 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if(!output.isEmpty()) { + Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if (tt >= 0) { + hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + } + } - if (tt >= 0) { - hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + if(!distanceOutput.isEmpty()) { + Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + if (td >= 0) { + hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); + } } } }; diff --git a/7.15/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/7.15/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index 13aaf3d..0d83e1c 100644 --- a/7.15/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/7.15/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -36,6 +36,8 @@ public class TraveltimeQueryBuilder extends AbstractQueryBuilder prefilterParser = (p, c) -> AbstractQueryBuilder.parseInnerQueryBuilder(p); @@ -36,9 +37,10 @@ public class TraveltimeQueryParser implements QueryParser qb.setMode(findByNameOrError("transportation mode", s, Util::findModeByName)), mode); queryParser.declareString((qb, s) -> qb.setCountry(findByNameOrError("country", s, Util::findCountryByName)), country); - queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("country", s, Util::findRequestTypeByName)), requestType); + queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("request mode", s, Util::findRequestTypeByName)), requestType); queryParser.declareObject(TraveltimeQueryBuilder::setPrefilter, prefilterParser, prefilter); queryParser.declareString(TraveltimeQueryBuilder::setOutput, output); + queryParser.declareString(TraveltimeQueryBuilder::setDistanceOutput, distanceOutput); queryParser.declareRequiredFieldSet(field.toString()); queryParser.declareRequiredFieldSet(origin.toString()); diff --git a/7.15/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java b/7.15/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java index d359c2e..c68eab1 100644 --- a/7.15/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java +++ b/7.15/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java @@ -16,6 +16,7 @@ public class TraveltimeSearchQuery extends Query { private final TraveltimeQueryParameters params; private final Query prefilter; private final String output; + private final String distanceOutput; private final URI appUri; private final String appId; private final String apiKey; @@ -45,7 +46,7 @@ public Query rewrite(IndexReader reader) throws IOException { if (newPrefilter == prefilter) { return super.rewrite(reader); } else { - return new TraveltimeSearchQuery(params, newPrefilter, output, appUri, appId, apiKey); + return new TraveltimeSearchQuery(params, newPrefilter, output, distanceOutput, appUri, appId, apiKey); } } } From c2bbce952905fd2a98439f6b3811b8d059bb027a Mon Sep 17 00:00:00 2001 From: Marcin Januszkiewicz Date: Wed, 28 Aug 2024 16:44:29 +0200 Subject: [PATCH 08/24] Implement distance querios for version 7.16 --- .../plugin/elasticsearch/TraveltimePlugin.java | 2 ++ .../elasticsearch/query/TraveltimeFetchPhase.java | 15 ++++++++++++--- .../query/TraveltimeQueryBuilder.java | 11 +++++++++-- .../query/TraveltimeQueryParser.java | 4 +++- .../query/TraveltimeSearchQuery.java | 3 ++- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/7.16/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java b/7.16/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java index c7c0afc..c71c5d2 100644 --- a/7.16/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java +++ b/7.16/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java @@ -47,6 +47,7 @@ public class TraveltimePlugin extends Plugin implements SearchPlugin { private void cleanUpAndReschedule(ThreadPool threadPool, TimeValue cleanupSeconds) { TraveltimeCache.INSTANCE.cleanUp(); + TraveltimeCache.DISTANCE.cleanUp(); threadPool.scheduleUnlessShuttingDown(cleanupSeconds, "generic", () -> cleanUpAndReschedule(threadPool, cleanupSeconds)); } @@ -57,6 +58,7 @@ public Collection createComponents(Client client, ClusterService cluster Integer cacheSize = CACHE_SIZE.get(environment.settings()); TraveltimeCache.INSTANCE.setUp(cacheSize, cacheExpiry); + TraveltimeCache.DISTANCE.setUp(cacheSize, cacheExpiry); cleanUpAndReschedule(threadPool, cleanupSeconds); return super.createComponents(client, clusterService, threadPool, resourceWatcherService, scriptService, xContentRegistry, environment, nodeEnvironment, namedWriteableRegistry, indexNameExpressionResolver, repositoriesServiceSupplier); diff --git a/7.16/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/7.16/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 13843d0..6691849 100644 --- a/7.16/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/7.16/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -45,6 +45,7 @@ public FetchSubPhaseProcessor getProcessor(FetchContext fetchContext) { if (traveltimeQuery == null) return null; TraveltimeQueryParameters params = traveltimeQuery.getParams(); final String output = traveltimeQuery.getOutput(); + final String distanceOutput = traveltimeQuery.getDistanceOutput(); FieldFetcher fieldFetcher = FieldFetcher.create(fetchContext.getSearchExecutionContext(), List.of(new FieldAndFormat(params.getField(), null))); @@ -59,10 +60,18 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if(!output.isEmpty()) { + Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if (tt >= 0) { + hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + } + } - if (tt >= 0) { - hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + if(!distanceOutput.isEmpty()) { + Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + if (td >= 0) { + hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); + } } } }; diff --git a/7.16/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/7.16/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index c7dafe1..041d632 100644 --- a/7.16/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/7.16/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -36,6 +36,8 @@ public class TraveltimeQueryBuilder extends AbstractQueryBuilder prefilterParser = (p, c) -> AbstractQueryBuilder.parseInnerQueryBuilder(p); @@ -36,9 +37,10 @@ public class TraveltimeQueryParser implements QueryParser qb.setMode(findByNameOrError("transportation mode", s, Util::findModeByName)), mode); queryParser.declareString((qb, s) -> qb.setCountry(findByNameOrError("country", s, Util::findCountryByName)), country); - queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("country", s, Util::findRequestTypeByName)), requestType); + queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("request mode", s, Util::findRequestTypeByName)), requestType); queryParser.declareObject(TraveltimeQueryBuilder::setPrefilter, prefilterParser, prefilter); queryParser.declareString(TraveltimeQueryBuilder::setOutput, output); + queryParser.declareString(TraveltimeQueryBuilder::setDistanceOutput, distanceOutput); queryParser.declareRequiredFieldSet(field.toString()); queryParser.declareRequiredFieldSet(origin.toString()); diff --git a/7.16/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java b/7.16/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java index d359c2e..c68eab1 100644 --- a/7.16/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java +++ b/7.16/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java @@ -16,6 +16,7 @@ public class TraveltimeSearchQuery extends Query { private final TraveltimeQueryParameters params; private final Query prefilter; private final String output; + private final String distanceOutput; private final URI appUri; private final String appId; private final String apiKey; @@ -45,7 +46,7 @@ public Query rewrite(IndexReader reader) throws IOException { if (newPrefilter == prefilter) { return super.rewrite(reader); } else { - return new TraveltimeSearchQuery(params, newPrefilter, output, appUri, appId, apiKey); + return new TraveltimeSearchQuery(params, newPrefilter, output, distanceOutput, appUri, appId, apiKey); } } } From 1c7bffbd4c3c9c5f4bc242f07e9dee89d2576915 Mon Sep 17 00:00:00 2001 From: Marcin Januszkiewicz Date: Wed, 28 Aug 2024 16:44:45 +0200 Subject: [PATCH 09/24] Implement distance querios for version 7.17 --- .../plugin/elasticsearch/TraveltimePlugin.java | 2 ++ .../elasticsearch/query/TraveltimeFetchPhase.java | 15 ++++++++++++--- .../query/TraveltimeQueryBuilder.java | 11 +++++++++-- .../query/TraveltimeQueryParser.java | 4 +++- .../query/TraveltimeSearchQuery.java | 3 ++- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/7.17/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java b/7.17/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java index c7c0afc..c71c5d2 100644 --- a/7.17/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java +++ b/7.17/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java @@ -47,6 +47,7 @@ public class TraveltimePlugin extends Plugin implements SearchPlugin { private void cleanUpAndReschedule(ThreadPool threadPool, TimeValue cleanupSeconds) { TraveltimeCache.INSTANCE.cleanUp(); + TraveltimeCache.DISTANCE.cleanUp(); threadPool.scheduleUnlessShuttingDown(cleanupSeconds, "generic", () -> cleanUpAndReschedule(threadPool, cleanupSeconds)); } @@ -57,6 +58,7 @@ public Collection createComponents(Client client, ClusterService cluster Integer cacheSize = CACHE_SIZE.get(environment.settings()); TraveltimeCache.INSTANCE.setUp(cacheSize, cacheExpiry); + TraveltimeCache.DISTANCE.setUp(cacheSize, cacheExpiry); cleanUpAndReschedule(threadPool, cleanupSeconds); return super.createComponents(client, clusterService, threadPool, resourceWatcherService, scriptService, xContentRegistry, environment, nodeEnvironment, namedWriteableRegistry, indexNameExpressionResolver, repositoriesServiceSupplier); diff --git a/7.17/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/7.17/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 13843d0..6691849 100644 --- a/7.17/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/7.17/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -45,6 +45,7 @@ public FetchSubPhaseProcessor getProcessor(FetchContext fetchContext) { if (traveltimeQuery == null) return null; TraveltimeQueryParameters params = traveltimeQuery.getParams(); final String output = traveltimeQuery.getOutput(); + final String distanceOutput = traveltimeQuery.getDistanceOutput(); FieldFetcher fieldFetcher = FieldFetcher.create(fetchContext.getSearchExecutionContext(), List.of(new FieldAndFormat(params.getField(), null))); @@ -59,10 +60,18 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if(!output.isEmpty()) { + Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if (tt >= 0) { + hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + } + } - if (tt >= 0) { - hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + if(!distanceOutput.isEmpty()) { + Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + if (td >= 0) { + hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); + } } } }; diff --git a/7.17/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/7.17/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index c7dafe1..041d632 100644 --- a/7.17/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/7.17/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -36,6 +36,8 @@ public class TraveltimeQueryBuilder extends AbstractQueryBuilder prefilterParser = (p, c) -> AbstractQueryBuilder.parseInnerQueryBuilder(p); @@ -36,9 +37,10 @@ public class TraveltimeQueryParser implements QueryParser qb.setMode(findByNameOrError("transportation mode", s, Util::findModeByName)), mode); queryParser.declareString((qb, s) -> qb.setCountry(findByNameOrError("country", s, Util::findCountryByName)), country); - queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("country", s, Util::findRequestTypeByName)), requestType); + queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("request mode", s, Util::findRequestTypeByName)), requestType); queryParser.declareObject(TraveltimeQueryBuilder::setPrefilter, prefilterParser, prefilter); queryParser.declareString(TraveltimeQueryBuilder::setOutput, output); + queryParser.declareString(TraveltimeQueryBuilder::setDistanceOutput, distanceOutput); queryParser.declareRequiredFieldSet(field.toString()); queryParser.declareRequiredFieldSet(origin.toString()); diff --git a/7.17/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java b/7.17/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java index d359c2e..c68eab1 100644 --- a/7.17/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java +++ b/7.17/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java @@ -16,6 +16,7 @@ public class TraveltimeSearchQuery extends Query { private final TraveltimeQueryParameters params; private final Query prefilter; private final String output; + private final String distanceOutput; private final URI appUri; private final String appId; private final String apiKey; @@ -45,7 +46,7 @@ public Query rewrite(IndexReader reader) throws IOException { if (newPrefilter == prefilter) { return super.rewrite(reader); } else { - return new TraveltimeSearchQuery(params, newPrefilter, output, appUri, appId, apiKey); + return new TraveltimeSearchQuery(params, newPrefilter, output, distanceOutput, appUri, appId, apiKey); } } } From c97f6da4f3fba7742ae62a50ea71ebe28c566a7c Mon Sep 17 00:00:00 2001 From: Marcin Januszkiewicz Date: Wed, 28 Aug 2024 16:46:15 +0200 Subject: [PATCH 10/24] Implement distance queries for version 8.0-8.3 --- .../plugin/elasticsearch/TraveltimePlugin.java | 2 ++ .../elasticsearch/query/TraveltimeFetchPhase.java | 15 ++++++++++++--- .../query/TraveltimeQueryBuilder.java | 11 +++++++++-- .../query/TraveltimeQueryParser.java | 4 +++- .../query/TraveltimeSearchQuery.java | 3 ++- .../plugin/elasticsearch/TraveltimePlugin.java | 2 ++ .../elasticsearch/query/TraveltimeFetchPhase.java | 15 ++++++++++++--- .../query/TraveltimeQueryBuilder.java | 11 +++++++++-- .../query/TraveltimeQueryParser.java | 4 +++- .../query/TraveltimeSearchQuery.java | 3 ++- .../plugin/elasticsearch/TraveltimePlugin.java | 2 ++ .../elasticsearch/query/TraveltimeFetchPhase.java | 15 ++++++++++++--- .../query/TraveltimeQueryBuilder.java | 11 +++++++++-- .../query/TraveltimeQueryParser.java | 4 +++- .../query/TraveltimeSearchQuery.java | 3 ++- .../plugin/elasticsearch/TraveltimePlugin.java | 2 ++ .../elasticsearch/query/TraveltimeFetchPhase.java | 15 ++++++++++++--- .../query/TraveltimeQueryBuilder.java | 11 +++++++++-- .../query/TraveltimeQueryParser.java | 4 +++- .../query/TraveltimeSearchQuery.java | 3 ++- 20 files changed, 112 insertions(+), 28 deletions(-) diff --git a/8.0/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java b/8.0/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java index c7c0afc..c71c5d2 100644 --- a/8.0/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java +++ b/8.0/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java @@ -47,6 +47,7 @@ public class TraveltimePlugin extends Plugin implements SearchPlugin { private void cleanUpAndReschedule(ThreadPool threadPool, TimeValue cleanupSeconds) { TraveltimeCache.INSTANCE.cleanUp(); + TraveltimeCache.DISTANCE.cleanUp(); threadPool.scheduleUnlessShuttingDown(cleanupSeconds, "generic", () -> cleanUpAndReschedule(threadPool, cleanupSeconds)); } @@ -57,6 +58,7 @@ public Collection createComponents(Client client, ClusterService cluster Integer cacheSize = CACHE_SIZE.get(environment.settings()); TraveltimeCache.INSTANCE.setUp(cacheSize, cacheExpiry); + TraveltimeCache.DISTANCE.setUp(cacheSize, cacheExpiry); cleanUpAndReschedule(threadPool, cleanupSeconds); return super.createComponents(client, clusterService, threadPool, resourceWatcherService, scriptService, xContentRegistry, environment, nodeEnvironment, namedWriteableRegistry, indexNameExpressionResolver, repositoriesServiceSupplier); diff --git a/8.0/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/8.0/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 13843d0..6691849 100644 --- a/8.0/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/8.0/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -45,6 +45,7 @@ public FetchSubPhaseProcessor getProcessor(FetchContext fetchContext) { if (traveltimeQuery == null) return null; TraveltimeQueryParameters params = traveltimeQuery.getParams(); final String output = traveltimeQuery.getOutput(); + final String distanceOutput = traveltimeQuery.getDistanceOutput(); FieldFetcher fieldFetcher = FieldFetcher.create(fetchContext.getSearchExecutionContext(), List.of(new FieldAndFormat(params.getField(), null))); @@ -59,10 +60,18 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if(!output.isEmpty()) { + Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if (tt >= 0) { + hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + } + } - if (tt >= 0) { - hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + if(!distanceOutput.isEmpty()) { + Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + if (td >= 0) { + hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); + } } } }; diff --git a/8.0/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/8.0/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index c7dafe1..041d632 100644 --- a/8.0/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/8.0/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -36,6 +36,8 @@ public class TraveltimeQueryBuilder extends AbstractQueryBuilder prefilterParser = (p, c) -> AbstractQueryBuilder.parseInnerQueryBuilder(p); @@ -36,9 +37,10 @@ public class TraveltimeQueryParser implements QueryParser qb.setMode(findByNameOrError("transportation mode", s, Util::findModeByName)), mode); queryParser.declareString((qb, s) -> qb.setCountry(findByNameOrError("country", s, Util::findCountryByName)), country); - queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("country", s, Util::findRequestTypeByName)), requestType); + queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("request mode", s, Util::findRequestTypeByName)), requestType); queryParser.declareObject(TraveltimeQueryBuilder::setPrefilter, prefilterParser, prefilter); queryParser.declareString(TraveltimeQueryBuilder::setOutput, output); + queryParser.declareString(TraveltimeQueryBuilder::setDistanceOutput, distanceOutput); queryParser.declareRequiredFieldSet(field.toString()); queryParser.declareRequiredFieldSet(origin.toString()); diff --git a/8.0/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java b/8.0/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java index 6826002..7ec036d 100644 --- a/8.0/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java +++ b/8.0/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java @@ -16,6 +16,7 @@ public class TraveltimeSearchQuery extends Query { private final TraveltimeQueryParameters params; private final Query prefilter; private final String output; + private final String distanceOutput; private final URI appUri; private final String appId; private final String apiKey; @@ -45,7 +46,7 @@ public Query rewrite(IndexReader reader) throws IOException { if (newPrefilter == prefilter) { return super.rewrite(reader); } else { - return new TraveltimeSearchQuery(params, newPrefilter, output, appUri, appId, apiKey); + return new TraveltimeSearchQuery(params, newPrefilter, output, distanceOutput, appUri, appId, apiKey); } } } diff --git a/8.1/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java b/8.1/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java index a750ec1..e598a70 100644 --- a/8.1/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java +++ b/8.1/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java @@ -47,6 +47,7 @@ public class TraveltimePlugin extends Plugin implements SearchPlugin { private void cleanUpAndReschedule(ThreadPool threadPool, TimeValue cleanupSeconds) { TraveltimeCache.INSTANCE.cleanUp(); + TraveltimeCache.DISTANCE.cleanUp(); threadPool.scheduleUnlessShuttingDown(cleanupSeconds, "generic", () -> cleanUpAndReschedule(threadPool, cleanupSeconds)); } @@ -57,6 +58,7 @@ public Collection createComponents(Client client, ClusterService cluster Integer cacheSize = CACHE_SIZE.get(environment.settings()); TraveltimeCache.INSTANCE.setUp(cacheSize, cacheExpiry); + TraveltimeCache.DISTANCE.setUp(cacheSize, cacheExpiry); cleanUpAndReschedule(threadPool, cleanupSeconds); return super.createComponents(client, clusterService, threadPool, resourceWatcherService, scriptService, xContentRegistry, environment, nodeEnvironment, namedWriteableRegistry, indexNameExpressionResolver, repositoriesServiceSupplier); diff --git a/8.1/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/8.1/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 13843d0..6691849 100644 --- a/8.1/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/8.1/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -45,6 +45,7 @@ public FetchSubPhaseProcessor getProcessor(FetchContext fetchContext) { if (traveltimeQuery == null) return null; TraveltimeQueryParameters params = traveltimeQuery.getParams(); final String output = traveltimeQuery.getOutput(); + final String distanceOutput = traveltimeQuery.getDistanceOutput(); FieldFetcher fieldFetcher = FieldFetcher.create(fetchContext.getSearchExecutionContext(), List.of(new FieldAndFormat(params.getField(), null))); @@ -59,10 +60,18 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if(!output.isEmpty()) { + Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if (tt >= 0) { + hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + } + } - if (tt >= 0) { - hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + if(!distanceOutput.isEmpty()) { + Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + if (td >= 0) { + hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); + } } } }; diff --git a/8.1/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/8.1/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index c7dafe1..041d632 100644 --- a/8.1/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/8.1/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -36,6 +36,8 @@ public class TraveltimeQueryBuilder extends AbstractQueryBuilder prefilterParser = (p, c) -> AbstractQueryBuilder.parseInnerQueryBuilder(p); @@ -36,9 +37,10 @@ public class TraveltimeQueryParser implements QueryParser qb.setMode(findByNameOrError("transportation mode", s, Util::findModeByName)), mode); queryParser.declareString((qb, s) -> qb.setCountry(findByNameOrError("country", s, Util::findCountryByName)), country); - queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("country", s, Util::findRequestTypeByName)), requestType); + queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("request mode", s, Util::findRequestTypeByName)), requestType); queryParser.declareObject(TraveltimeQueryBuilder::setPrefilter, prefilterParser, prefilter); queryParser.declareString(TraveltimeQueryBuilder::setOutput, output); + queryParser.declareString(TraveltimeQueryBuilder::setDistanceOutput, distanceOutput); queryParser.declareRequiredFieldSet(field.toString()); queryParser.declareRequiredFieldSet(origin.toString()); diff --git a/8.1/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java b/8.1/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java index 6826002..7ec036d 100644 --- a/8.1/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java +++ b/8.1/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java @@ -16,6 +16,7 @@ public class TraveltimeSearchQuery extends Query { private final TraveltimeQueryParameters params; private final Query prefilter; private final String output; + private final String distanceOutput; private final URI appUri; private final String appId; private final String apiKey; @@ -45,7 +46,7 @@ public Query rewrite(IndexReader reader) throws IOException { if (newPrefilter == prefilter) { return super.rewrite(reader); } else { - return new TraveltimeSearchQuery(params, newPrefilter, output, appUri, appId, apiKey); + return new TraveltimeSearchQuery(params, newPrefilter, output, distanceOutput, appUri, appId, apiKey); } } } diff --git a/8.2/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java b/8.2/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java index a750ec1..e598a70 100644 --- a/8.2/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java +++ b/8.2/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java @@ -47,6 +47,7 @@ public class TraveltimePlugin extends Plugin implements SearchPlugin { private void cleanUpAndReschedule(ThreadPool threadPool, TimeValue cleanupSeconds) { TraveltimeCache.INSTANCE.cleanUp(); + TraveltimeCache.DISTANCE.cleanUp(); threadPool.scheduleUnlessShuttingDown(cleanupSeconds, "generic", () -> cleanUpAndReschedule(threadPool, cleanupSeconds)); } @@ -57,6 +58,7 @@ public Collection createComponents(Client client, ClusterService cluster Integer cacheSize = CACHE_SIZE.get(environment.settings()); TraveltimeCache.INSTANCE.setUp(cacheSize, cacheExpiry); + TraveltimeCache.DISTANCE.setUp(cacheSize, cacheExpiry); cleanUpAndReschedule(threadPool, cleanupSeconds); return super.createComponents(client, clusterService, threadPool, resourceWatcherService, scriptService, xContentRegistry, environment, nodeEnvironment, namedWriteableRegistry, indexNameExpressionResolver, repositoriesServiceSupplier); diff --git a/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 13843d0..6691849 100644 --- a/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -45,6 +45,7 @@ public FetchSubPhaseProcessor getProcessor(FetchContext fetchContext) { if (traveltimeQuery == null) return null; TraveltimeQueryParameters params = traveltimeQuery.getParams(); final String output = traveltimeQuery.getOutput(); + final String distanceOutput = traveltimeQuery.getDistanceOutput(); FieldFetcher fieldFetcher = FieldFetcher.create(fetchContext.getSearchExecutionContext(), List.of(new FieldAndFormat(params.getField(), null))); @@ -59,10 +60,18 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if(!output.isEmpty()) { + Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if (tt >= 0) { + hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + } + } - if (tt >= 0) { - hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + if(!distanceOutput.isEmpty()) { + Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + if (td >= 0) { + hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); + } } } }; diff --git a/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index e35b5c6..1256faa 100644 --- a/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -37,6 +37,8 @@ public class TraveltimeQueryBuilder extends AbstractQueryBuilder prefilterParser = (p, c) -> AbstractQueryBuilder.parseInnerQueryBuilder(p); @@ -36,9 +37,10 @@ public class TraveltimeQueryParser implements QueryParser qb.setMode(findByNameOrError("transportation mode", s, Util::findModeByName)), mode); queryParser.declareString((qb, s) -> qb.setCountry(findByNameOrError("country", s, Util::findCountryByName)), country); - queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("country", s, Util::findRequestTypeByName)), requestType); + queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("request mode", s, Util::findRequestTypeByName)), requestType); queryParser.declareObject(TraveltimeQueryBuilder::setPrefilter, prefilterParser, prefilter); queryParser.declareString(TraveltimeQueryBuilder::setOutput, output); + queryParser.declareString(TraveltimeQueryBuilder::setDistanceOutput, distanceOutput); queryParser.declareRequiredFieldSet(field.toString()); queryParser.declareRequiredFieldSet(origin.toString()); diff --git a/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java b/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java index 6826002..7ec036d 100644 --- a/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java +++ b/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java @@ -16,6 +16,7 @@ public class TraveltimeSearchQuery extends Query { private final TraveltimeQueryParameters params; private final Query prefilter; private final String output; + private final String distanceOutput; private final URI appUri; private final String appId; private final String apiKey; @@ -45,7 +46,7 @@ public Query rewrite(IndexReader reader) throws IOException { if (newPrefilter == prefilter) { return super.rewrite(reader); } else { - return new TraveltimeSearchQuery(params, newPrefilter, output, appUri, appId, apiKey); + return new TraveltimeSearchQuery(params, newPrefilter, output, distanceOutput, appUri, appId, apiKey); } } } diff --git a/8.3/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java b/8.3/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java index a750ec1..e598a70 100644 --- a/8.3/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java +++ b/8.3/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java @@ -47,6 +47,7 @@ public class TraveltimePlugin extends Plugin implements SearchPlugin { private void cleanUpAndReschedule(ThreadPool threadPool, TimeValue cleanupSeconds) { TraveltimeCache.INSTANCE.cleanUp(); + TraveltimeCache.DISTANCE.cleanUp(); threadPool.scheduleUnlessShuttingDown(cleanupSeconds, "generic", () -> cleanUpAndReschedule(threadPool, cleanupSeconds)); } @@ -57,6 +58,7 @@ public Collection createComponents(Client client, ClusterService cluster Integer cacheSize = CACHE_SIZE.get(environment.settings()); TraveltimeCache.INSTANCE.setUp(cacheSize, cacheExpiry); + TraveltimeCache.DISTANCE.setUp(cacheSize, cacheExpiry); cleanUpAndReschedule(threadPool, cleanupSeconds); return super.createComponents(client, clusterService, threadPool, resourceWatcherService, scriptService, xContentRegistry, environment, nodeEnvironment, namedWriteableRegistry, indexNameExpressionResolver, repositoriesServiceSupplier); diff --git a/8.3/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/8.3/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 13843d0..6691849 100644 --- a/8.3/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/8.3/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -45,6 +45,7 @@ public FetchSubPhaseProcessor getProcessor(FetchContext fetchContext) { if (traveltimeQuery == null) return null; TraveltimeQueryParameters params = traveltimeQuery.getParams(); final String output = traveltimeQuery.getOutput(); + final String distanceOutput = traveltimeQuery.getDistanceOutput(); FieldFetcher fieldFetcher = FieldFetcher.create(fetchContext.getSearchExecutionContext(), List.of(new FieldAndFormat(params.getField(), null))); @@ -59,10 +60,18 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if(!output.isEmpty()) { + Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if (tt >= 0) { + hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + } + } - if (tt >= 0) { - hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + if(!distanceOutput.isEmpty()) { + Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + if (td >= 0) { + hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); + } } } }; diff --git a/8.3/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/8.3/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index e35b5c6..1256faa 100644 --- a/8.3/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/8.3/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -37,6 +37,8 @@ public class TraveltimeQueryBuilder extends AbstractQueryBuilder prefilterParser = (p, c) -> AbstractQueryBuilder.parseInnerQueryBuilder(p); @@ -36,9 +37,10 @@ public class TraveltimeQueryParser implements QueryParser qb.setMode(findByNameOrError("transportation mode", s, Util::findModeByName)), mode); queryParser.declareString((qb, s) -> qb.setCountry(findByNameOrError("country", s, Util::findCountryByName)), country); - queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("country", s, Util::findRequestTypeByName)), requestType); + queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("request mode", s, Util::findRequestTypeByName)), requestType); queryParser.declareObject(TraveltimeQueryBuilder::setPrefilter, prefilterParser, prefilter); queryParser.declareString(TraveltimeQueryBuilder::setOutput, output); + queryParser.declareString(TraveltimeQueryBuilder::setDistanceOutput, distanceOutput); queryParser.declareRequiredFieldSet(field.toString()); queryParser.declareRequiredFieldSet(origin.toString()); diff --git a/8.3/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java b/8.3/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java index 6826002..7ec036d 100644 --- a/8.3/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java +++ b/8.3/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java @@ -16,6 +16,7 @@ public class TraveltimeSearchQuery extends Query { private final TraveltimeQueryParameters params; private final Query prefilter; private final String output; + private final String distanceOutput; private final URI appUri; private final String appId; private final String apiKey; @@ -45,7 +46,7 @@ public Query rewrite(IndexReader reader) throws IOException { if (newPrefilter == prefilter) { return super.rewrite(reader); } else { - return new TraveltimeSearchQuery(params, newPrefilter, output, appUri, appId, apiKey); + return new TraveltimeSearchQuery(params, newPrefilter, output, distanceOutput, appUri, appId, apiKey); } } } From 96d080735a6ff9de89e7ac812e90d5523788d5cf Mon Sep 17 00:00:00 2001 From: Marcin Januszkiewicz Date: Wed, 28 Aug 2024 16:46:59 +0200 Subject: [PATCH 11/24] Implement distance queries for version 8.5 --- .../plugin/elasticsearch/TraveltimePlugin.java | 2 ++ .../elasticsearch/query/TraveltimeFetchPhase.java | 15 ++++++++++++--- .../query/TraveltimeQueryBuilder.java | 11 +++++++++-- .../query/TraveltimeQueryParser.java | 4 +++- .../query/TraveltimeSearchQuery.java | 3 ++- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/8.4/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java b/8.4/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java index 49b3cb6..780ae25 100644 --- a/8.4/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java +++ b/8.4/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java @@ -48,6 +48,7 @@ public class TraveltimePlugin extends Plugin implements SearchPlugin { private void cleanUpAndReschedule(ThreadPool threadPool, TimeValue cleanupSeconds) { TraveltimeCache.INSTANCE.cleanUp(); + TraveltimeCache.DISTANCE.cleanUp(); threadPool.scheduleUnlessShuttingDown(cleanupSeconds, "generic", () -> cleanUpAndReschedule(threadPool, cleanupSeconds)); } @@ -58,6 +59,7 @@ public Collection createComponents(Client client, ClusterService cluster Integer cacheSize = CACHE_SIZE.get(environment.settings()); TraveltimeCache.INSTANCE.setUp(cacheSize, cacheExpiry); + TraveltimeCache.DISTANCE.setUp(cacheSize, cacheExpiry); cleanUpAndReschedule(threadPool, cleanupSeconds); return super.createComponents(client, clusterService, threadPool, resourceWatcherService, scriptService, xContentRegistry, environment, nodeEnvironment, namedWriteableRegistry, indexNameExpressionResolver, repositoriesServiceSupplier, tracer); diff --git a/8.4/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/8.4/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 13843d0..6691849 100644 --- a/8.4/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/8.4/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -45,6 +45,7 @@ public FetchSubPhaseProcessor getProcessor(FetchContext fetchContext) { if (traveltimeQuery == null) return null; TraveltimeQueryParameters params = traveltimeQuery.getParams(); final String output = traveltimeQuery.getOutput(); + final String distanceOutput = traveltimeQuery.getDistanceOutput(); FieldFetcher fieldFetcher = FieldFetcher.create(fetchContext.getSearchExecutionContext(), List.of(new FieldAndFormat(params.getField(), null))); @@ -59,10 +60,18 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if(!output.isEmpty()) { + Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if (tt >= 0) { + hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + } + } - if (tt >= 0) { - hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + if(!distanceOutput.isEmpty()) { + Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + if (td >= 0) { + hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); + } } } }; diff --git a/8.4/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/8.4/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index e35b5c6..1256faa 100644 --- a/8.4/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/8.4/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -37,6 +37,8 @@ public class TraveltimeQueryBuilder extends AbstractQueryBuilder prefilterParser = (p, c) -> AbstractQueryBuilder.parseInnerQueryBuilder(p); @@ -36,9 +37,10 @@ public class TraveltimeQueryParser implements QueryParser qb.setMode(findByNameOrError("transportation mode", s, Util::findModeByName)), mode); queryParser.declareString((qb, s) -> qb.setCountry(findByNameOrError("country", s, Util::findCountryByName)), country); - queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("country", s, Util::findRequestTypeByName)), requestType); + queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("request mode", s, Util::findRequestTypeByName)), requestType); queryParser.declareObject(TraveltimeQueryBuilder::setPrefilter, prefilterParser, prefilter); queryParser.declareString(TraveltimeQueryBuilder::setOutput, output); + queryParser.declareString(TraveltimeQueryBuilder::setDistanceOutput, distanceOutput); queryParser.declareRequiredFieldSet(field.toString()); queryParser.declareRequiredFieldSet(origin.toString()); diff --git a/8.4/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java b/8.4/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java index 6826002..7ec036d 100644 --- a/8.4/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java +++ b/8.4/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java @@ -16,6 +16,7 @@ public class TraveltimeSearchQuery extends Query { private final TraveltimeQueryParameters params; private final Query prefilter; private final String output; + private final String distanceOutput; private final URI appUri; private final String appId; private final String apiKey; @@ -45,7 +46,7 @@ public Query rewrite(IndexReader reader) throws IOException { if (newPrefilter == prefilter) { return super.rewrite(reader); } else { - return new TraveltimeSearchQuery(params, newPrefilter, output, appUri, appId, apiKey); + return new TraveltimeSearchQuery(params, newPrefilter, output, distanceOutput, appUri, appId, apiKey); } } } From f64b2d98916bfb8848e7e2645daaa118a7bbc5ee Mon Sep 17 00:00:00 2001 From: Marcin Januszkiewicz Date: Wed, 28 Aug 2024 16:50:22 +0200 Subject: [PATCH 12/24] Implement distance queries for version 8.5-8.6 --- .../plugin/elasticsearch/TraveltimePlugin.java | 2 ++ .../elasticsearch/query/TraveltimeFetchPhase.java | 15 ++++++++++++--- .../query/TraveltimeQueryBuilder.java | 11 +++++++++-- .../query/TraveltimeQueryParser.java | 4 +++- .../query/TraveltimeSearchQuery.java | 3 ++- .../plugin/elasticsearch/TraveltimePlugin.java | 2 ++ .../elasticsearch/query/TraveltimeFetchPhase.java | 15 ++++++++++++--- .../query/TraveltimeQueryBuilder.java | 11 +++++++++-- .../query/TraveltimeQueryParser.java | 4 +++- .../query/TraveltimeSearchQuery.java | 3 ++- 10 files changed, 56 insertions(+), 14 deletions(-) diff --git a/8.5/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java b/8.5/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java index d451511..df539c7 100644 --- a/8.5/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java +++ b/8.5/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java @@ -49,6 +49,7 @@ public class TraveltimePlugin extends Plugin implements SearchPlugin { private void cleanUpAndReschedule(ThreadPool threadPool, TimeValue cleanupSeconds) { TraveltimeCache.INSTANCE.cleanUp(); + TraveltimeCache.DISTANCE.cleanUp(); threadPool.scheduleUnlessShuttingDown(cleanupSeconds, "generic", () -> cleanUpAndReschedule(threadPool, cleanupSeconds)); } @@ -59,6 +60,7 @@ public Collection createComponents(Client client, ClusterService cluster Integer cacheSize = CACHE_SIZE.get(environment.settings()); TraveltimeCache.INSTANCE.setUp(cacheSize, cacheExpiry); + TraveltimeCache.DISTANCE.setUp(cacheSize, cacheExpiry); cleanUpAndReschedule(threadPool, cleanupSeconds); return super.createComponents(client, clusterService, threadPool, resourceWatcherService, scriptService, xContentRegistry, environment, nodeEnvironment, namedWriteableRegistry, indexNameExpressionResolver, repositoriesServiceSupplier, tracer, allocationDeciders); diff --git a/8.5/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/8.5/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 13843d0..6691849 100644 --- a/8.5/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/8.5/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -45,6 +45,7 @@ public FetchSubPhaseProcessor getProcessor(FetchContext fetchContext) { if (traveltimeQuery == null) return null; TraveltimeQueryParameters params = traveltimeQuery.getParams(); final String output = traveltimeQuery.getOutput(); + final String distanceOutput = traveltimeQuery.getDistanceOutput(); FieldFetcher fieldFetcher = FieldFetcher.create(fetchContext.getSearchExecutionContext(), List.of(new FieldAndFormat(params.getField(), null))); @@ -59,10 +60,18 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if(!output.isEmpty()) { + Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if (tt >= 0) { + hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + } + } - if (tt >= 0) { - hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + if(!distanceOutput.isEmpty()) { + Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + if (td >= 0) { + hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); + } } } }; diff --git a/8.5/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/8.5/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index a48aa02..09ad195 100644 --- a/8.5/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/8.5/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -37,6 +37,8 @@ public class TraveltimeQueryBuilder extends AbstractQueryBuilder prefilterParser = (p, c) -> AbstractQueryBuilder.parseInnerQueryBuilder(p); @@ -36,9 +37,10 @@ public class TraveltimeQueryParser implements QueryParser qb.setMode(findByNameOrError("transportation mode", s, Util::findModeByName)), mode); queryParser.declareString((qb, s) -> qb.setCountry(findByNameOrError("country", s, Util::findCountryByName)), country); - queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("country", s, Util::findRequestTypeByName)), requestType); + queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("request mode", s, Util::findRequestTypeByName)), requestType); queryParser.declareObject(TraveltimeQueryBuilder::setPrefilter, prefilterParser, prefilter); queryParser.declareString(TraveltimeQueryBuilder::setOutput, output); + queryParser.declareString(TraveltimeQueryBuilder::setDistanceOutput, distanceOutput); queryParser.declareRequiredFieldSet(field.toString()); queryParser.declareRequiredFieldSet(origin.toString()); diff --git a/8.5/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java b/8.5/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java index 6826002..7ec036d 100644 --- a/8.5/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java +++ b/8.5/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java @@ -16,6 +16,7 @@ public class TraveltimeSearchQuery extends Query { private final TraveltimeQueryParameters params; private final Query prefilter; private final String output; + private final String distanceOutput; private final URI appUri; private final String appId; private final String apiKey; @@ -45,7 +46,7 @@ public Query rewrite(IndexReader reader) throws IOException { if (newPrefilter == prefilter) { return super.rewrite(reader); } else { - return new TraveltimeSearchQuery(params, newPrefilter, output, appUri, appId, apiKey); + return new TraveltimeSearchQuery(params, newPrefilter, output, distanceOutput, appUri, appId, apiKey); } } } diff --git a/8.6/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java b/8.6/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java index 2d2f51f..e11294e 100644 --- a/8.6/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java +++ b/8.6/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java @@ -49,6 +49,7 @@ public class TraveltimePlugin extends Plugin implements SearchPlugin { private void cleanUpAndReschedule(ThreadPool threadPool, TimeValue cleanupSeconds) { TraveltimeCache.INSTANCE.cleanUp(); + TraveltimeCache.DISTANCE.cleanUp(); threadPool.scheduleUnlessShuttingDown(cleanupSeconds, "generic", () -> cleanUpAndReschedule(threadPool, cleanupSeconds)); } @@ -73,6 +74,7 @@ public Collection createComponents( Integer cacheSize = CACHE_SIZE.get(environment.settings()); TraveltimeCache.INSTANCE.setUp(cacheSize, cacheExpiry); + TraveltimeCache.DISTANCE.setUp(cacheSize, cacheExpiry); cleanUpAndReschedule(threadPool, cleanupSeconds); return super.createComponents(client, clusterService, threadPool, resourceWatcherService, scriptService, xContentRegistry, environment, nodeEnvironment, namedWriteableRegistry, indexNameExpressionResolver, repositoriesServiceSupplier, tracer, allocationService); diff --git a/8.6/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/8.6/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 019a235..34ccd96 100644 --- a/8.6/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/8.6/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -47,6 +47,7 @@ public FetchSubPhaseProcessor getProcessor(FetchContext fetchContext) { if (traveltimeQuery == null) return null; TraveltimeQueryParameters params = traveltimeQuery.getParams(); final String output = traveltimeQuery.getOutput(); + final String distanceOutput = traveltimeQuery.getDistanceOutput(); FieldFetcher fieldFetcher = FieldFetcher.create(fetchContext.getSearchExecutionContext(), List.of(new FieldAndFormat(params.getField(), null))); @@ -61,10 +62,18 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if (!output.isEmpty()) { + Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if (tt >= 0) { + hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + } + } - if (tt >= 0) { - hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + if (!distanceOutput.isEmpty()) { + Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + if (td >= 0) { + hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); + } } } diff --git a/8.6/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/8.6/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index 2ff750c..a126374 100644 --- a/8.6/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/8.6/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -38,6 +38,8 @@ public class TraveltimeQueryBuilder extends AbstractQueryBuilder prefilterParser = (p, c) -> TraveltimeQueryBuilder.parseInnerQueryBuilder(p); @@ -35,9 +36,10 @@ public class TraveltimeQueryParser implements QueryParser qb.setMode(findByNameOrError("transportation mode", s, Util::findModeByName)), mode); queryParser.declareString((qb, s) -> qb.setCountry(findByNameOrError("country", s, Util::findCountryByName)), country); - queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("country", s, Util::findRequestTypeByName)), requestType); + queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("request mode", s, Util::findRequestTypeByName)), requestType); queryParser.declareObject(TraveltimeQueryBuilder::setPrefilter, prefilterParser, prefilter); queryParser.declareString(TraveltimeQueryBuilder::setOutput, output); + queryParser.declareString(TraveltimeQueryBuilder::setDistanceOutput, distanceOutput); queryParser.declareRequiredFieldSet(field.toString()); queryParser.declareRequiredFieldSet(origin.toString()); diff --git a/8.6/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java b/8.6/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java index 6826002..7ec036d 100644 --- a/8.6/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java +++ b/8.6/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java @@ -16,6 +16,7 @@ public class TraveltimeSearchQuery extends Query { private final TraveltimeQueryParameters params; private final Query prefilter; private final String output; + private final String distanceOutput; private final URI appUri; private final String appId; private final String apiKey; @@ -45,7 +46,7 @@ public Query rewrite(IndexReader reader) throws IOException { if (newPrefilter == prefilter) { return super.rewrite(reader); } else { - return new TraveltimeSearchQuery(params, newPrefilter, output, appUri, appId, apiKey); + return new TraveltimeSearchQuery(params, newPrefilter, output, distanceOutput, appUri, appId, apiKey); } } } From bf17e669cba3bf80d59921d8dc22a85c3278926b Mon Sep 17 00:00:00 2001 From: Marcin Januszkiewicz Date: Wed, 28 Aug 2024 16:51:08 +0200 Subject: [PATCH 13/24] Implement distance queries for version 8.7-8.9 --- .../plugin/elasticsearch/TraveltimePlugin.java | 2 ++ .../elasticsearch/query/TraveltimeFetchPhase.java | 15 ++++++++++++--- .../query/TraveltimeQueryBuilder.java | 11 +++++++++-- .../query/TraveltimeQueryParser.java | 4 +++- .../query/TraveltimeSearchQuery.java | 3 ++- .../plugin/elasticsearch/TraveltimePlugin.java | 2 ++ .../elasticsearch/query/TraveltimeFetchPhase.java | 15 ++++++++++++--- .../query/TraveltimeQueryBuilder.java | 11 +++++++++-- .../query/TraveltimeQueryParser.java | 4 +++- .../query/TraveltimeSearchQuery.java | 3 ++- .../plugin/elasticsearch/TraveltimePlugin.java | 2 ++ .../elasticsearch/query/TraveltimeFetchPhase.java | 15 ++++++++++++--- .../query/TraveltimeQueryBuilder.java | 11 +++++++++-- .../query/TraveltimeQueryParser.java | 4 +++- .../query/TraveltimeSearchQuery.java | 3 ++- 15 files changed, 84 insertions(+), 21 deletions(-) diff --git a/8.7/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java b/8.7/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java index 84dc6a2..826e2f0 100644 --- a/8.7/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java +++ b/8.7/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java @@ -49,6 +49,7 @@ public class TraveltimePlugin extends Plugin implements SearchPlugin { private void cleanUpAndReschedule(ThreadPool threadPool, TimeValue cleanupSeconds) { TraveltimeCache.INSTANCE.cleanUp(); + TraveltimeCache.DISTANCE.cleanUp(); threadPool.scheduleUnlessShuttingDown(cleanupSeconds, "generic", () -> cleanUpAndReschedule(threadPool, cleanupSeconds)); } @@ -73,6 +74,7 @@ public Collection createComponents( Integer cacheSize = CACHE_SIZE.get(environment.settings()); TraveltimeCache.INSTANCE.setUp(cacheSize, cacheExpiry); + TraveltimeCache.DISTANCE.setUp(cacheSize, cacheExpiry); cleanUpAndReschedule(threadPool, cleanupSeconds); return super.createComponents(client, clusterService, threadPool, resourceWatcherService, scriptService, xContentRegistry, environment, nodeEnvironment, namedWriteableRegistry, indexNameExpressionResolver, repositoriesServiceSupplier, tracer, allocationService); diff --git a/8.7/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/8.7/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 019a235..34ccd96 100644 --- a/8.7/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/8.7/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -47,6 +47,7 @@ public FetchSubPhaseProcessor getProcessor(FetchContext fetchContext) { if (traveltimeQuery == null) return null; TraveltimeQueryParameters params = traveltimeQuery.getParams(); final String output = traveltimeQuery.getOutput(); + final String distanceOutput = traveltimeQuery.getDistanceOutput(); FieldFetcher fieldFetcher = FieldFetcher.create(fetchContext.getSearchExecutionContext(), List.of(new FieldAndFormat(params.getField(), null))); @@ -61,10 +62,18 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if (!output.isEmpty()) { + Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if (tt >= 0) { + hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + } + } - if (tt >= 0) { - hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + if (!distanceOutput.isEmpty()) { + Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + if (td >= 0) { + hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); + } } } diff --git a/8.7/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/8.7/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index 797e0c7..ea3ba4d 100644 --- a/8.7/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/8.7/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -38,6 +38,8 @@ public class TraveltimeQueryBuilder extends AbstractQueryBuilder prefilterParser = (p, c) -> TraveltimeQueryBuilder.parseInnerQueryBuilder(p); @@ -35,9 +36,10 @@ public class TraveltimeQueryParser implements QueryParser qb.setMode(findByNameOrError("transportation mode", s, Util::findModeByName)), mode); queryParser.declareString((qb, s) -> qb.setCountry(findByNameOrError("country", s, Util::findCountryByName)), country); - queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("country", s, Util::findRequestTypeByName)), requestType); + queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("request mode", s, Util::findRequestTypeByName)), requestType); queryParser.declareObject(TraveltimeQueryBuilder::setPrefilter, prefilterParser, prefilter); queryParser.declareString(TraveltimeQueryBuilder::setOutput, output); + queryParser.declareString(TraveltimeQueryBuilder::setDistanceOutput, distanceOutput); queryParser.declareRequiredFieldSet(field.toString()); queryParser.declareRequiredFieldSet(origin.toString()); diff --git a/8.7/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java b/8.7/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java index 6826002..7ec036d 100644 --- a/8.7/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java +++ b/8.7/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java @@ -16,6 +16,7 @@ public class TraveltimeSearchQuery extends Query { private final TraveltimeQueryParameters params; private final Query prefilter; private final String output; + private final String distanceOutput; private final URI appUri; private final String appId; private final String apiKey; @@ -45,7 +46,7 @@ public Query rewrite(IndexReader reader) throws IOException { if (newPrefilter == prefilter) { return super.rewrite(reader); } else { - return new TraveltimeSearchQuery(params, newPrefilter, output, appUri, appId, apiKey); + return new TraveltimeSearchQuery(params, newPrefilter, output, distanceOutput, appUri, appId, apiKey); } } } diff --git a/8.8/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java b/8.8/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java index 84dc6a2..826e2f0 100644 --- a/8.8/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java +++ b/8.8/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java @@ -49,6 +49,7 @@ public class TraveltimePlugin extends Plugin implements SearchPlugin { private void cleanUpAndReschedule(ThreadPool threadPool, TimeValue cleanupSeconds) { TraveltimeCache.INSTANCE.cleanUp(); + TraveltimeCache.DISTANCE.cleanUp(); threadPool.scheduleUnlessShuttingDown(cleanupSeconds, "generic", () -> cleanUpAndReschedule(threadPool, cleanupSeconds)); } @@ -73,6 +74,7 @@ public Collection createComponents( Integer cacheSize = CACHE_SIZE.get(environment.settings()); TraveltimeCache.INSTANCE.setUp(cacheSize, cacheExpiry); + TraveltimeCache.DISTANCE.setUp(cacheSize, cacheExpiry); cleanUpAndReschedule(threadPool, cleanupSeconds); return super.createComponents(client, clusterService, threadPool, resourceWatcherService, scriptService, xContentRegistry, environment, nodeEnvironment, namedWriteableRegistry, indexNameExpressionResolver, repositoriesServiceSupplier, tracer, allocationService); diff --git a/8.8/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/8.8/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 019a235..34ccd96 100644 --- a/8.8/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/8.8/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -47,6 +47,7 @@ public FetchSubPhaseProcessor getProcessor(FetchContext fetchContext) { if (traveltimeQuery == null) return null; TraveltimeQueryParameters params = traveltimeQuery.getParams(); final String output = traveltimeQuery.getOutput(); + final String distanceOutput = traveltimeQuery.getDistanceOutput(); FieldFetcher fieldFetcher = FieldFetcher.create(fetchContext.getSearchExecutionContext(), List.of(new FieldAndFormat(params.getField(), null))); @@ -61,10 +62,18 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if (!output.isEmpty()) { + Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if (tt >= 0) { + hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + } + } - if (tt >= 0) { - hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + if (!distanceOutput.isEmpty()) { + Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + if (td >= 0) { + hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); + } } } diff --git a/8.8/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/8.8/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index 797e0c7..ea3ba4d 100644 --- a/8.8/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/8.8/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -38,6 +38,8 @@ public class TraveltimeQueryBuilder extends AbstractQueryBuilder prefilterParser = (p, c) -> TraveltimeQueryBuilder.parseInnerQueryBuilder(p); @@ -35,9 +36,10 @@ public class TraveltimeQueryParser implements QueryParser qb.setMode(findByNameOrError("transportation mode", s, Util::findModeByName)), mode); queryParser.declareString((qb, s) -> qb.setCountry(findByNameOrError("country", s, Util::findCountryByName)), country); - queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("country", s, Util::findRequestTypeByName)), requestType); + queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("request mode", s, Util::findRequestTypeByName)), requestType); queryParser.declareObject(TraveltimeQueryBuilder::setPrefilter, prefilterParser, prefilter); queryParser.declareString(TraveltimeQueryBuilder::setOutput, output); + queryParser.declareString(TraveltimeQueryBuilder::setDistanceOutput, distanceOutput); queryParser.declareRequiredFieldSet(field.toString()); queryParser.declareRequiredFieldSet(origin.toString()); diff --git a/8.8/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java b/8.8/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java index 6826002..7ec036d 100644 --- a/8.8/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java +++ b/8.8/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java @@ -16,6 +16,7 @@ public class TraveltimeSearchQuery extends Query { private final TraveltimeQueryParameters params; private final Query prefilter; private final String output; + private final String distanceOutput; private final URI appUri; private final String appId; private final String apiKey; @@ -45,7 +46,7 @@ public Query rewrite(IndexReader reader) throws IOException { if (newPrefilter == prefilter) { return super.rewrite(reader); } else { - return new TraveltimeSearchQuery(params, newPrefilter, output, appUri, appId, apiKey); + return new TraveltimeSearchQuery(params, newPrefilter, output, distanceOutput, appUri, appId, apiKey); } } } diff --git a/8.9/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java b/8.9/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java index 84dc6a2..826e2f0 100644 --- a/8.9/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java +++ b/8.9/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java @@ -49,6 +49,7 @@ public class TraveltimePlugin extends Plugin implements SearchPlugin { private void cleanUpAndReschedule(ThreadPool threadPool, TimeValue cleanupSeconds) { TraveltimeCache.INSTANCE.cleanUp(); + TraveltimeCache.DISTANCE.cleanUp(); threadPool.scheduleUnlessShuttingDown(cleanupSeconds, "generic", () -> cleanUpAndReschedule(threadPool, cleanupSeconds)); } @@ -73,6 +74,7 @@ public Collection createComponents( Integer cacheSize = CACHE_SIZE.get(environment.settings()); TraveltimeCache.INSTANCE.setUp(cacheSize, cacheExpiry); + TraveltimeCache.DISTANCE.setUp(cacheSize, cacheExpiry); cleanUpAndReschedule(threadPool, cleanupSeconds); return super.createComponents(client, clusterService, threadPool, resourceWatcherService, scriptService, xContentRegistry, environment, nodeEnvironment, namedWriteableRegistry, indexNameExpressionResolver, repositoriesServiceSupplier, tracer, allocationService); diff --git a/8.9/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/8.9/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 019a235..34ccd96 100644 --- a/8.9/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/8.9/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -47,6 +47,7 @@ public FetchSubPhaseProcessor getProcessor(FetchContext fetchContext) { if (traveltimeQuery == null) return null; TraveltimeQueryParameters params = traveltimeQuery.getParams(); final String output = traveltimeQuery.getOutput(); + final String distanceOutput = traveltimeQuery.getDistanceOutput(); FieldFetcher fieldFetcher = FieldFetcher.create(fetchContext.getSearchExecutionContext(), List.of(new FieldAndFormat(params.getField(), null))); @@ -61,10 +62,18 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if (!output.isEmpty()) { + Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + if (tt >= 0) { + hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + } + } - if (tt >= 0) { - hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + if (!distanceOutput.isEmpty()) { + Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + if (td >= 0) { + hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); + } } } diff --git a/8.9/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/8.9/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index 3eeca5d..849752c 100644 --- a/8.9/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/8.9/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -38,6 +38,8 @@ public class TraveltimeQueryBuilder extends AbstractQueryBuilder prefilterParser = (p, c) -> TraveltimeQueryBuilder.parseInnerQueryBuilder(p); @@ -35,9 +36,10 @@ public class TraveltimeQueryParser implements QueryParser qb.setMode(findByNameOrError("transportation mode", s, Util::findModeByName)), mode); queryParser.declareString((qb, s) -> qb.setCountry(findByNameOrError("country", s, Util::findCountryByName)), country); - queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("country", s, Util::findRequestTypeByName)), requestType); + queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("request mode", s, Util::findRequestTypeByName)), requestType); queryParser.declareObject(TraveltimeQueryBuilder::setPrefilter, prefilterParser, prefilter); queryParser.declareString(TraveltimeQueryBuilder::setOutput, output); + queryParser.declareString(TraveltimeQueryBuilder::setDistanceOutput, distanceOutput); queryParser.declareRequiredFieldSet(field.toString()); queryParser.declareRequiredFieldSet(origin.toString()); diff --git a/8.9/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java b/8.9/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java index 0ee3888..0bc37e5 100644 --- a/8.9/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java +++ b/8.9/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java @@ -15,6 +15,7 @@ public class TraveltimeSearchQuery extends Query { private final TraveltimeQueryParameters params; private final Query prefilter; private final String output; + private final String distanceOutput; private final URI appUri; private final String appId; private final String apiKey; @@ -44,7 +45,7 @@ public Query rewrite(IndexSearcher reader) throws IOException { if (newPrefilter == prefilter) { return super.rewrite(reader); } else { - return new TraveltimeSearchQuery(params, newPrefilter, output, appUri, appId, apiKey); + return new TraveltimeSearchQuery(params, newPrefilter, output, distanceOutput, appUri, appId, apiKey); } } } From a764626df8388939ff1da4c780494609339c5f1e Mon Sep 17 00:00:00 2001 From: Marcin Januszkiewicz Date: Wed, 28 Aug 2024 17:22:25 +0200 Subject: [PATCH 14/24] Fix missaplied patch --- .../elasticsearch/query/TraveltimeQueryBuilder.java | 11 ++++++++++- .../elasticsearch/query/TraveltimeQueryBuilder.java | 9 ++++++++- .../elasticsearch/query/TraveltimeQueryBuilder.java | 8 +++++++- .../elasticsearch/query/TraveltimeQueryBuilder.java | 8 +++++++- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index 3eeca5d..01495c8 100644 --- a/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -38,6 +38,8 @@ public class TraveltimeQueryBuilder extends AbstractQueryBuilder Date: Thu, 29 Aug 2024 12:55:16 +0200 Subject: [PATCH 15/24] Fix fetch phase in 7.10 --- .../plugin/elasticsearch/query/TraveltimeFetchPhase.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/7.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/7.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 393d983..4865b2d 100644 --- a/7.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/7.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -60,15 +60,16 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); + val point = docValues.nextValue(); if(!output.isEmpty()) { - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + Integer tt = TraveltimeCache.INSTANCE.get(params, point); if (tt >= 0) { hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); } } if(!distanceOutput.isEmpty()) { - Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + Integer td = TraveltimeCache.DISTANCE.get(params, point); if (td >= 0) { hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); } From abd12448f867234be12a734332e3f81dbf3898cc Mon Sep 17 00:00:00 2001 From: Marcin Januszkiewicz Date: Thu, 29 Aug 2024 13:01:04 +0200 Subject: [PATCH 16/24] Fix fetch phase in 7.11-8.9 --- .../plugin/elasticsearch/query/TraveltimeFetchPhase.java | 5 +++-- .../plugin/elasticsearch/query/TraveltimeFetchPhase.java | 5 +++-- .../plugin/elasticsearch/query/TraveltimeFetchPhase.java | 5 +++-- .../plugin/elasticsearch/query/TraveltimeFetchPhase.java | 5 +++-- .../plugin/elasticsearch/query/TraveltimeFetchPhase.java | 5 +++-- .../plugin/elasticsearch/query/TraveltimeFetchPhase.java | 5 +++-- .../plugin/elasticsearch/query/TraveltimeFetchPhase.java | 5 +++-- .../plugin/elasticsearch/query/TraveltimeFetchPhase.java | 5 +++-- .../plugin/elasticsearch/query/TraveltimeFetchPhase.java | 5 +++-- .../plugin/elasticsearch/query/TraveltimeFetchPhase.java | 5 +++-- .../plugin/elasticsearch/query/TraveltimeFetchPhase.java | 5 +++-- .../plugin/elasticsearch/query/TraveltimeFetchPhase.java | 5 +++-- .../plugin/elasticsearch/query/TraveltimeFetchPhase.java | 5 +++-- .../plugin/elasticsearch/query/TraveltimeFetchPhase.java | 5 +++-- .../plugin/elasticsearch/query/TraveltimeFetchPhase.java | 5 +++-- .../plugin/elasticsearch/query/TraveltimeFetchPhase.java | 5 +++-- .../plugin/elasticsearch/query/TraveltimeFetchPhase.java | 5 +++-- 17 files changed, 51 insertions(+), 34 deletions(-) diff --git a/7.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/7.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 2e2eaec..a2590cd 100644 --- a/7.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/7.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -60,15 +60,16 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); + val point = docValues.nextValue(); if(!output.isEmpty()) { - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + Integer tt = TraveltimeCache.INSTANCE.get(params, point); if (tt >= 0) { hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); } } if(!distanceOutput.isEmpty()) { - Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + Integer td = TraveltimeCache.DISTANCE.get(params, point); if (td >= 0) { hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); } diff --git a/7.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/7.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 6691849..aab65ac 100644 --- a/7.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/7.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -60,15 +60,16 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); + val point = docValues.nextValue(); if(!output.isEmpty()) { - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + Integer tt = TraveltimeCache.INSTANCE.get(params, point); if (tt >= 0) { hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); } } if(!distanceOutput.isEmpty()) { - Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + Integer td = TraveltimeCache.DISTANCE.get(params, point); if (td >= 0) { hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); } diff --git a/7.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/7.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 6691849..aab65ac 100644 --- a/7.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/7.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -60,15 +60,16 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); + val point = docValues.nextValue(); if(!output.isEmpty()) { - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + Integer tt = TraveltimeCache.INSTANCE.get(params, point); if (tt >= 0) { hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); } } if(!distanceOutput.isEmpty()) { - Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + Integer td = TraveltimeCache.DISTANCE.get(params, point); if (td >= 0) { hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); } diff --git a/7.14/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/7.14/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 6691849..aab65ac 100644 --- a/7.14/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/7.14/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -60,15 +60,16 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); + val point = docValues.nextValue(); if(!output.isEmpty()) { - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + Integer tt = TraveltimeCache.INSTANCE.get(params, point); if (tt >= 0) { hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); } } if(!distanceOutput.isEmpty()) { - Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + Integer td = TraveltimeCache.DISTANCE.get(params, point); if (td >= 0) { hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); } diff --git a/7.15/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/7.15/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 6691849..aab65ac 100644 --- a/7.15/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/7.15/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -60,15 +60,16 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); + val point = docValues.nextValue(); if(!output.isEmpty()) { - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + Integer tt = TraveltimeCache.INSTANCE.get(params, point); if (tt >= 0) { hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); } } if(!distanceOutput.isEmpty()) { - Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + Integer td = TraveltimeCache.DISTANCE.get(params, point); if (td >= 0) { hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); } diff --git a/7.16/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/7.16/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 6691849..aab65ac 100644 --- a/7.16/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/7.16/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -60,15 +60,16 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); + val point = docValues.nextValue(); if(!output.isEmpty()) { - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + Integer tt = TraveltimeCache.INSTANCE.get(params, point); if (tt >= 0) { hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); } } if(!distanceOutput.isEmpty()) { - Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + Integer td = TraveltimeCache.DISTANCE.get(params, point); if (td >= 0) { hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); } diff --git a/7.17/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/7.17/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 6691849..aab65ac 100644 --- a/7.17/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/7.17/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -60,15 +60,16 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); + val point = docValues.nextValue(); if(!output.isEmpty()) { - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + Integer tt = TraveltimeCache.INSTANCE.get(params, point); if (tt >= 0) { hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); } } if(!distanceOutput.isEmpty()) { - Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + Integer td = TraveltimeCache.DISTANCE.get(params, point); if (td >= 0) { hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); } diff --git a/8.0/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/8.0/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 6691849..aab65ac 100644 --- a/8.0/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/8.0/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -60,15 +60,16 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); + val point = docValues.nextValue(); if(!output.isEmpty()) { - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + Integer tt = TraveltimeCache.INSTANCE.get(params, point); if (tt >= 0) { hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); } } if(!distanceOutput.isEmpty()) { - Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + Integer td = TraveltimeCache.DISTANCE.get(params, point); if (td >= 0) { hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); } diff --git a/8.1/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/8.1/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 6691849..aab65ac 100644 --- a/8.1/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/8.1/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -60,15 +60,16 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); + val point = docValues.nextValue(); if(!output.isEmpty()) { - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + Integer tt = TraveltimeCache.INSTANCE.get(params, point); if (tt >= 0) { hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); } } if(!distanceOutput.isEmpty()) { - Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + Integer td = TraveltimeCache.DISTANCE.get(params, point); if (td >= 0) { hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); } diff --git a/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 6691849..aab65ac 100644 --- a/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -60,15 +60,16 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); + val point = docValues.nextValue(); if(!output.isEmpty()) { - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + Integer tt = TraveltimeCache.INSTANCE.get(params, point); if (tt >= 0) { hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); } } if(!distanceOutput.isEmpty()) { - Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + Integer td = TraveltimeCache.DISTANCE.get(params, point); if (td >= 0) { hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); } diff --git a/8.3/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/8.3/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 6691849..aab65ac 100644 --- a/8.3/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/8.3/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -60,15 +60,16 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); + val point = docValues.nextValue(); if(!output.isEmpty()) { - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + Integer tt = TraveltimeCache.INSTANCE.get(params, point); if (tt >= 0) { hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); } } if(!distanceOutput.isEmpty()) { - Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + Integer td = TraveltimeCache.DISTANCE.get(params, point); if (td >= 0) { hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); } diff --git a/8.4/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/8.4/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 6691849..aab65ac 100644 --- a/8.4/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/8.4/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -60,15 +60,16 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); + val point = docValues.nextValue(); if(!output.isEmpty()) { - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + Integer tt = TraveltimeCache.INSTANCE.get(params, point); if (tt >= 0) { hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); } } if(!distanceOutput.isEmpty()) { - Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + Integer td = TraveltimeCache.DISTANCE.get(params, point); if (td >= 0) { hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); } diff --git a/8.5/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/8.5/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 6691849..aab65ac 100644 --- a/8.5/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/8.5/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -60,15 +60,16 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); + val point = docValues.nextValue(); if(!output.isEmpty()) { - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + Integer tt = TraveltimeCache.INSTANCE.get(params, point); if (tt >= 0) { hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); } } if(!distanceOutput.isEmpty()) { - Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + Integer td = TraveltimeCache.DISTANCE.get(params, point); if (td >= 0) { hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); } diff --git a/8.6/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/8.6/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 34ccd96..2230825 100644 --- a/8.6/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/8.6/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -62,15 +62,16 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); + val point = docValues.nextValue(); if (!output.isEmpty()) { - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + Integer tt = TraveltimeCache.INSTANCE.get(params, point); if (tt >= 0) { hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); } } if (!distanceOutput.isEmpty()) { - Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + Integer td = TraveltimeCache.DISTANCE.get(params, point); if (td >= 0) { hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); } diff --git a/8.7/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/8.7/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 34ccd96..2230825 100644 --- a/8.7/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/8.7/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -62,15 +62,16 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); + val point = docValues.nextValue(); if (!output.isEmpty()) { - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + Integer tt = TraveltimeCache.INSTANCE.get(params, point); if (tt >= 0) { hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); } } if (!distanceOutput.isEmpty()) { - Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + Integer td = TraveltimeCache.DISTANCE.get(params, point); if (td >= 0) { hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); } diff --git a/8.8/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/8.8/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 34ccd96..2230825 100644 --- a/8.8/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/8.8/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -62,15 +62,16 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); + val point = docValues.nextValue(); if (!output.isEmpty()) { - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + Integer tt = TraveltimeCache.INSTANCE.get(params, point); if (tt >= 0) { hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); } } if (!distanceOutput.isEmpty()) { - Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + Integer td = TraveltimeCache.DISTANCE.get(params, point); if (td >= 0) { hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); } diff --git a/8.9/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/8.9/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 34ccd96..2230825 100644 --- a/8.9/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/8.9/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -62,15 +62,16 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); + val point = docValues.nextValue(); if (!output.isEmpty()) { - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + Integer tt = TraveltimeCache.INSTANCE.get(params, point); if (tt >= 0) { hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); } } if (!distanceOutput.isEmpty()) { - Integer td = TraveltimeCache.DISTANCE.get(params, docValues.nextValue()); + Integer td = TraveltimeCache.DISTANCE.get(params, point); if (td >= 0) { hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); } From 454ec0dbb01af905b4aaed5ef957e0d97c04985f Mon Sep 17 00:00:00 2001 From: Marcin Januszkiewicz Date: Thu, 29 Aug 2024 13:13:20 +0200 Subject: [PATCH 17/24] Fix misapplied patch --- .../elasticsearch/query/TraveltimeWeight.java | 51 +++++++++++++----- .../elasticsearch/query/TraveltimeWeight.java | 51 +++++++++++++----- .../elasticsearch/query/TraveltimeWeight.java | 51 +++++++++++++----- .../elasticsearch/query/TraveltimeWeight.java | 51 +++++++++++++----- .../elasticsearch/query/TraveltimeWeight.java | 51 +++++++++++++----- .../elasticsearch/query/TraveltimeWeight.java | 51 +++++++++++++----- .../elasticsearch/query/TraveltimeWeight.java | 51 +++++++++++++----- .../elasticsearch/query/TraveltimeWeight.java | 53 +++++++++++++------ .../elasticsearch/query/TraveltimeWeight.java | 50 +++++++++++++---- .../elasticsearch/query/TraveltimeWeight.java | 51 +++++++++++++----- .../elasticsearch/query/TraveltimeWeight.java | 51 +++++++++++++----- .../elasticsearch/query/TraveltimeWeight.java | 51 +++++++++++++----- .../elasticsearch/query/TraveltimeWeight.java | 51 +++++++++++++----- .../elasticsearch/query/TraveltimeWeight.java | 51 +++++++++++++----- .../elasticsearch/query/TraveltimeWeight.java | 51 +++++++++++++----- 15 files changed, 584 insertions(+), 182 deletions(-) diff --git a/7.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java b/7.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java index 701b099..5358ac9 100644 --- a/7.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java +++ b/7.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java @@ -122,18 +122,45 @@ public Scorer scorer(LeafReaderContext context) throws IOException { val pointToTime = new Long2IntOpenHashMap(valueArray.size()); - val results = protoFetcher.getTimes( - ttQuery.getParams().getOrigin(), - decodedArray, - ttQuery.getParams().getLimit(), - ttQuery.getParams().getMode(), - ttQuery.getParams().getCountry(), - ttQuery.getParams().getRequestType() - ); - - for (int index = 0; index < results.size(); index++) { - if(results.get(index) >= 0) { - pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + if (ttQuery.getParams().isIncludeDistance()) { + val pointToDistance = new Long2IntOpenHashMap(valueArray.size()); + + val mode = Util.unsafeCastToDistanceTransportation(ttQuery.getParams().getMode()); + + val timeDistance = protoFetcher.getTimesAndDistances( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + mode, + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + val times = timeDistance.getLeft(); + val distances = timeDistance.getRight(); + + for (int index = 0; index < times.size(); index++) { + if (times.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), times.get(index).intValue()); + pointToDistance.put(valueArray.getLong(index), distances.get(index).intValue()); + } + } + + TraveltimeCache.DISTANCE.add(ttQuery.getParams(), pointToDistance); + } else { + val results = protoFetcher.getTimes( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + ttQuery.getParams().getMode(), + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + for (int index = 0; index < results.size(); index++) { + if (results.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + } } } diff --git a/7.14/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java b/7.14/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java index 701b099..5358ac9 100644 --- a/7.14/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java +++ b/7.14/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java @@ -122,18 +122,45 @@ public Scorer scorer(LeafReaderContext context) throws IOException { val pointToTime = new Long2IntOpenHashMap(valueArray.size()); - val results = protoFetcher.getTimes( - ttQuery.getParams().getOrigin(), - decodedArray, - ttQuery.getParams().getLimit(), - ttQuery.getParams().getMode(), - ttQuery.getParams().getCountry(), - ttQuery.getParams().getRequestType() - ); - - for (int index = 0; index < results.size(); index++) { - if(results.get(index) >= 0) { - pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + if (ttQuery.getParams().isIncludeDistance()) { + val pointToDistance = new Long2IntOpenHashMap(valueArray.size()); + + val mode = Util.unsafeCastToDistanceTransportation(ttQuery.getParams().getMode()); + + val timeDistance = protoFetcher.getTimesAndDistances( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + mode, + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + val times = timeDistance.getLeft(); + val distances = timeDistance.getRight(); + + for (int index = 0; index < times.size(); index++) { + if (times.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), times.get(index).intValue()); + pointToDistance.put(valueArray.getLong(index), distances.get(index).intValue()); + } + } + + TraveltimeCache.DISTANCE.add(ttQuery.getParams(), pointToDistance); + } else { + val results = protoFetcher.getTimes( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + ttQuery.getParams().getMode(), + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + for (int index = 0; index < results.size(); index++) { + if (results.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + } } } diff --git a/7.15/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java b/7.15/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java index 701b099..5358ac9 100644 --- a/7.15/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java +++ b/7.15/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java @@ -122,18 +122,45 @@ public Scorer scorer(LeafReaderContext context) throws IOException { val pointToTime = new Long2IntOpenHashMap(valueArray.size()); - val results = protoFetcher.getTimes( - ttQuery.getParams().getOrigin(), - decodedArray, - ttQuery.getParams().getLimit(), - ttQuery.getParams().getMode(), - ttQuery.getParams().getCountry(), - ttQuery.getParams().getRequestType() - ); - - for (int index = 0; index < results.size(); index++) { - if(results.get(index) >= 0) { - pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + if (ttQuery.getParams().isIncludeDistance()) { + val pointToDistance = new Long2IntOpenHashMap(valueArray.size()); + + val mode = Util.unsafeCastToDistanceTransportation(ttQuery.getParams().getMode()); + + val timeDistance = protoFetcher.getTimesAndDistances( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + mode, + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + val times = timeDistance.getLeft(); + val distances = timeDistance.getRight(); + + for (int index = 0; index < times.size(); index++) { + if (times.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), times.get(index).intValue()); + pointToDistance.put(valueArray.getLong(index), distances.get(index).intValue()); + } + } + + TraveltimeCache.DISTANCE.add(ttQuery.getParams(), pointToDistance); + } else { + val results = protoFetcher.getTimes( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + ttQuery.getParams().getMode(), + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + for (int index = 0; index < results.size(); index++) { + if (results.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + } } } diff --git a/7.16/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java b/7.16/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java index 701b099..5358ac9 100644 --- a/7.16/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java +++ b/7.16/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java @@ -122,18 +122,45 @@ public Scorer scorer(LeafReaderContext context) throws IOException { val pointToTime = new Long2IntOpenHashMap(valueArray.size()); - val results = protoFetcher.getTimes( - ttQuery.getParams().getOrigin(), - decodedArray, - ttQuery.getParams().getLimit(), - ttQuery.getParams().getMode(), - ttQuery.getParams().getCountry(), - ttQuery.getParams().getRequestType() - ); - - for (int index = 0; index < results.size(); index++) { - if(results.get(index) >= 0) { - pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + if (ttQuery.getParams().isIncludeDistance()) { + val pointToDistance = new Long2IntOpenHashMap(valueArray.size()); + + val mode = Util.unsafeCastToDistanceTransportation(ttQuery.getParams().getMode()); + + val timeDistance = protoFetcher.getTimesAndDistances( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + mode, + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + val times = timeDistance.getLeft(); + val distances = timeDistance.getRight(); + + for (int index = 0; index < times.size(); index++) { + if (times.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), times.get(index).intValue()); + pointToDistance.put(valueArray.getLong(index), distances.get(index).intValue()); + } + } + + TraveltimeCache.DISTANCE.add(ttQuery.getParams(), pointToDistance); + } else { + val results = protoFetcher.getTimes( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + ttQuery.getParams().getMode(), + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + for (int index = 0; index < results.size(); index++) { + if (results.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + } } } diff --git a/7.17/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java b/7.17/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java index 701b099..5358ac9 100644 --- a/7.17/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java +++ b/7.17/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java @@ -122,18 +122,45 @@ public Scorer scorer(LeafReaderContext context) throws IOException { val pointToTime = new Long2IntOpenHashMap(valueArray.size()); - val results = protoFetcher.getTimes( - ttQuery.getParams().getOrigin(), - decodedArray, - ttQuery.getParams().getLimit(), - ttQuery.getParams().getMode(), - ttQuery.getParams().getCountry(), - ttQuery.getParams().getRequestType() - ); - - for (int index = 0; index < results.size(); index++) { - if(results.get(index) >= 0) { - pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + if (ttQuery.getParams().isIncludeDistance()) { + val pointToDistance = new Long2IntOpenHashMap(valueArray.size()); + + val mode = Util.unsafeCastToDistanceTransportation(ttQuery.getParams().getMode()); + + val timeDistance = protoFetcher.getTimesAndDistances( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + mode, + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + val times = timeDistance.getLeft(); + val distances = timeDistance.getRight(); + + for (int index = 0; index < times.size(); index++) { + if (times.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), times.get(index).intValue()); + pointToDistance.put(valueArray.getLong(index), distances.get(index).intValue()); + } + } + + TraveltimeCache.DISTANCE.add(ttQuery.getParams(), pointToDistance); + } else { + val results = protoFetcher.getTimes( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + ttQuery.getParams().getMode(), + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + for (int index = 0; index < results.size(); index++) { + if (results.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + } } } diff --git a/8.0/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java b/8.0/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java index a990cba..7f365e8 100644 --- a/8.0/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java +++ b/8.0/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java @@ -116,18 +116,45 @@ public Scorer scorer(LeafReaderContext context) throws IOException { val pointToTime = new Long2IntOpenHashMap(valueArray.size()); - val results = protoFetcher.getTimes( - ttQuery.getParams().getOrigin(), - decodedArray, - ttQuery.getParams().getLimit(), - ttQuery.getParams().getMode(), - ttQuery.getParams().getCountry(), - ttQuery.getParams().getRequestType() - ); - - for (int index = 0; index < results.size(); index++) { - if(results.get(index) >= 0) { - pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + if (ttQuery.getParams().isIncludeDistance()) { + val pointToDistance = new Long2IntOpenHashMap(valueArray.size()); + + val mode = Util.unsafeCastToDistanceTransportation(ttQuery.getParams().getMode()); + + val timeDistance = protoFetcher.getTimesAndDistances( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + mode, + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + val times = timeDistance.getLeft(); + val distances = timeDistance.getRight(); + + for (int index = 0; index < times.size(); index++) { + if (times.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), times.get(index).intValue()); + pointToDistance.put(valueArray.getLong(index), distances.get(index).intValue()); + } + } + + TraveltimeCache.DISTANCE.add(ttQuery.getParams(), pointToDistance); + } else { + val results = protoFetcher.getTimes( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + ttQuery.getParams().getMode(), + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + for (int index = 0; index < results.size(); index++) { + if (results.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + } } } diff --git a/8.1/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java b/8.1/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java index 6c74bd4..7f365e8 100644 --- a/8.1/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java +++ b/8.1/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java @@ -116,18 +116,45 @@ public Scorer scorer(LeafReaderContext context) throws IOException { val pointToTime = new Long2IntOpenHashMap(valueArray.size()); - val results = protoFetcher.getTimes( - ttQuery.getParams().getOrigin(), - decodedArray, - ttQuery.getParams().getLimit(), - ttQuery.getParams().getMode(), - ttQuery.getParams().getCountry(), - ttQuery.getParams().getRequestType() - ); - - for (int index = 0; index < results.size(); index++) { - if(results.get(index) >= 0) { - pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + if (ttQuery.getParams().isIncludeDistance()) { + val pointToDistance = new Long2IntOpenHashMap(valueArray.size()); + + val mode = Util.unsafeCastToDistanceTransportation(ttQuery.getParams().getMode()); + + val timeDistance = protoFetcher.getTimesAndDistances( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + mode, + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + val times = timeDistance.getLeft(); + val distances = timeDistance.getRight(); + + for (int index = 0; index < times.size(); index++) { + if (times.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), times.get(index).intValue()); + pointToDistance.put(valueArray.getLong(index), distances.get(index).intValue()); + } + } + + TraveltimeCache.DISTANCE.add(ttQuery.getParams(), pointToDistance); + } else { + val results = protoFetcher.getTimes( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + ttQuery.getParams().getMode(), + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + for (int index = 0; index < results.size(); index++) { + if (results.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + } } } diff --git a/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java b/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java index a990cba..d77793c 100644 --- a/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java +++ b/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java @@ -116,23 +116,46 @@ public Scorer scorer(LeafReaderContext context) throws IOException { val pointToTime = new Long2IntOpenHashMap(valueArray.size()); - val results = protoFetcher.getTimes( - ttQuery.getParams().getOrigin(), - decodedArray, - ttQuery.getParams().getLimit(), - ttQuery.getParams().getMode(), - ttQuery.getParams().getCountry(), - ttQuery.getParams().getRequestType() - ); - - for (int index = 0; index < results.size(); index++) { - if(results.get(index) >= 0) { - pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + if (ttQuery.getParams().isIncludeDistance()) { + val pointToDistance = new Long2IntOpenHashMap(valueArray.size()); + + val mode = Util.unsafeCastToDistanceTransportation(ttQuery.getParams().getMode()); + + val timeDistance = protoFetcher.getTimesAndDistances( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + mode, + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + val times = timeDistance.getLeft(); + val distances = timeDistance.getRight(); + + for (int index = 0; index < times.size(); index++) { + if (times.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), times.get(index).intValue()); + pointToDistance.put(valueArray.getLong(index), distances.get(index).intValue()); + } } - } - if(hasOutput) { - TraveltimeCache.INSTANCE.add(ttQuery.getParams(), pointToTime); + TraveltimeCache.DISTANCE.add(ttQuery.getParams(), pointToDistance); + } else { + val results = protoFetcher.getTimes( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + ttQuery.getParams().getMode(), + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + for (int index = 0; index < results.size(); index++) { + if (results.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + } + } } return new TraveltimeScorer(this, pointToTime, filteredValues(context), boost); diff --git a/8.3/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java b/8.3/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java index e359622..7f365e8 100644 --- a/8.3/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java +++ b/8.3/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java @@ -116,17 +116,45 @@ public Scorer scorer(LeafReaderContext context) throws IOException { val pointToTime = new Long2IntOpenHashMap(valueArray.size()); - val results = protoFetcher.getTimes( - ttQuery.getParams().getOrigin(), - decodedArray, - ttQuery.getParams().getLimit(), - ttQuery.getParams().getMode(), - ttQuery.getParams().getCountry(), ttQuery.getParams().getRequestType() - ); - - for (int index = 0; index < results.size(); index++) { - if(results.get(index) >= 0) { - pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + if (ttQuery.getParams().isIncludeDistance()) { + val pointToDistance = new Long2IntOpenHashMap(valueArray.size()); + + val mode = Util.unsafeCastToDistanceTransportation(ttQuery.getParams().getMode()); + + val timeDistance = protoFetcher.getTimesAndDistances( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + mode, + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + val times = timeDistance.getLeft(); + val distances = timeDistance.getRight(); + + for (int index = 0; index < times.size(); index++) { + if (times.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), times.get(index).intValue()); + pointToDistance.put(valueArray.getLong(index), distances.get(index).intValue()); + } + } + + TraveltimeCache.DISTANCE.add(ttQuery.getParams(), pointToDistance); + } else { + val results = protoFetcher.getTimes( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + ttQuery.getParams().getMode(), + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + for (int index = 0; index < results.size(); index++) { + if (results.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + } } } diff --git a/8.4/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java b/8.4/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java index a990cba..7f365e8 100644 --- a/8.4/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java +++ b/8.4/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java @@ -116,18 +116,45 @@ public Scorer scorer(LeafReaderContext context) throws IOException { val pointToTime = new Long2IntOpenHashMap(valueArray.size()); - val results = protoFetcher.getTimes( - ttQuery.getParams().getOrigin(), - decodedArray, - ttQuery.getParams().getLimit(), - ttQuery.getParams().getMode(), - ttQuery.getParams().getCountry(), - ttQuery.getParams().getRequestType() - ); - - for (int index = 0; index < results.size(); index++) { - if(results.get(index) >= 0) { - pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + if (ttQuery.getParams().isIncludeDistance()) { + val pointToDistance = new Long2IntOpenHashMap(valueArray.size()); + + val mode = Util.unsafeCastToDistanceTransportation(ttQuery.getParams().getMode()); + + val timeDistance = protoFetcher.getTimesAndDistances( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + mode, + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + val times = timeDistance.getLeft(); + val distances = timeDistance.getRight(); + + for (int index = 0; index < times.size(); index++) { + if (times.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), times.get(index).intValue()); + pointToDistance.put(valueArray.getLong(index), distances.get(index).intValue()); + } + } + + TraveltimeCache.DISTANCE.add(ttQuery.getParams(), pointToDistance); + } else { + val results = protoFetcher.getTimes( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + ttQuery.getParams().getMode(), + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + for (int index = 0; index < results.size(); index++) { + if (results.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + } } } diff --git a/8.5/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java b/8.5/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java index a990cba..7f365e8 100644 --- a/8.5/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java +++ b/8.5/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java @@ -116,18 +116,45 @@ public Scorer scorer(LeafReaderContext context) throws IOException { val pointToTime = new Long2IntOpenHashMap(valueArray.size()); - val results = protoFetcher.getTimes( - ttQuery.getParams().getOrigin(), - decodedArray, - ttQuery.getParams().getLimit(), - ttQuery.getParams().getMode(), - ttQuery.getParams().getCountry(), - ttQuery.getParams().getRequestType() - ); - - for (int index = 0; index < results.size(); index++) { - if(results.get(index) >= 0) { - pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + if (ttQuery.getParams().isIncludeDistance()) { + val pointToDistance = new Long2IntOpenHashMap(valueArray.size()); + + val mode = Util.unsafeCastToDistanceTransportation(ttQuery.getParams().getMode()); + + val timeDistance = protoFetcher.getTimesAndDistances( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + mode, + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + val times = timeDistance.getLeft(); + val distances = timeDistance.getRight(); + + for (int index = 0; index < times.size(); index++) { + if (times.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), times.get(index).intValue()); + pointToDistance.put(valueArray.getLong(index), distances.get(index).intValue()); + } + } + + TraveltimeCache.DISTANCE.add(ttQuery.getParams(), pointToDistance); + } else { + val results = protoFetcher.getTimes( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + ttQuery.getParams().getMode(), + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + for (int index = 0; index < results.size(); index++) { + if (results.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + } } } diff --git a/8.6/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java b/8.6/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java index a990cba..7f365e8 100644 --- a/8.6/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java +++ b/8.6/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java @@ -116,18 +116,45 @@ public Scorer scorer(LeafReaderContext context) throws IOException { val pointToTime = new Long2IntOpenHashMap(valueArray.size()); - val results = protoFetcher.getTimes( - ttQuery.getParams().getOrigin(), - decodedArray, - ttQuery.getParams().getLimit(), - ttQuery.getParams().getMode(), - ttQuery.getParams().getCountry(), - ttQuery.getParams().getRequestType() - ); - - for (int index = 0; index < results.size(); index++) { - if(results.get(index) >= 0) { - pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + if (ttQuery.getParams().isIncludeDistance()) { + val pointToDistance = new Long2IntOpenHashMap(valueArray.size()); + + val mode = Util.unsafeCastToDistanceTransportation(ttQuery.getParams().getMode()); + + val timeDistance = protoFetcher.getTimesAndDistances( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + mode, + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + val times = timeDistance.getLeft(); + val distances = timeDistance.getRight(); + + for (int index = 0; index < times.size(); index++) { + if (times.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), times.get(index).intValue()); + pointToDistance.put(valueArray.getLong(index), distances.get(index).intValue()); + } + } + + TraveltimeCache.DISTANCE.add(ttQuery.getParams(), pointToDistance); + } else { + val results = protoFetcher.getTimes( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + ttQuery.getParams().getMode(), + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + for (int index = 0; index < results.size(); index++) { + if (results.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + } } } diff --git a/8.7/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java b/8.7/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java index a990cba..7f365e8 100644 --- a/8.7/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java +++ b/8.7/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java @@ -116,18 +116,45 @@ public Scorer scorer(LeafReaderContext context) throws IOException { val pointToTime = new Long2IntOpenHashMap(valueArray.size()); - val results = protoFetcher.getTimes( - ttQuery.getParams().getOrigin(), - decodedArray, - ttQuery.getParams().getLimit(), - ttQuery.getParams().getMode(), - ttQuery.getParams().getCountry(), - ttQuery.getParams().getRequestType() - ); - - for (int index = 0; index < results.size(); index++) { - if(results.get(index) >= 0) { - pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + if (ttQuery.getParams().isIncludeDistance()) { + val pointToDistance = new Long2IntOpenHashMap(valueArray.size()); + + val mode = Util.unsafeCastToDistanceTransportation(ttQuery.getParams().getMode()); + + val timeDistance = protoFetcher.getTimesAndDistances( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + mode, + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + val times = timeDistance.getLeft(); + val distances = timeDistance.getRight(); + + for (int index = 0; index < times.size(); index++) { + if (times.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), times.get(index).intValue()); + pointToDistance.put(valueArray.getLong(index), distances.get(index).intValue()); + } + } + + TraveltimeCache.DISTANCE.add(ttQuery.getParams(), pointToDistance); + } else { + val results = protoFetcher.getTimes( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + ttQuery.getParams().getMode(), + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + for (int index = 0; index < results.size(); index++) { + if (results.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + } } } diff --git a/8.8/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java b/8.8/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java index a990cba..7f365e8 100644 --- a/8.8/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java +++ b/8.8/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java @@ -116,18 +116,45 @@ public Scorer scorer(LeafReaderContext context) throws IOException { val pointToTime = new Long2IntOpenHashMap(valueArray.size()); - val results = protoFetcher.getTimes( - ttQuery.getParams().getOrigin(), - decodedArray, - ttQuery.getParams().getLimit(), - ttQuery.getParams().getMode(), - ttQuery.getParams().getCountry(), - ttQuery.getParams().getRequestType() - ); - - for (int index = 0; index < results.size(); index++) { - if(results.get(index) >= 0) { - pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + if (ttQuery.getParams().isIncludeDistance()) { + val pointToDistance = new Long2IntOpenHashMap(valueArray.size()); + + val mode = Util.unsafeCastToDistanceTransportation(ttQuery.getParams().getMode()); + + val timeDistance = protoFetcher.getTimesAndDistances( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + mode, + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + val times = timeDistance.getLeft(); + val distances = timeDistance.getRight(); + + for (int index = 0; index < times.size(); index++) { + if (times.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), times.get(index).intValue()); + pointToDistance.put(valueArray.getLong(index), distances.get(index).intValue()); + } + } + + TraveltimeCache.DISTANCE.add(ttQuery.getParams(), pointToDistance); + } else { + val results = protoFetcher.getTimes( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + ttQuery.getParams().getMode(), + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + for (int index = 0; index < results.size(); index++) { + if (results.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + } } } diff --git a/8.9/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java b/8.9/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java index a990cba..7f365e8 100644 --- a/8.9/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java +++ b/8.9/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java @@ -116,18 +116,45 @@ public Scorer scorer(LeafReaderContext context) throws IOException { val pointToTime = new Long2IntOpenHashMap(valueArray.size()); - val results = protoFetcher.getTimes( - ttQuery.getParams().getOrigin(), - decodedArray, - ttQuery.getParams().getLimit(), - ttQuery.getParams().getMode(), - ttQuery.getParams().getCountry(), - ttQuery.getParams().getRequestType() - ); - - for (int index = 0; index < results.size(); index++) { - if(results.get(index) >= 0) { - pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + if (ttQuery.getParams().isIncludeDistance()) { + val pointToDistance = new Long2IntOpenHashMap(valueArray.size()); + + val mode = Util.unsafeCastToDistanceTransportation(ttQuery.getParams().getMode()); + + val timeDistance = protoFetcher.getTimesAndDistances( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + mode, + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + val times = timeDistance.getLeft(); + val distances = timeDistance.getRight(); + + for (int index = 0; index < times.size(); index++) { + if (times.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), times.get(index).intValue()); + pointToDistance.put(valueArray.getLong(index), distances.get(index).intValue()); + } + } + + TraveltimeCache.DISTANCE.add(ttQuery.getParams(), pointToDistance); + } else { + val results = protoFetcher.getTimes( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + ttQuery.getParams().getMode(), + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + for (int index = 0; index < results.size(); index++) { + if (results.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + } } } From dec7dad24c9b615c34ba6ba484749b5e93de75ed Mon Sep 17 00:00:00 2001 From: Marcin Januszkiewicz Date: Thu, 29 Aug 2024 13:16:40 +0200 Subject: [PATCH 18/24] Apply patch to 8.10 --- .../elasticsearch/TraveltimePlugin.java | 2 + .../query/TraveltimeFetchPhase.java | 16 ++++-- .../query/TraveltimeQueryBuilder.java | 2 +- .../query/TraveltimeQueryParser.java | 4 +- .../query/TraveltimeSearchQuery.java | 3 +- .../elasticsearch/query/TraveltimeWeight.java | 51 ++++++++++++++----- 6 files changed, 60 insertions(+), 18 deletions(-) diff --git a/8.10/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java b/8.10/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java index 99a22f6..c26ff2d 100644 --- a/8.10/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java +++ b/8.10/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java @@ -50,6 +50,7 @@ public class TraveltimePlugin extends Plugin implements SearchPlugin { private void cleanUpAndReschedule(ThreadPool threadPool, TimeValue cleanupSeconds) { TraveltimeCache.INSTANCE.cleanUp(); + TraveltimeCache.DISTANCE.cleanUp(); threadPool.scheduleUnlessShuttingDown(cleanupSeconds, "generic", () -> cleanUpAndReschedule(threadPool, cleanupSeconds)); } @@ -75,6 +76,7 @@ public Collection createComponents( Integer cacheSize = CACHE_SIZE.get(environment.settings()); TraveltimeCache.INSTANCE.setUp(cacheSize, cacheExpiry); + TraveltimeCache.DISTANCE.setUp(cacheSize, cacheExpiry); cleanUpAndReschedule(threadPool, cleanupSeconds); return super.createComponents(client, clusterService, threadPool, resourceWatcherService, scriptService, xContentRegistry, environment, nodeEnvironment, namedWriteableRegistry, indexNameExpressionResolver, repositoriesServiceSupplier, tracer, allocationService, indicesService); diff --git a/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 019a235..2230825 100644 --- a/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -47,6 +47,7 @@ public FetchSubPhaseProcessor getProcessor(FetchContext fetchContext) { if (traveltimeQuery == null) return null; TraveltimeQueryParameters params = traveltimeQuery.getParams(); final String output = traveltimeQuery.getOutput(); + final String distanceOutput = traveltimeQuery.getDistanceOutput(); FieldFetcher fieldFetcher = FieldFetcher.create(fetchContext.getSearchExecutionContext(), List.of(new FieldAndFormat(params.getField(), null))); @@ -61,10 +62,19 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + val point = docValues.nextValue(); + if (!output.isEmpty()) { + Integer tt = TraveltimeCache.INSTANCE.get(params, point); + if (tt >= 0) { + hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + } + } - if (tt >= 0) { - hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + if (!distanceOutput.isEmpty()) { + Integer td = TraveltimeCache.DISTANCE.get(params, point); + if (td >= 0) { + hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); + } } } diff --git a/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index 01495c8..7045c88 100644 --- a/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -154,7 +154,7 @@ protected Query doToQuery(SearchExecutionContext context) throws IOException { Query prefilterQuery = prefilter != null ? prefilter.toQuery(context) : null; - return new TraveltimeSearchQuery(params, prefilterQuery, output, appUri, appId, apiKey); + return new TraveltimeSearchQuery(params, prefilterQuery, output, distanceOutput, appUri, appId, apiKey); } @Override diff --git a/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java b/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java index 1705d39..ac2a6ab 100644 --- a/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java +++ b/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java @@ -24,6 +24,7 @@ public class TraveltimeQueryParser implements QueryParser prefilterParser = (p, c) -> TraveltimeQueryBuilder.parseInnerQueryBuilder(p); @@ -35,9 +36,10 @@ public class TraveltimeQueryParser implements QueryParser qb.setMode(findByNameOrError("transportation mode", s, Util::findModeByName)), mode); queryParser.declareString((qb, s) -> qb.setCountry(findByNameOrError("country", s, Util::findCountryByName)), country); - queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("country", s, Util::findRequestTypeByName)), requestType); + queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("request mode", s, Util::findRequestTypeByName)), requestType); queryParser.declareObject(TraveltimeQueryBuilder::setPrefilter, prefilterParser, prefilter); queryParser.declareString(TraveltimeQueryBuilder::setOutput, output); + queryParser.declareString(TraveltimeQueryBuilder::setDistanceOutput, distanceOutput); queryParser.declareRequiredFieldSet(field.toString()); queryParser.declareRequiredFieldSet(origin.toString()); diff --git a/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java b/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java index 0ee3888..0bc37e5 100644 --- a/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java +++ b/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java @@ -15,6 +15,7 @@ public class TraveltimeSearchQuery extends Query { private final TraveltimeQueryParameters params; private final Query prefilter; private final String output; + private final String distanceOutput; private final URI appUri; private final String appId; private final String apiKey; @@ -44,7 +45,7 @@ public Query rewrite(IndexSearcher reader) throws IOException { if (newPrefilter == prefilter) { return super.rewrite(reader); } else { - return new TraveltimeSearchQuery(params, newPrefilter, output, appUri, appId, apiKey); + return new TraveltimeSearchQuery(params, newPrefilter, output, distanceOutput, appUri, appId, apiKey); } } } diff --git a/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java b/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java index a990cba..7f365e8 100644 --- a/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java +++ b/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java @@ -116,18 +116,45 @@ public Scorer scorer(LeafReaderContext context) throws IOException { val pointToTime = new Long2IntOpenHashMap(valueArray.size()); - val results = protoFetcher.getTimes( - ttQuery.getParams().getOrigin(), - decodedArray, - ttQuery.getParams().getLimit(), - ttQuery.getParams().getMode(), - ttQuery.getParams().getCountry(), - ttQuery.getParams().getRequestType() - ); - - for (int index = 0; index < results.size(); index++) { - if(results.get(index) >= 0) { - pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + if (ttQuery.getParams().isIncludeDistance()) { + val pointToDistance = new Long2IntOpenHashMap(valueArray.size()); + + val mode = Util.unsafeCastToDistanceTransportation(ttQuery.getParams().getMode()); + + val timeDistance = protoFetcher.getTimesAndDistances( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + mode, + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + val times = timeDistance.getLeft(); + val distances = timeDistance.getRight(); + + for (int index = 0; index < times.size(); index++) { + if (times.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), times.get(index).intValue()); + pointToDistance.put(valueArray.getLong(index), distances.get(index).intValue()); + } + } + + TraveltimeCache.DISTANCE.add(ttQuery.getParams(), pointToDistance); + } else { + val results = protoFetcher.getTimes( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + ttQuery.getParams().getMode(), + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + for (int index = 0; index < results.size(); index++) { + if (results.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + } } } From 22cd3f905ea3ce167e7164d51f5ec167af415a3c Mon Sep 17 00:00:00 2001 From: Marcin Januszkiewicz Date: Thu, 29 Aug 2024 13:18:32 +0200 Subject: [PATCH 19/24] Apply patch to 8.11 --- .../elasticsearch/TraveltimePlugin.java | 2 + .../query/TraveltimeFetchPhase.java | 16 ++++-- .../query/TraveltimeQueryBuilder.java | 4 +- .../query/TraveltimeQueryParser.java | 4 +- .../query/TraveltimeSearchQuery.java | 3 +- .../elasticsearch/query/TraveltimeWeight.java | 51 ++++++++++++++----- 6 files changed, 62 insertions(+), 18 deletions(-) diff --git a/8.11/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java b/8.11/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java index 89720ba..c26cc3e 100644 --- a/8.11/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java +++ b/8.11/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java @@ -50,6 +50,7 @@ public class TraveltimePlugin extends Plugin implements SearchPlugin { private void cleanUpAndReschedule(ThreadPool threadPool, TimeValue cleanupSeconds) { TraveltimeCache.INSTANCE.cleanUp(); + TraveltimeCache.DISTANCE.cleanUp(); threadPool.scheduleUnlessShuttingDown(cleanupSeconds, threadPool.generic(), () -> cleanUpAndReschedule(threadPool, cleanupSeconds)); } @@ -75,6 +76,7 @@ public Collection createComponents( Integer cacheSize = CACHE_SIZE.get(environment.settings()); TraveltimeCache.INSTANCE.setUp(cacheSize, cacheExpiry); + TraveltimeCache.DISTANCE.setUp(cacheSize, cacheExpiry); cleanUpAndReschedule(threadPool, cleanupSeconds); return super.createComponents(client, clusterService, threadPool, resourceWatcherService, scriptService, xContentRegistry, environment, nodeEnvironment, namedWriteableRegistry, indexNameExpressionResolver, repositoriesServiceSupplier, telemetryProvider, allocationService, indicesService); diff --git a/8.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/8.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 019a235..2230825 100644 --- a/8.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/8.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -47,6 +47,7 @@ public FetchSubPhaseProcessor getProcessor(FetchContext fetchContext) { if (traveltimeQuery == null) return null; TraveltimeQueryParameters params = traveltimeQuery.getParams(); final String output = traveltimeQuery.getOutput(); + final String distanceOutput = traveltimeQuery.getDistanceOutput(); FieldFetcher fieldFetcher = FieldFetcher.create(fetchContext.getSearchExecutionContext(), List.of(new FieldAndFormat(params.getField(), null))); @@ -61,10 +62,19 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + val point = docValues.nextValue(); + if (!output.isEmpty()) { + Integer tt = TraveltimeCache.INSTANCE.get(params, point); + if (tt >= 0) { + hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + } + } - if (tt >= 0) { - hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + if (!distanceOutput.isEmpty()) { + Integer td = TraveltimeCache.DISTANCE.get(params, point); + if (td >= 0) { + hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); + } } } diff --git a/8.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/8.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index 4b962d5..7d73359 100644 --- a/8.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/8.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -69,6 +69,7 @@ protected void doWriteTo(StreamOutput out) throws IOException { out.writeOptionalEnum(requestType); out.writeOptionalNamedWriteable(prefilter); out.writeString(output); + out.writeString(distanceOutput); } @Override @@ -81,6 +82,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.field("requestType", requestType == null ? null : requestType.name()); builder.field("prefilter", prefilter); builder.field("output", output); + builder.field("distanceOutput", distanceOutput); } @Override @@ -153,7 +155,7 @@ protected Query doToQuery(SearchExecutionContext context) throws IOException { Query prefilterQuery = prefilter != null ? prefilter.toQuery(context) : null; - return new TraveltimeSearchQuery(params, prefilterQuery, output, appUri, appId, apiKey); + return new TraveltimeSearchQuery(params, prefilterQuery, output, distanceOutput, appUri, appId, apiKey); } @Override diff --git a/8.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java b/8.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java index 1705d39..ac2a6ab 100644 --- a/8.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java +++ b/8.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java @@ -24,6 +24,7 @@ public class TraveltimeQueryParser implements QueryParser prefilterParser = (p, c) -> TraveltimeQueryBuilder.parseInnerQueryBuilder(p); @@ -35,9 +36,10 @@ public class TraveltimeQueryParser implements QueryParser qb.setMode(findByNameOrError("transportation mode", s, Util::findModeByName)), mode); queryParser.declareString((qb, s) -> qb.setCountry(findByNameOrError("country", s, Util::findCountryByName)), country); - queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("country", s, Util::findRequestTypeByName)), requestType); + queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("request mode", s, Util::findRequestTypeByName)), requestType); queryParser.declareObject(TraveltimeQueryBuilder::setPrefilter, prefilterParser, prefilter); queryParser.declareString(TraveltimeQueryBuilder::setOutput, output); + queryParser.declareString(TraveltimeQueryBuilder::setDistanceOutput, distanceOutput); queryParser.declareRequiredFieldSet(field.toString()); queryParser.declareRequiredFieldSet(origin.toString()); diff --git a/8.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java b/8.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java index 0ee3888..0bc37e5 100644 --- a/8.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java +++ b/8.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java @@ -15,6 +15,7 @@ public class TraveltimeSearchQuery extends Query { private final TraveltimeQueryParameters params; private final Query prefilter; private final String output; + private final String distanceOutput; private final URI appUri; private final String appId; private final String apiKey; @@ -44,7 +45,7 @@ public Query rewrite(IndexSearcher reader) throws IOException { if (newPrefilter == prefilter) { return super.rewrite(reader); } else { - return new TraveltimeSearchQuery(params, newPrefilter, output, appUri, appId, apiKey); + return new TraveltimeSearchQuery(params, newPrefilter, output, distanceOutput, appUri, appId, apiKey); } } } diff --git a/8.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java b/8.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java index a990cba..7f365e8 100644 --- a/8.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java +++ b/8.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java @@ -116,18 +116,45 @@ public Scorer scorer(LeafReaderContext context) throws IOException { val pointToTime = new Long2IntOpenHashMap(valueArray.size()); - val results = protoFetcher.getTimes( - ttQuery.getParams().getOrigin(), - decodedArray, - ttQuery.getParams().getLimit(), - ttQuery.getParams().getMode(), - ttQuery.getParams().getCountry(), - ttQuery.getParams().getRequestType() - ); - - for (int index = 0; index < results.size(); index++) { - if(results.get(index) >= 0) { - pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + if (ttQuery.getParams().isIncludeDistance()) { + val pointToDistance = new Long2IntOpenHashMap(valueArray.size()); + + val mode = Util.unsafeCastToDistanceTransportation(ttQuery.getParams().getMode()); + + val timeDistance = protoFetcher.getTimesAndDistances( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + mode, + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + val times = timeDistance.getLeft(); + val distances = timeDistance.getRight(); + + for (int index = 0; index < times.size(); index++) { + if (times.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), times.get(index).intValue()); + pointToDistance.put(valueArray.getLong(index), distances.get(index).intValue()); + } + } + + TraveltimeCache.DISTANCE.add(ttQuery.getParams(), pointToDistance); + } else { + val results = protoFetcher.getTimes( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + ttQuery.getParams().getMode(), + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + for (int index = 0; index < results.size(); index++) { + if (results.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + } } } From 2207d5785b8ddc5d1c6eed151b25bdc8af21a93b Mon Sep 17 00:00:00 2001 From: Marcin Januszkiewicz Date: Thu, 29 Aug 2024 13:20:03 +0200 Subject: [PATCH 20/24] Apply patch to 8.12 --- .../elasticsearch/TraveltimePlugin.java | 2 + .../query/TraveltimeFetchPhase.java | 16 ++++-- .../query/TraveltimeQueryBuilder.java | 5 +- .../query/TraveltimeQueryParser.java | 4 +- .../query/TraveltimeSearchQuery.java | 3 +- .../elasticsearch/query/TraveltimeWeight.java | 51 ++++++++++++++----- 6 files changed, 63 insertions(+), 18 deletions(-) diff --git a/8.12/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java b/8.12/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java index d0c837d..1153fc8 100644 --- a/8.12/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java +++ b/8.12/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java @@ -50,6 +50,7 @@ public class TraveltimePlugin extends Plugin implements SearchPlugin { private void cleanUpAndReschedule(ThreadPool threadPool, TimeValue cleanupSeconds) { TraveltimeCache.INSTANCE.cleanUp(); + TraveltimeCache.DISTANCE.cleanUp(); threadPool.scheduleUnlessShuttingDown(cleanupSeconds, threadPool.generic(), () -> cleanUpAndReschedule(threadPool, cleanupSeconds)); } @@ -60,6 +61,7 @@ public Collection createComponents(PluginServices pluginServices) { Integer cacheSize = CACHE_SIZE.get(pluginServices.environment().settings()); TraveltimeCache.INSTANCE.setUp(cacheSize, cacheExpiry); + TraveltimeCache.DISTANCE.setUp(cacheSize, cacheExpiry); cleanUpAndReschedule(pluginServices.threadPool(), cleanupSeconds); return super.createComponents(pluginServices); diff --git a/8.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/8.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 019a235..2230825 100644 --- a/8.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/8.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -47,6 +47,7 @@ public FetchSubPhaseProcessor getProcessor(FetchContext fetchContext) { if (traveltimeQuery == null) return null; TraveltimeQueryParameters params = traveltimeQuery.getParams(); final String output = traveltimeQuery.getOutput(); + final String distanceOutput = traveltimeQuery.getDistanceOutput(); FieldFetcher fieldFetcher = FieldFetcher.create(fetchContext.getSearchExecutionContext(), List.of(new FieldAndFormat(params.getField(), null))); @@ -61,10 +62,19 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + val point = docValues.nextValue(); + if (!output.isEmpty()) { + Integer tt = TraveltimeCache.INSTANCE.get(params, point); + if (tt >= 0) { + hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + } + } - if (tt >= 0) { - hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + if (!distanceOutput.isEmpty()) { + Integer td = TraveltimeCache.DISTANCE.get(params, point); + if (td >= 0) { + hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); + } } } diff --git a/8.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/8.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index 4137a2d..eb28878 100644 --- a/8.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/8.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -131,6 +131,9 @@ protected Query doToQuery(SearchExecutionContext context) throws IOException { throw new IllegalStateException("Traveltime query requires either 'mode' field to be present or a default mode to be set in the config"); } } + if(params.isIncludeDistance() && !Util.canUseDistance(params.getMode())) { + throw new IllegalStateException("Traveltime query with distance output cannot be used with public transportation mode"); + } if (params.getCountry() == null) { if (defaultCountry.isPresent()) { params = params.withCountry(defaultCountry.get()); @@ -152,7 +155,7 @@ protected Query doToQuery(SearchExecutionContext context) throws IOException { Query prefilterQuery = prefilter != null ? prefilter.toQuery(context) : null; - return new TraveltimeSearchQuery(params, prefilterQuery, output, appUri, appId, apiKey); + return new TraveltimeSearchQuery(params, prefilterQuery, output, distanceOutput, appUri, appId, apiKey); } @Override diff --git a/8.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java b/8.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java index 1705d39..ac2a6ab 100644 --- a/8.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java +++ b/8.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java @@ -24,6 +24,7 @@ public class TraveltimeQueryParser implements QueryParser prefilterParser = (p, c) -> TraveltimeQueryBuilder.parseInnerQueryBuilder(p); @@ -35,9 +36,10 @@ public class TraveltimeQueryParser implements QueryParser qb.setMode(findByNameOrError("transportation mode", s, Util::findModeByName)), mode); queryParser.declareString((qb, s) -> qb.setCountry(findByNameOrError("country", s, Util::findCountryByName)), country); - queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("country", s, Util::findRequestTypeByName)), requestType); + queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("request mode", s, Util::findRequestTypeByName)), requestType); queryParser.declareObject(TraveltimeQueryBuilder::setPrefilter, prefilterParser, prefilter); queryParser.declareString(TraveltimeQueryBuilder::setOutput, output); + queryParser.declareString(TraveltimeQueryBuilder::setDistanceOutput, distanceOutput); queryParser.declareRequiredFieldSet(field.toString()); queryParser.declareRequiredFieldSet(origin.toString()); diff --git a/8.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java b/8.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java index 0ee3888..0bc37e5 100644 --- a/8.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java +++ b/8.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java @@ -15,6 +15,7 @@ public class TraveltimeSearchQuery extends Query { private final TraveltimeQueryParameters params; private final Query prefilter; private final String output; + private final String distanceOutput; private final URI appUri; private final String appId; private final String apiKey; @@ -44,7 +45,7 @@ public Query rewrite(IndexSearcher reader) throws IOException { if (newPrefilter == prefilter) { return super.rewrite(reader); } else { - return new TraveltimeSearchQuery(params, newPrefilter, output, appUri, appId, apiKey); + return new TraveltimeSearchQuery(params, newPrefilter, output, distanceOutput, appUri, appId, apiKey); } } } diff --git a/8.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java b/8.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java index a990cba..7f365e8 100644 --- a/8.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java +++ b/8.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java @@ -116,18 +116,45 @@ public Scorer scorer(LeafReaderContext context) throws IOException { val pointToTime = new Long2IntOpenHashMap(valueArray.size()); - val results = protoFetcher.getTimes( - ttQuery.getParams().getOrigin(), - decodedArray, - ttQuery.getParams().getLimit(), - ttQuery.getParams().getMode(), - ttQuery.getParams().getCountry(), - ttQuery.getParams().getRequestType() - ); - - for (int index = 0; index < results.size(); index++) { - if(results.get(index) >= 0) { - pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + if (ttQuery.getParams().isIncludeDistance()) { + val pointToDistance = new Long2IntOpenHashMap(valueArray.size()); + + val mode = Util.unsafeCastToDistanceTransportation(ttQuery.getParams().getMode()); + + val timeDistance = protoFetcher.getTimesAndDistances( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + mode, + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + val times = timeDistance.getLeft(); + val distances = timeDistance.getRight(); + + for (int index = 0; index < times.size(); index++) { + if (times.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), times.get(index).intValue()); + pointToDistance.put(valueArray.getLong(index), distances.get(index).intValue()); + } + } + + TraveltimeCache.DISTANCE.add(ttQuery.getParams(), pointToDistance); + } else { + val results = protoFetcher.getTimes( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + ttQuery.getParams().getMode(), + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + for (int index = 0; index < results.size(); index++) { + if (results.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + } } } From ce5fbe02baafeee02b6e5bc70af1ed20439b2fe2 Mon Sep 17 00:00:00 2001 From: Marcin Januszkiewicz Date: Thu, 29 Aug 2024 13:21:04 +0200 Subject: [PATCH 21/24] Apply patch to 8.13 --- .../elasticsearch/TraveltimePlugin.java | 2 + .../query/TraveltimeFetchPhase.java | 16 ++++-- .../query/TraveltimeQueryBuilder.java | 5 +- .../query/TraveltimeQueryParser.java | 4 +- .../query/TraveltimeSearchQuery.java | 3 +- .../elasticsearch/query/TraveltimeWeight.java | 51 ++++++++++++++----- 6 files changed, 63 insertions(+), 18 deletions(-) diff --git a/8.13/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java b/8.13/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java index d0c837d..1153fc8 100644 --- a/8.13/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java +++ b/8.13/src/main/java/com/traveltime/plugin/elasticsearch/TraveltimePlugin.java @@ -50,6 +50,7 @@ public class TraveltimePlugin extends Plugin implements SearchPlugin { private void cleanUpAndReschedule(ThreadPool threadPool, TimeValue cleanupSeconds) { TraveltimeCache.INSTANCE.cleanUp(); + TraveltimeCache.DISTANCE.cleanUp(); threadPool.scheduleUnlessShuttingDown(cleanupSeconds, threadPool.generic(), () -> cleanUpAndReschedule(threadPool, cleanupSeconds)); } @@ -60,6 +61,7 @@ public Collection createComponents(PluginServices pluginServices) { Integer cacheSize = CACHE_SIZE.get(pluginServices.environment().settings()); TraveltimeCache.INSTANCE.setUp(cacheSize, cacheExpiry); + TraveltimeCache.DISTANCE.setUp(cacheSize, cacheExpiry); cleanUpAndReschedule(pluginServices.threadPool(), cleanupSeconds); return super.createComponents(pluginServices); diff --git a/8.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java b/8.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java index 019a235..2230825 100644 --- a/8.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java +++ b/8.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeFetchPhase.java @@ -47,6 +47,7 @@ public FetchSubPhaseProcessor getProcessor(FetchContext fetchContext) { if (traveltimeQuery == null) return null; TraveltimeQueryParameters params = traveltimeQuery.getParams(); final String output = traveltimeQuery.getOutput(); + final String distanceOutput = traveltimeQuery.getDistanceOutput(); FieldFetcher fieldFetcher = FieldFetcher.create(fetchContext.getSearchExecutionContext(), List.of(new FieldAndFormat(params.getField(), null))); @@ -61,10 +62,19 @@ public void setNextReader(LeafReaderContext readerContext) { public void process(HitContext hitContext) throws IOException { val docValues = hitContext.reader().getSortedNumericDocValues(params.getField()); docValues.advance(hitContext.docId()); - Integer tt = TraveltimeCache.INSTANCE.get(params, docValues.nextValue()); + val point = docValues.nextValue(); + if (!output.isEmpty()) { + Integer tt = TraveltimeCache.INSTANCE.get(params, point); + if (tt >= 0) { + hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + } + } - if (tt >= 0) { - hitContext.hit().setDocumentField(output, new DocumentField(output, List.of(tt))); + if (!distanceOutput.isEmpty()) { + Integer td = TraveltimeCache.DISTANCE.get(params, point); + if (td >= 0) { + hitContext.hit().setDocumentField(distanceOutput, new DocumentField(distanceOutput, List.of(td))); + } } } diff --git a/8.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/8.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index 4137a2d..eb28878 100644 --- a/8.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/8.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -131,6 +131,9 @@ protected Query doToQuery(SearchExecutionContext context) throws IOException { throw new IllegalStateException("Traveltime query requires either 'mode' field to be present or a default mode to be set in the config"); } } + if(params.isIncludeDistance() && !Util.canUseDistance(params.getMode())) { + throw new IllegalStateException("Traveltime query with distance output cannot be used with public transportation mode"); + } if (params.getCountry() == null) { if (defaultCountry.isPresent()) { params = params.withCountry(defaultCountry.get()); @@ -152,7 +155,7 @@ protected Query doToQuery(SearchExecutionContext context) throws IOException { Query prefilterQuery = prefilter != null ? prefilter.toQuery(context) : null; - return new TraveltimeSearchQuery(params, prefilterQuery, output, appUri, appId, apiKey); + return new TraveltimeSearchQuery(params, prefilterQuery, output, distanceOutput, appUri, appId, apiKey); } @Override diff --git a/8.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java b/8.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java index 1705d39..ac2a6ab 100644 --- a/8.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java +++ b/8.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java @@ -24,6 +24,7 @@ public class TraveltimeQueryParser implements QueryParser prefilterParser = (p, c) -> TraveltimeQueryBuilder.parseInnerQueryBuilder(p); @@ -35,9 +36,10 @@ public class TraveltimeQueryParser implements QueryParser qb.setMode(findByNameOrError("transportation mode", s, Util::findModeByName)), mode); queryParser.declareString((qb, s) -> qb.setCountry(findByNameOrError("country", s, Util::findCountryByName)), country); - queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("country", s, Util::findRequestTypeByName)), requestType); + queryParser.declareString((qb, s) -> qb.setRequestType(findByNameOrError("request mode", s, Util::findRequestTypeByName)), requestType); queryParser.declareObject(TraveltimeQueryBuilder::setPrefilter, prefilterParser, prefilter); queryParser.declareString(TraveltimeQueryBuilder::setOutput, output); + queryParser.declareString(TraveltimeQueryBuilder::setDistanceOutput, distanceOutput); queryParser.declareRequiredFieldSet(field.toString()); queryParser.declareRequiredFieldSet(origin.toString()); diff --git a/8.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java b/8.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java index 0ee3888..0bc37e5 100644 --- a/8.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java +++ b/8.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeSearchQuery.java @@ -15,6 +15,7 @@ public class TraveltimeSearchQuery extends Query { private final TraveltimeQueryParameters params; private final Query prefilter; private final String output; + private final String distanceOutput; private final URI appUri; private final String appId; private final String apiKey; @@ -44,7 +45,7 @@ public Query rewrite(IndexSearcher reader) throws IOException { if (newPrefilter == prefilter) { return super.rewrite(reader); } else { - return new TraveltimeSearchQuery(params, newPrefilter, output, appUri, appId, apiKey); + return new TraveltimeSearchQuery(params, newPrefilter, output, distanceOutput, appUri, appId, apiKey); } } } diff --git a/8.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java b/8.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java index a990cba..7f365e8 100644 --- a/8.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java +++ b/8.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java @@ -116,18 +116,45 @@ public Scorer scorer(LeafReaderContext context) throws IOException { val pointToTime = new Long2IntOpenHashMap(valueArray.size()); - val results = protoFetcher.getTimes( - ttQuery.getParams().getOrigin(), - decodedArray, - ttQuery.getParams().getLimit(), - ttQuery.getParams().getMode(), - ttQuery.getParams().getCountry(), - ttQuery.getParams().getRequestType() - ); - - for (int index = 0; index < results.size(); index++) { - if(results.get(index) >= 0) { - pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + if (ttQuery.getParams().isIncludeDistance()) { + val pointToDistance = new Long2IntOpenHashMap(valueArray.size()); + + val mode = Util.unsafeCastToDistanceTransportation(ttQuery.getParams().getMode()); + + val timeDistance = protoFetcher.getTimesAndDistances( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + mode, + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + val times = timeDistance.getLeft(); + val distances = timeDistance.getRight(); + + for (int index = 0; index < times.size(); index++) { + if (times.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), times.get(index).intValue()); + pointToDistance.put(valueArray.getLong(index), distances.get(index).intValue()); + } + } + + TraveltimeCache.DISTANCE.add(ttQuery.getParams(), pointToDistance); + } else { + val results = protoFetcher.getTimes( + ttQuery.getParams().getOrigin(), + decodedArray, + ttQuery.getParams().getLimit(), + ttQuery.getParams().getMode(), + ttQuery.getParams().getCountry(), + ttQuery.getParams().getRequestType() + ); + + for (int index = 0; index < results.size(); index++) { + if (results.get(index) >= 0) { + pointToTime.put(valueArray.getLong(index), results.get(index).intValue()); + } } } From 0aff981bb49b6f363582d2b861c13fc4e02fc282 Mon Sep 17 00:00:00 2001 From: Marcin Januszkiewicz Date: Thu, 29 Aug 2024 13:36:34 +0200 Subject: [PATCH 22/24] Unify query builders --- .../plugin/elasticsearch/query/TraveltimeQueryBuilder.java | 2 +- .../plugin/elasticsearch/query/TraveltimeQueryBuilder.java | 2 +- .../plugin/elasticsearch/query/TraveltimeQueryBuilder.java | 3 +++ .../plugin/elasticsearch/query/TraveltimeQueryBuilder.java | 3 +++ .../plugin/elasticsearch/query/TraveltimeQueryBuilder.java | 3 +++ .../plugin/elasticsearch/query/TraveltimeQueryBuilder.java | 3 +++ .../plugin/elasticsearch/query/TraveltimeQueryBuilder.java | 3 +++ .../plugin/elasticsearch/query/TraveltimeQueryBuilder.java | 3 +++ .../plugin/elasticsearch/query/TraveltimeQueryBuilder.java | 3 +++ .../plugin/elasticsearch/query/TraveltimeQueryBuilder.java | 3 +++ .../plugin/elasticsearch/query/TraveltimeQueryBuilder.java | 2 +- .../plugin/elasticsearch/query/TraveltimeQueryBuilder.java | 2 +- .../plugin/elasticsearch/query/TraveltimeQueryBuilder.java | 2 +- .../plugin/elasticsearch/query/TraveltimeQueryBuilder.java | 3 +++ .../plugin/elasticsearch/query/TraveltimeQueryBuilder.java | 3 +++ .../plugin/elasticsearch/query/TraveltimeQueryBuilder.java | 3 +++ .../plugin/elasticsearch/query/TraveltimeQueryBuilder.java | 3 +++ .../plugin/elasticsearch/query/TraveltimeQueryBuilder.java | 3 +++ .../plugin/elasticsearch/query/TraveltimeQueryBuilder.java | 3 +++ .../plugin/elasticsearch/query/TraveltimeQueryBuilder.java | 3 +++ .../plugin/elasticsearch/query/TraveltimeQueryBuilder.java | 3 +++ 21 files changed, 53 insertions(+), 5 deletions(-) diff --git a/7.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/7.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index d54d801..7fc0e68 100644 --- a/7.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/7.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -93,7 +93,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.field("country", country == null ? null : country.getValue()); builder.field("prefilter", prefilter); builder.field("output", output); - builder.field("distance_output", distanceOutput); + builder.field("distanceOutput", distanceOutput); } @Override diff --git a/7.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/7.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index be01bc0..96746a3 100644 --- a/7.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/7.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -93,7 +93,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.field("country", country == null ? null : country.getValue()); builder.field("prefilter", prefilter); builder.field("output", output); - builder.field("distance_output", distanceOutput); + builder.field("distanceOutput", distanceOutput); } @Override diff --git a/7.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/7.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index 0d83e1c..8aa58a8 100644 --- a/7.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/7.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -53,6 +53,7 @@ public TraveltimeQueryBuilder(StreamInput in) throws IOException { requestType = in.readOptionalEnum(RequestType.class); prefilter = in.readOptionalNamedWriteable(QueryBuilder.class); output = in.readString(); + distanceOutput = in.readString(); } @Override @@ -65,6 +66,7 @@ protected void doWriteTo(StreamOutput out) throws IOException { out.writeOptionalEnum(requestType); out.writeOptionalNamedWriteable(prefilter); out.writeString(output); + out.writeString(distanceOutput); } @Override @@ -77,6 +79,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.field("requestType", requestType == null ? null : requestType.name()); builder.field("prefilter", prefilter); builder.field("output", output); + builder.field("distanceOutput", distanceOutput); } @Override diff --git a/7.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/7.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index 0d83e1c..8aa58a8 100644 --- a/7.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/7.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -53,6 +53,7 @@ public TraveltimeQueryBuilder(StreamInput in) throws IOException { requestType = in.readOptionalEnum(RequestType.class); prefilter = in.readOptionalNamedWriteable(QueryBuilder.class); output = in.readString(); + distanceOutput = in.readString(); } @Override @@ -65,6 +66,7 @@ protected void doWriteTo(StreamOutput out) throws IOException { out.writeOptionalEnum(requestType); out.writeOptionalNamedWriteable(prefilter); out.writeString(output); + out.writeString(distanceOutput); } @Override @@ -77,6 +79,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.field("requestType", requestType == null ? null : requestType.name()); builder.field("prefilter", prefilter); builder.field("output", output); + builder.field("distanceOutput", distanceOutput); } @Override diff --git a/7.14/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/7.14/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index 0d83e1c..8aa58a8 100644 --- a/7.14/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/7.14/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -53,6 +53,7 @@ public TraveltimeQueryBuilder(StreamInput in) throws IOException { requestType = in.readOptionalEnum(RequestType.class); prefilter = in.readOptionalNamedWriteable(QueryBuilder.class); output = in.readString(); + distanceOutput = in.readString(); } @Override @@ -65,6 +66,7 @@ protected void doWriteTo(StreamOutput out) throws IOException { out.writeOptionalEnum(requestType); out.writeOptionalNamedWriteable(prefilter); out.writeString(output); + out.writeString(distanceOutput); } @Override @@ -77,6 +79,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.field("requestType", requestType == null ? null : requestType.name()); builder.field("prefilter", prefilter); builder.field("output", output); + builder.field("distanceOutput", distanceOutput); } @Override diff --git a/7.15/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/7.15/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index 0d83e1c..8aa58a8 100644 --- a/7.15/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/7.15/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -53,6 +53,7 @@ public TraveltimeQueryBuilder(StreamInput in) throws IOException { requestType = in.readOptionalEnum(RequestType.class); prefilter = in.readOptionalNamedWriteable(QueryBuilder.class); output = in.readString(); + distanceOutput = in.readString(); } @Override @@ -65,6 +66,7 @@ protected void doWriteTo(StreamOutput out) throws IOException { out.writeOptionalEnum(requestType); out.writeOptionalNamedWriteable(prefilter); out.writeString(output); + out.writeString(distanceOutput); } @Override @@ -77,6 +79,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.field("requestType", requestType == null ? null : requestType.name()); builder.field("prefilter", prefilter); builder.field("output", output); + builder.field("distanceOutput", distanceOutput); } @Override diff --git a/7.16/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/7.16/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index 041d632..84237a3 100644 --- a/7.16/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/7.16/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -53,6 +53,7 @@ public TraveltimeQueryBuilder(StreamInput in) throws IOException { requestType = in.readOptionalEnum(RequestType.class); prefilter = in.readOptionalNamedWriteable(QueryBuilder.class); output = in.readString(); + distanceOutput = in.readString(); } @Override @@ -65,6 +66,7 @@ protected void doWriteTo(StreamOutput out) throws IOException { out.writeOptionalEnum(requestType); out.writeOptionalNamedWriteable(prefilter); out.writeString(output); + out.writeString(distanceOutput); } @Override @@ -77,6 +79,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.field("requestType", requestType == null ? null : requestType.name()); builder.field("prefilter", prefilter); builder.field("output", output); + builder.field("distanceOutput", distanceOutput); } @Override diff --git a/7.17/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/7.17/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index 041d632..84237a3 100644 --- a/7.17/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/7.17/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -53,6 +53,7 @@ public TraveltimeQueryBuilder(StreamInput in) throws IOException { requestType = in.readOptionalEnum(RequestType.class); prefilter = in.readOptionalNamedWriteable(QueryBuilder.class); output = in.readString(); + distanceOutput = in.readString(); } @Override @@ -65,6 +66,7 @@ protected void doWriteTo(StreamOutput out) throws IOException { out.writeOptionalEnum(requestType); out.writeOptionalNamedWriteable(prefilter); out.writeString(output); + out.writeString(distanceOutput); } @Override @@ -77,6 +79,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.field("requestType", requestType == null ? null : requestType.name()); builder.field("prefilter", prefilter); builder.field("output", output); + builder.field("distanceOutput", distanceOutput); } @Override diff --git a/8.0/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/8.0/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index 041d632..84237a3 100644 --- a/8.0/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/8.0/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -53,6 +53,7 @@ public TraveltimeQueryBuilder(StreamInput in) throws IOException { requestType = in.readOptionalEnum(RequestType.class); prefilter = in.readOptionalNamedWriteable(QueryBuilder.class); output = in.readString(); + distanceOutput = in.readString(); } @Override @@ -65,6 +66,7 @@ protected void doWriteTo(StreamOutput out) throws IOException { out.writeOptionalEnum(requestType); out.writeOptionalNamedWriteable(prefilter); out.writeString(output); + out.writeString(distanceOutput); } @Override @@ -77,6 +79,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.field("requestType", requestType == null ? null : requestType.name()); builder.field("prefilter", prefilter); builder.field("output", output); + builder.field("distanceOutput", distanceOutput); } @Override diff --git a/8.1/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/8.1/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index 041d632..84237a3 100644 --- a/8.1/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/8.1/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -53,6 +53,7 @@ public TraveltimeQueryBuilder(StreamInput in) throws IOException { requestType = in.readOptionalEnum(RequestType.class); prefilter = in.readOptionalNamedWriteable(QueryBuilder.class); output = in.readString(); + distanceOutput = in.readString(); } @Override @@ -65,6 +66,7 @@ protected void doWriteTo(StreamOutput out) throws IOException { out.writeOptionalEnum(requestType); out.writeOptionalNamedWriteable(prefilter); out.writeString(output); + out.writeString(distanceOutput); } @Override @@ -77,6 +79,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.field("requestType", requestType == null ? null : requestType.name()); builder.field("prefilter", prefilter); builder.field("output", output); + builder.field("distanceOutput", distanceOutput); } @Override diff --git a/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index 7045c88..3225ea4 100644 --- a/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -81,7 +81,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.field("requestType", requestType == null ? null : requestType.name()); builder.field("prefilter", prefilter); builder.field("output", output); - builder.field("distance_output", distanceOutput); + builder.field("distanceOutput", distanceOutput); } @Override diff --git a/8.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/8.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index eb28878..d6f78b2 100644 --- a/8.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/8.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -82,7 +82,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.field("requestType", requestType == null ? null : requestType.name()); builder.field("prefilter", prefilter); builder.field("output", output); - builder.field("distance_output", distanceOutput); + builder.field("distanceOutput", distanceOutput); } @Override diff --git a/8.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/8.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index eb28878..d6f78b2 100644 --- a/8.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/8.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -82,7 +82,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.field("requestType", requestType == null ? null : requestType.name()); builder.field("prefilter", prefilter); builder.field("output", output); - builder.field("distance_output", distanceOutput); + builder.field("distanceOutput", distanceOutput); } @Override diff --git a/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index 1256faa..6000a45 100644 --- a/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -54,6 +54,7 @@ public TraveltimeQueryBuilder(StreamInput in) throws IOException { requestType = in.readOptionalEnum(RequestType.class); prefilter = in.readOptionalNamedWriteable(QueryBuilder.class); output = in.readString(); + distanceOutput = in.readString(); } @Override @@ -66,6 +67,7 @@ protected void doWriteTo(StreamOutput out) throws IOException { out.writeOptionalEnum(requestType); out.writeOptionalNamedWriteable(prefilter); out.writeString(output); + out.writeString(distanceOutput); } @Override @@ -78,6 +80,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.field("requestType", requestType == null ? null : requestType.name()); builder.field("prefilter", prefilter); builder.field("output", output); + builder.field("distanceOutput", distanceOutput); } @Override diff --git a/8.3/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/8.3/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index 1256faa..6000a45 100644 --- a/8.3/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/8.3/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -54,6 +54,7 @@ public TraveltimeQueryBuilder(StreamInput in) throws IOException { requestType = in.readOptionalEnum(RequestType.class); prefilter = in.readOptionalNamedWriteable(QueryBuilder.class); output = in.readString(); + distanceOutput = in.readString(); } @Override @@ -66,6 +67,7 @@ protected void doWriteTo(StreamOutput out) throws IOException { out.writeOptionalEnum(requestType); out.writeOptionalNamedWriteable(prefilter); out.writeString(output); + out.writeString(distanceOutput); } @Override @@ -78,6 +80,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.field("requestType", requestType == null ? null : requestType.name()); builder.field("prefilter", prefilter); builder.field("output", output); + builder.field("distanceOutput", distanceOutput); } @Override diff --git a/8.4/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/8.4/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index 1256faa..6000a45 100644 --- a/8.4/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/8.4/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -54,6 +54,7 @@ public TraveltimeQueryBuilder(StreamInput in) throws IOException { requestType = in.readOptionalEnum(RequestType.class); prefilter = in.readOptionalNamedWriteable(QueryBuilder.class); output = in.readString(); + distanceOutput = in.readString(); } @Override @@ -66,6 +67,7 @@ protected void doWriteTo(StreamOutput out) throws IOException { out.writeOptionalEnum(requestType); out.writeOptionalNamedWriteable(prefilter); out.writeString(output); + out.writeString(distanceOutput); } @Override @@ -78,6 +80,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.field("requestType", requestType == null ? null : requestType.name()); builder.field("prefilter", prefilter); builder.field("output", output); + builder.field("distanceOutput", distanceOutput); } @Override diff --git a/8.5/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/8.5/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index 09ad195..efd97ea 100644 --- a/8.5/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/8.5/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -54,6 +54,7 @@ public TraveltimeQueryBuilder(StreamInput in) throws IOException { requestType = in.readOptionalEnum(RequestType.class); prefilter = in.readOptionalNamedWriteable(QueryBuilder.class); output = in.readString(); + distanceOutput = in.readString(); } @Override @@ -66,6 +67,7 @@ protected void doWriteTo(StreamOutput out) throws IOException { out.writeOptionalEnum(requestType); out.writeOptionalNamedWriteable(prefilter); out.writeString(output); + out.writeString(distanceOutput); } @Override @@ -78,6 +80,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.field("requestType", requestType == null ? null : requestType.name()); builder.field("prefilter", prefilter); builder.field("output", output); + builder.field("distanceOutput", distanceOutput); } @Override diff --git a/8.6/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/8.6/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index a126374..fa14f86 100644 --- a/8.6/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/8.6/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -55,6 +55,7 @@ public TraveltimeQueryBuilder(StreamInput in) throws IOException { requestType = in.readOptionalEnum(RequestType.class); prefilter = in.readOptionalNamedWriteable(QueryBuilder.class); output = in.readString(); + distanceOutput = in.readString(); } @Override @@ -67,6 +68,7 @@ protected void doWriteTo(StreamOutput out) throws IOException { out.writeOptionalEnum(requestType); out.writeOptionalNamedWriteable(prefilter); out.writeString(output); + out.writeString(distanceOutput); } @Override @@ -79,6 +81,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.field("requestType", requestType == null ? null : requestType.name()); builder.field("prefilter", prefilter); builder.field("output", output); + builder.field("distanceOutput", distanceOutput); } @Override diff --git a/8.7/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/8.7/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index ea3ba4d..d4b6e9e 100644 --- a/8.7/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/8.7/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -55,6 +55,7 @@ public TraveltimeQueryBuilder(StreamInput in) throws IOException { requestType = in.readOptionalEnum(RequestType.class); prefilter = in.readOptionalNamedWriteable(QueryBuilder.class); output = in.readString(); + distanceOutput = in.readString(); } @Override @@ -67,6 +68,7 @@ protected void doWriteTo(StreamOutput out) throws IOException { out.writeOptionalEnum(requestType); out.writeOptionalNamedWriteable(prefilter); out.writeString(output); + out.writeString(distanceOutput); } @Override @@ -79,6 +81,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.field("requestType", requestType == null ? null : requestType.name()); builder.field("prefilter", prefilter); builder.field("output", output); + builder.field("distanceOutput", distanceOutput); } @Override diff --git a/8.8/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/8.8/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index ea3ba4d..d4b6e9e 100644 --- a/8.8/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/8.8/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -55,6 +55,7 @@ public TraveltimeQueryBuilder(StreamInput in) throws IOException { requestType = in.readOptionalEnum(RequestType.class); prefilter = in.readOptionalNamedWriteable(QueryBuilder.class); output = in.readString(); + distanceOutput = in.readString(); } @Override @@ -67,6 +68,7 @@ protected void doWriteTo(StreamOutput out) throws IOException { out.writeOptionalEnum(requestType); out.writeOptionalNamedWriteable(prefilter); out.writeString(output); + out.writeString(distanceOutput); } @Override @@ -79,6 +81,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.field("requestType", requestType == null ? null : requestType.name()); builder.field("prefilter", prefilter); builder.field("output", output); + builder.field("distanceOutput", distanceOutput); } @Override diff --git a/8.9/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java b/8.9/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java index 849752c..dfac8d5 100644 --- a/8.9/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java +++ b/8.9/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryBuilder.java @@ -55,6 +55,7 @@ public TraveltimeQueryBuilder(StreamInput in) throws IOException { requestType = in.readOptionalEnum(RequestType.class); prefilter = in.readOptionalNamedWriteable(QueryBuilder.class); output = in.readString(); + distanceOutput = in.readString(); } @Override @@ -67,6 +68,7 @@ protected void doWriteTo(StreamOutput out) throws IOException { out.writeOptionalEnum(requestType); out.writeOptionalNamedWriteable(prefilter); out.writeString(output); + out.writeString(distanceOutput); } @Override @@ -79,6 +81,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.field("requestType", requestType == null ? null : requestType.name()); builder.field("prefilter", prefilter); builder.field("output", output); + builder.field("distanceOutput", distanceOutput); } @Override From b1bf8ffef2f15554d006d97a7a688d18dc175a3c Mon Sep 17 00:00:00 2001 From: Marcin Januszkiewicz Date: Thu, 29 Aug 2024 14:41:49 +0200 Subject: [PATCH 23/24] Change distance output field name --- .../plugin/elasticsearch/query/TraveltimeQueryParser.java | 2 +- .../plugin/elasticsearch/query/TraveltimeQueryParser.java | 2 +- .../plugin/elasticsearch/query/TraveltimeQueryParser.java | 2 +- .../plugin/elasticsearch/query/TraveltimeQueryParser.java | 2 +- .../plugin/elasticsearch/query/TraveltimeQueryParser.java | 2 +- .../plugin/elasticsearch/query/TraveltimeQueryParser.java | 2 +- .../plugin/elasticsearch/query/TraveltimeQueryParser.java | 2 +- .../plugin/elasticsearch/query/TraveltimeQueryParser.java | 2 +- .../plugin/elasticsearch/query/TraveltimeQueryParser.java | 2 +- .../plugin/elasticsearch/query/TraveltimeQueryParser.java | 2 +- .../plugin/elasticsearch/query/TraveltimeQueryParser.java | 2 +- .../plugin/elasticsearch/query/TraveltimeQueryParser.java | 2 +- .../plugin/elasticsearch/query/TraveltimeQueryParser.java | 2 +- .../plugin/elasticsearch/query/TraveltimeQueryParser.java | 2 +- .../plugin/elasticsearch/query/TraveltimeQueryParser.java | 2 +- .../plugin/elasticsearch/query/TraveltimeQueryParser.java | 2 +- .../plugin/elasticsearch/query/TraveltimeQueryParser.java | 2 +- .../plugin/elasticsearch/query/TraveltimeQueryParser.java | 2 +- .../plugin/elasticsearch/query/TraveltimeQueryParser.java | 2 +- .../plugin/elasticsearch/query/TraveltimeQueryParser.java | 2 +- .../plugin/elasticsearch/query/TraveltimeQueryParser.java | 2 +- .../plugin/elasticsearch/query/TraveltimeQueryParser.java | 2 +- 22 files changed, 22 insertions(+), 22 deletions(-) diff --git a/7.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java b/7.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java index ec1e54b..a8bdac1 100644 --- a/7.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java +++ b/7.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java @@ -25,7 +25,7 @@ public class TraveltimeQueryParser implements QueryParser prefilterParser = (p, c) -> AbstractQueryBuilder.parseInnerQueryBuilder(p); diff --git a/7.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java b/7.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java index ec1e54b..a8bdac1 100644 --- a/7.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java +++ b/7.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java @@ -25,7 +25,7 @@ public class TraveltimeQueryParser implements QueryParser prefilterParser = (p, c) -> AbstractQueryBuilder.parseInnerQueryBuilder(p); diff --git a/7.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java b/7.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java index ec1e54b..a8bdac1 100644 --- a/7.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java +++ b/7.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java @@ -25,7 +25,7 @@ public class TraveltimeQueryParser implements QueryParser prefilterParser = (p, c) -> AbstractQueryBuilder.parseInnerQueryBuilder(p); diff --git a/7.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java b/7.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java index ec1e54b..a8bdac1 100644 --- a/7.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java +++ b/7.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java @@ -25,7 +25,7 @@ public class TraveltimeQueryParser implements QueryParser prefilterParser = (p, c) -> AbstractQueryBuilder.parseInnerQueryBuilder(p); diff --git a/7.14/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java b/7.14/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java index 9c7f6b8..7e7125d 100644 --- a/7.14/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java +++ b/7.14/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java @@ -25,7 +25,7 @@ public class TraveltimeQueryParser implements QueryParser prefilterParser = (p, c) -> AbstractQueryBuilder.parseInnerQueryBuilder(p); diff --git a/7.15/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java b/7.15/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java index 9c7f6b8..7e7125d 100644 --- a/7.15/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java +++ b/7.15/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java @@ -25,7 +25,7 @@ public class TraveltimeQueryParser implements QueryParser prefilterParser = (p, c) -> AbstractQueryBuilder.parseInnerQueryBuilder(p); diff --git a/7.16/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java b/7.16/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java index 9cf1040..4df2ba9 100644 --- a/7.16/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java +++ b/7.16/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java @@ -25,7 +25,7 @@ public class TraveltimeQueryParser implements QueryParser prefilterParser = (p, c) -> AbstractQueryBuilder.parseInnerQueryBuilder(p); diff --git a/7.17/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java b/7.17/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java index 9cf1040..4df2ba9 100644 --- a/7.17/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java +++ b/7.17/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java @@ -25,7 +25,7 @@ public class TraveltimeQueryParser implements QueryParser prefilterParser = (p, c) -> AbstractQueryBuilder.parseInnerQueryBuilder(p); diff --git a/8.0/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java b/8.0/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java index 9cf1040..4df2ba9 100644 --- a/8.0/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java +++ b/8.0/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java @@ -25,7 +25,7 @@ public class TraveltimeQueryParser implements QueryParser prefilterParser = (p, c) -> AbstractQueryBuilder.parseInnerQueryBuilder(p); diff --git a/8.1/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java b/8.1/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java index 9cf1040..4df2ba9 100644 --- a/8.1/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java +++ b/8.1/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java @@ -25,7 +25,7 @@ public class TraveltimeQueryParser implements QueryParser prefilterParser = (p, c) -> AbstractQueryBuilder.parseInnerQueryBuilder(p); diff --git a/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java b/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java index ac2a6ab..6f1deee 100644 --- a/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java +++ b/8.10/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java @@ -24,7 +24,7 @@ public class TraveltimeQueryParser implements QueryParser prefilterParser = (p, c) -> TraveltimeQueryBuilder.parseInnerQueryBuilder(p); diff --git a/8.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java b/8.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java index ac2a6ab..6f1deee 100644 --- a/8.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java +++ b/8.11/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java @@ -24,7 +24,7 @@ public class TraveltimeQueryParser implements QueryParser prefilterParser = (p, c) -> TraveltimeQueryBuilder.parseInnerQueryBuilder(p); diff --git a/8.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java b/8.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java index ac2a6ab..6f1deee 100644 --- a/8.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java +++ b/8.12/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java @@ -24,7 +24,7 @@ public class TraveltimeQueryParser implements QueryParser prefilterParser = (p, c) -> TraveltimeQueryBuilder.parseInnerQueryBuilder(p); diff --git a/8.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java b/8.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java index ac2a6ab..6f1deee 100644 --- a/8.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java +++ b/8.13/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java @@ -24,7 +24,7 @@ public class TraveltimeQueryParser implements QueryParser prefilterParser = (p, c) -> TraveltimeQueryBuilder.parseInnerQueryBuilder(p); diff --git a/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java b/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java index 9cf1040..4df2ba9 100644 --- a/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java +++ b/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java @@ -25,7 +25,7 @@ public class TraveltimeQueryParser implements QueryParser prefilterParser = (p, c) -> AbstractQueryBuilder.parseInnerQueryBuilder(p); diff --git a/8.3/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java b/8.3/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java index 9cf1040..4df2ba9 100644 --- a/8.3/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java +++ b/8.3/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java @@ -25,7 +25,7 @@ public class TraveltimeQueryParser implements QueryParser prefilterParser = (p, c) -> AbstractQueryBuilder.parseInnerQueryBuilder(p); diff --git a/8.4/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java b/8.4/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java index 9cf1040..4df2ba9 100644 --- a/8.4/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java +++ b/8.4/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java @@ -25,7 +25,7 @@ public class TraveltimeQueryParser implements QueryParser prefilterParser = (p, c) -> AbstractQueryBuilder.parseInnerQueryBuilder(p); diff --git a/8.5/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java b/8.5/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java index 9cf1040..4df2ba9 100644 --- a/8.5/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java +++ b/8.5/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java @@ -25,7 +25,7 @@ public class TraveltimeQueryParser implements QueryParser prefilterParser = (p, c) -> AbstractQueryBuilder.parseInnerQueryBuilder(p); diff --git a/8.6/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java b/8.6/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java index ac2a6ab..6f1deee 100644 --- a/8.6/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java +++ b/8.6/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java @@ -24,7 +24,7 @@ public class TraveltimeQueryParser implements QueryParser prefilterParser = (p, c) -> TraveltimeQueryBuilder.parseInnerQueryBuilder(p); diff --git a/8.7/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java b/8.7/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java index ac2a6ab..6f1deee 100644 --- a/8.7/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java +++ b/8.7/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java @@ -24,7 +24,7 @@ public class TraveltimeQueryParser implements QueryParser prefilterParser = (p, c) -> TraveltimeQueryBuilder.parseInnerQueryBuilder(p); diff --git a/8.8/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java b/8.8/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java index ac2a6ab..6f1deee 100644 --- a/8.8/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java +++ b/8.8/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java @@ -24,7 +24,7 @@ public class TraveltimeQueryParser implements QueryParser prefilterParser = (p, c) -> TraveltimeQueryBuilder.parseInnerQueryBuilder(p); diff --git a/8.9/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java b/8.9/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java index ac2a6ab..6f1deee 100644 --- a/8.9/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java +++ b/8.9/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeQueryParser.java @@ -24,7 +24,7 @@ public class TraveltimeQueryParser implements QueryParser prefilterParser = (p, c) -> TraveltimeQueryBuilder.parseInnerQueryBuilder(p); From 2e6dc2f358959b72f0e9d92cdf379ac0225c25ef Mon Sep 17 00:00:00 2001 From: Marcin Januszkiewicz Date: Thu, 29 Aug 2024 15:02:05 +0200 Subject: [PATCH 24/24] Fix misapplied patch --- .../plugin/elasticsearch/query/TraveltimeWeight.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java b/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java index d77793c..7f365e8 100644 --- a/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java +++ b/8.2/src/main/java/com/traveltime/plugin/elasticsearch/query/TraveltimeWeight.java @@ -158,6 +158,10 @@ public Scorer scorer(LeafReaderContext context) throws IOException { } } + if(hasOutput) { + TraveltimeCache.INSTANCE.add(ttQuery.getParams(), pointToTime); + } + return new TraveltimeScorer(this, pointToTime, filteredValues(context), boost); }