-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from traveltime-dev/9.4-support
9.4+ support
- Loading branch information
Showing
71 changed files
with
105,970 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
buildPlugin(this, "9.6.1") | ||
configure(this) { | ||
dependencies { | ||
compileOnly 'org.locationtech.spatial4j:spatial4j:0.8' | ||
compileOnly 'com.github.ben-manes.caffeine:caffeine:3.1.1' | ||
} | ||
|
||
compileJava { | ||
sourceCompatibility = JavaVersion.VERSION_11 | ||
targetCompatibility = JavaVersion.VERSION_11 | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
9.4/src/main/java/com/traveltime/plugin/solr/TimeFilterQParserPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.traveltime.plugin.solr; | ||
|
||
import com.traveltime.plugin.solr.cache.RequestCache; | ||
import com.traveltime.plugin.solr.fetcher.JsonFetcherSingleton; | ||
import com.traveltime.plugin.solr.query.timefilter.TimeFilterQueryParser; | ||
import org.apache.solr.common.params.SolrParams; | ||
import org.apache.solr.common.util.NamedList; | ||
import org.apache.solr.request.SolrQueryRequest; | ||
import org.apache.solr.search.QParser; | ||
import org.apache.solr.search.QParserPlugin; | ||
|
||
import java.net.URI; | ||
import java.util.Optional; | ||
|
||
import static com.traveltime.plugin.solr.query.ParamSource.PARAM_PREFIX; | ||
|
||
public class TimeFilterQParserPlugin extends QParserPlugin { | ||
private String cacheName = RequestCache.NAME; | ||
private boolean isFilteringDisabled = false; | ||
private String paramPrefix = PARAM_PREFIX; | ||
|
||
private static final Integer DEFAULT_LOCATION_SIZE_LIMIT = 2000; | ||
|
||
@Override | ||
public void init(NamedList args) { | ||
Object cache = args.get("cache"); | ||
if (cache != null) cacheName = cache.toString(); | ||
|
||
Object filteringDisabled = args.get("filtering_disabled"); | ||
if (filteringDisabled != null) this.isFilteringDisabled = Boolean.parseBoolean(filteringDisabled.toString()); | ||
|
||
Object prefix = args.get("prefix"); | ||
if (prefix != null) paramPrefix = prefix.toString(); | ||
|
||
Object uriVal = args.get("api_uri"); | ||
URI uri = null; | ||
if (uriVal != null) uri = URI.create(uriVal.toString()); | ||
|
||
String appId = args.get("app_id").toString(); | ||
String apiKey = args.get("api_key").toString(); | ||
int locationLimit = | ||
Optional.ofNullable(args.get("location_limit")) | ||
.map(x -> Integer.parseInt(x.toString())) | ||
.orElse(DEFAULT_LOCATION_SIZE_LIMIT); | ||
|
||
JsonFetcherSingleton.INSTANCE.init(uri, appId, apiKey, locationLimit); | ||
} | ||
|
||
@Override | ||
public QParser createParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) { | ||
return new TimeFilterQueryParser( | ||
qstr, | ||
localParams, | ||
params, | ||
req, | ||
JsonFetcherSingleton.INSTANCE.getFetcher(), | ||
cacheName, | ||
isFilteringDisabled, | ||
paramPrefix | ||
); | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
9.4/src/main/java/com/traveltime/plugin/solr/TravelTimeQParserPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.traveltime.plugin.solr; | ||
|
||
import com.traveltime.plugin.solr.cache.RequestCache; | ||
import com.traveltime.plugin.solr.fetcher.ProtoFetcherSingleton; | ||
import com.traveltime.plugin.solr.query.TravelTimeQueryParser; | ||
import org.apache.solr.common.params.SolrParams; | ||
import org.apache.solr.common.util.NamedList; | ||
import org.apache.solr.request.SolrQueryRequest; | ||
import org.apache.solr.search.QParser; | ||
import org.apache.solr.search.QParserPlugin; | ||
|
||
import java.net.URI; | ||
|
||
import static com.traveltime.plugin.solr.query.ParamSource.PARAM_PREFIX; | ||
|
||
public class TravelTimeQParserPlugin extends QParserPlugin { | ||
private String cacheName = RequestCache.NAME; | ||
private boolean isFilteringDisabled = false; | ||
private String paramPrefix = PARAM_PREFIX; | ||
|
||
@Override | ||
public void init(NamedList args) { | ||
Object cache = args.get("cache"); | ||
if (cache != null) cacheName = cache.toString(); | ||
|
||
Object filteringDisabled = args.get("filtering_disabled"); | ||
if (filteringDisabled != null) this.isFilteringDisabled = Boolean.parseBoolean(filteringDisabled.toString()); | ||
|
||
Object prefix = args.get("prefix"); | ||
if (prefix != null) paramPrefix = prefix.toString(); | ||
|
||
Object uriVal = args.get("api_uri"); | ||
URI uri = null; | ||
if (uriVal != null) uri = URI.create(uriVal.toString()); | ||
|
||
String appId = args.get("app_id").toString(); | ||
String apiKey = args.get("api_key").toString(); | ||
ProtoFetcherSingleton.INSTANCE.init(uri, appId, apiKey); | ||
} | ||
|
||
@Override | ||
public QParser createParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) { | ||
return new TravelTimeQueryParser( | ||
qstr, | ||
localParams, | ||
params, | ||
req, | ||
ProtoFetcherSingleton.INSTANCE.getFetcher(), | ||
cacheName, | ||
isFilteringDisabled, | ||
paramPrefix | ||
); | ||
} | ||
|
||
} |
79 changes: 79 additions & 0 deletions
79
9.4/src/main/java/com/traveltime/plugin/solr/cache/BasicTravelTimes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.traveltime.plugin.solr.cache; | ||
|
||
import com.traveltime.sdk.dto.common.Coordinates; | ||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; | ||
import it.unimi.dsi.fastutil.objects.ObjectCollection; | ||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; | ||
import lombok.val; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.concurrent.locks.StampedLock; | ||
|
||
public class BasicTravelTimes extends TravelTimes { | ||
private final StampedLock rwLock = new StampedLock(); | ||
private final Object2IntOpenHashMap<Coordinates> coordsToTimes = new Object2IntOpenHashMap<>(); | ||
|
||
@Override | ||
public Set<Coordinates> nonCached(int ignored, ObjectCollection<Coordinates> coords) { | ||
long read = rwLock.readLock(); | ||
try { | ||
val nonCachedSet = new ObjectOpenHashSet<Coordinates>(); | ||
coords.forEach(coord -> { | ||
if (!coordsToTimes.containsKey(coord)) { | ||
nonCachedSet.add(coord); | ||
} | ||
} | ||
); | ||
return nonCachedSet; | ||
} finally { | ||
rwLock.unlock(read); | ||
} | ||
} | ||
|
||
@Override | ||
public void putAll(int ignored, ArrayList<Coordinates> coords, List<Integer> times) { | ||
long write = rwLock.writeLock(); | ||
try { | ||
for (int index = 0; index < times.size(); index++) { | ||
coordsToTimes.put(coords.get(index), times.get(index).intValue()); | ||
} | ||
} finally { | ||
rwLock.unlock(write); | ||
} | ||
} | ||
|
||
@Override | ||
public Object2IntOpenHashMap<Coordinates> mapToTimes(int ignored, ObjectCollection<Coordinates> coords) { | ||
long read = rwLock.readLock(); | ||
try { | ||
val pointToTime = new Object2IntOpenHashMap<Coordinates>(coords.size()); | ||
coords.forEach(coord -> { | ||
int time = coordsToTimes.getOrDefault(coord, -1); | ||
if (time > 0) { | ||
pointToTime.put(coord, time); | ||
} | ||
}); | ||
|
||
return pointToTime; | ||
} finally { | ||
rwLock.unlock(read); | ||
} | ||
} | ||
|
||
@Override | ||
public int get(Coordinates coord) { | ||
long read = rwLock.tryOptimisticRead(); | ||
int time = coordsToTimes.getOrDefault(coord, -1); | ||
if (!rwLock.validate(read)) { | ||
read = rwLock.readLock(); | ||
try { | ||
time = coordsToTimes.getOrDefault(coord, -1); | ||
} finally { | ||
rwLock.unlock(read); | ||
} | ||
} | ||
return time; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
9.4/src/main/java/com/traveltime/plugin/solr/cache/ExactRequestCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.traveltime.plugin.solr.cache; | ||
|
||
import com.traveltime.plugin.solr.query.TravelTimeQueryParameters; | ||
|
||
public class ExactRequestCache extends RequestCache<TravelTimeQueryParameters> { | ||
private final Object[] lock = new Object[0]; | ||
|
||
@Override | ||
public TravelTimes getOrFresh(TravelTimeQueryParameters key) { | ||
TravelTimes result = get(key); | ||
if (result == null) { | ||
synchronized (lock) { | ||
result = get(key); | ||
if (result == null) { | ||
result = new BasicTravelTimes(); | ||
put(key, result); | ||
} | ||
} | ||
} | ||
return result; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
9.4/src/main/java/com/traveltime/plugin/solr/cache/ExactTimeFilterRequestCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.traveltime.plugin.solr.cache; | ||
|
||
import com.traveltime.plugin.solr.query.timefilter.TimeFilterQueryParameters; | ||
|
||
public class ExactTimeFilterRequestCache extends RequestCache<TimeFilterQueryParameters> { | ||
private final Object[] lock = new Object[0]; | ||
|
||
@Override | ||
public TravelTimes getOrFresh(TimeFilterQueryParameters key) { | ||
TravelTimes result = get(key); | ||
if (result == null) { | ||
synchronized (lock) { | ||
result = get(key); | ||
if (result == null) { | ||
result = new BasicTravelTimes(); | ||
put(key, result); | ||
} | ||
} | ||
} | ||
return result; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
9.4/src/main/java/com/traveltime/plugin/solr/cache/FuzzyRequestCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.traveltime.plugin.solr.cache; | ||
|
||
import com.traveltime.plugin.solr.query.TravelTimeQueryParameters; | ||
import org.apache.solr.search.CacheRegenerator; | ||
|
||
import java.util.Map; | ||
|
||
public class FuzzyRequestCache extends RequestCache<TravelTimeQueryParameters> { | ||
private final Object[] lock = new Object[0]; | ||
private Map<String, String> args; | ||
|
||
@Override | ||
public Object init(Map<String, String> args, Object persistence, CacheRegenerator regenerator) { | ||
this.args = args; | ||
return super.init(args, persistence, regenerator); | ||
} | ||
|
||
@Override | ||
public TravelTimes getOrFresh(TravelTimeQueryParameters key) { | ||
key = new TravelTimeQueryParameters(null, key.getOrigin(), 0, key.getMode(), null); | ||
TravelTimes result = get(key); | ||
if (result == null) { | ||
synchronized (lock) { | ||
result = get(key); | ||
if (result == null) { | ||
result = new LRUTimes(args); | ||
put(key, result); | ||
} | ||
} | ||
} | ||
return result; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
9.4/src/main/java/com/traveltime/plugin/solr/cache/FuzzyTimeFilterRequestCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.traveltime.plugin.solr.cache; | ||
|
||
import com.traveltime.plugin.solr.query.timefilter.TimeFilterQueryParameters; | ||
import org.apache.solr.search.CacheRegenerator; | ||
|
||
import java.util.Map; | ||
|
||
public class FuzzyTimeFilterRequestCache extends RequestCache<TimeFilterQueryParameters> { | ||
private final Object[] lock = new Object[0]; | ||
private Map<String, String> args; | ||
|
||
@Override | ||
public Object init(Map<String, String> args, Object persistence, CacheRegenerator regenerator) { | ||
this.args = args; | ||
return super.init(args, persistence, regenerator); | ||
} | ||
|
||
@Override | ||
public TravelTimes getOrFresh(TimeFilterQueryParameters key) { | ||
key = key.withField(null).withTravelTime(0); | ||
TravelTimes result = get(key); | ||
if (result == null) { | ||
synchronized (lock) { | ||
result = get(key); | ||
if (result == null) { | ||
result = new LRUTimes(args); | ||
put(key, result); | ||
} | ||
} | ||
} | ||
return result; | ||
} | ||
} |
Oops, something went wrong.