Skip to content

Commit

Permalink
releaseb improving the search completion
Browse files Browse the repository at this point in the history
  • Loading branch information
Sammers21 committed Jul 28, 2024
1 parent c705ab0 commit 8b91382
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/io/github/sammers/pla/http/Http.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,25 @@ public void start() {
List<SearchResult> search = ladder.search(searchQ);
int remaining = 20 - search.size();
if (remaining > 0) {
List<Pair<String, String>> topRealms = realmStats.top20Realms().subList(0, remaining);
List<SearchResult> additionalResults = topRealms.stream().map(realm ->
new SearchResult(String.format("%s-%s", searchQ, realm.getValue0()), realm.getValue1(), "null")
).toList();
search.addAll(additionalResults);
String[] split = searchQ.trim().split("-");
if (split.length == 1) {
List<Pair<String, String>> top20 = realmStats.top20Realms();
List<Pair<String, String>> topRealms = top20.subList(0, Math.min(remaining, top20.size()));
List<SearchResult> additionalResults = topRealms.stream().map(realm ->
new SearchResult(String.format("%s-%s", searchQ, realm.getValue0()), realm.getValue1(), "null")
).toList();
search.addAll(additionalResults);
} else if (split.length > 1 && !split[0].isEmpty()) {
List<Pair<String, String>> top20 = realmStats.realmsStartingWithTop20(split[1]);
List<Pair<String, String>> topRealms = top20.subList(0, Math.min(remaining, top20.size()));
List<SearchResult> additionalResults = topRealms.stream()
.map(realm -> new SearchResult(String.format("%s-%s", split[0], realm.getValue0()), realm.getValue1(), "null")
).toList();
search.addAll(additionalResults);
}
}
List<JsonObject> list = search.stream().map(SearchResult::toJson).map(j -> j.put("source", "pvpqnet")).toList();
if (list.isEmpty()) {
checkPvPFrAPI.searchChars(searchQ).subscribe(searchResults -> {
ctx.response().end(new JsonArray(searchResults.stream().map(ExtCharacterSearcher.CheckPvPSearchResult::toJson).map(j -> j.put("source", "checkpvp.fr")).toList()).encode());
}, err -> {
log.error("Failed to search chars", err);
ctx.response().end(new JsonArray().encode());
});
} else {
ctx.response().end(new JsonArray(list).encode());
}
ctx.response().end(new JsonArray(list).encode());
}
});
});
Expand Down
10 changes: 10 additions & 0 deletions src/io/github/sammers/pla/logic/RealmStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,14 @@ public List<Pair<String, String>> top20Realms() {
return top20.subList(0, Math.min(20, top20.size()));
}

public List<Pair<String, String>> realmsStartingWithTop20(String prefix) {
List<Pair<String, String>> realms = new ArrayList<>();
for (Pair<String, String> realm : realmStats.keySet()) {
if (realm.getValue0().toLowerCase().startsWith(prefix.toLowerCase())) {
realms.add(realm);
}
}
return realms;
}

}

0 comments on commit 8b91382

Please sign in to comment.