Skip to content

Commit

Permalink
Add Javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Aug 6, 2024
1 parent 42e45e1 commit 611727b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -98,6 +97,27 @@ class LuceneIndexTest {
.withCoordinate(52.52277, 13.41046)
.build();

static final RegularStop MERIDIAN_AVE = TEST_MODEL
.stop("Meridian Ave N & N 148th St")
.withId(FeedScopedId.parse("kcm:16340"))
.withCode("16340")
.withCoordinate(47.736145, -122.33445)
.build();

static final RegularStop MERIDIAN_N_1 = TEST_MODEL
.stop("Meridian N & Spencer")
.withId(FeedScopedId.parse("pierce:13268"))
.withCode("4168")
.withCoordinate(47.209366,-122.293999)
.build();

static final RegularStop MERIDIAN_N_2 = TEST_MODEL
.stop("Meridian N & Spencer")
.withId(FeedScopedId.parse("pierce:30976"))
.withCode("4169")
.withCoordinate(47.209316,-122.293841)
.build();

static LuceneIndex index;

static StopClusterMapper mapper;
Expand All @@ -113,7 +133,10 @@ static void setup() {
LICHTERFELDE_OST_2,
WESTHAFEN,
ARTS_CENTER,
ARTHUR
ARTHUR,
MERIDIAN_N_1,
MERIDIAN_N_2,
MERIDIAN_AVE
)
.forEach(stopModel::withRegularStop);
List
Expand Down Expand Up @@ -295,9 +318,15 @@ void agenciesAndFeedPublisher() {
assertEquals(List.of(StopClusterMapper.toAgency(BVG)), cluster.primary().agencies());
assertEquals("A Publisher", cluster.primary().feedPublisher().name());
}

@Test
void number() {
var names = index.queryStopClusters("Meridian Ave N & N 148").map(c -> c.primary().name()).toList();
assertEquals(List.of(MERIDIAN_AVE.getName().toString(), MERIDIAN_N_1.getName().toString()), names);
}
}

private static @Nonnull Function<StopCluster, FeedScopedId> primaryId() {
private static Function<StopCluster, FeedScopedId> primaryId() {
return c -> c.primary().id();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.FuzzyQuery;
import org.apache.lucene.search.PrefixQuery;
import org.apache.lucene.search.TermQuery;
Expand Down Expand Up @@ -296,9 +297,9 @@ private Stream<Document> matchingDocuments(
);

var fuzzyNameQuery = new FuzzyQuery(new Term(NAME, analyzer.normalize(NAME, searchTerms)));
var prefixNameQuery = new PrefixQuery(
var prefixNameQuery = new BoostQuery(new PrefixQuery(
new Term(NAME, analyzer.normalize(NAME, searchTerms))
);
), 5);
var codeQuery = new TermQuery(new Term(CODE, analyzer.normalize(CODE, searchTerms)));

var prefixCodeQuery = new PrefixQuery(
Expand Down Expand Up @@ -327,7 +328,8 @@ private Stream<Document> matchingDocuments(
.stream(topDocs.scoreDocs)
.map(scoreDoc -> {
try {
return searcher.doc(scoreDoc.doc);
var x = searcher.doc(scoreDoc.doc);
return x;
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public DefaultRealtimeVehicleService(TransitService transitService) {
this.transitService = transitService;
}

/**
* Stores the relationship between a list of realtime vehicles with a pattern. If the pattern is
* a realtime-added one, then the original (scheduled) one is used as the key for the map storing
* the information.
*/
@Override
public void setRealtimeVehicles(TripPattern pattern, List<RealtimeVehicle> updates) {
if (pattern.getOriginalTripPattern() != null) {
Expand All @@ -45,6 +50,13 @@ public void clearRealtimeVehicles(TripPattern pattern) {
vehicles.remove(pattern);
}

/**
* Gets the realtime vehicles for a given pattern. If the pattern is a realtime-added one
* then the original (scheduled) one is used for the lookup instead, so you receive the correct
* result no matter if you use the realtime or static information.
*
* @see DefaultRealtimeVehicleService#setRealtimeVehicles(TripPattern, List)
*/
@Override
public List<RealtimeVehicle> getRealtimeVehicles(@Nonnull TripPattern pattern) {
if (pattern.getOriginalTripPattern() != null) {
Expand Down

0 comments on commit 611727b

Please sign in to comment.