Skip to content

Commit

Permalink
Merge pull request #34 from traveltime-dev/distance-docs
Browse files Browse the repository at this point in the history
Distance docs
  • Loading branch information
mjanuszkiewicz-tt authored Aug 29, 2024
2 parents 519ec5c + 7f83219 commit d6a162d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import it.unimi.dsi.fastutil.longs.Long2IntMap;
import java.io.IOException;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.Scorer;
Expand All @@ -17,7 +16,7 @@ public class TraveltimeScorer extends Scorer {
private class TraveltimeFilteredDocs extends DocIdSetIterator {
private final TraveltimeWeight.FilteredIterator backing;

@Getter private long currentValue = 0;
private long currentValue = 0;
private boolean currentValueDirty = true;

private void invalidateCurrentValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,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());
}
}
}

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Can be set either in the query or as a default in the config.
Defaults to `ONE_TO_MANY`.
- `prefilter`: Arbitrary Elasticsearch query that will be used to limit which points are sent to the API.
- `output`: **[since 7.10]** name of the field that will hold the travel times in the response
- `distanceOutput` **[since 7.10]**: name of the field that will hold the travel distances in the response. Cannot be used with `mode` set to `pt`.

###Examples

Expand Down

0 comments on commit d6a162d

Please sign in to comment.