Skip to content

Commit

Permalink
Better sort and sizing
Browse files Browse the repository at this point in the history
  • Loading branch information
JornC committed Feb 9, 2022
1 parent 4db453f commit 79026bc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
v-show="hasQuery"
ref="resultsContainer"
:style='map("maxHeight", maxHeight)'
:class='map("scrolling", scrolling)'
aria-label="search results"
role="tree">
<vertical-collapse-group>
Expand Down Expand Up @@ -118,10 +117,7 @@
border: 1px solid #b3b3b3;
border-top: none;
box-sizing: border-box;

&.scrolling {
overflow: auto;
}
overflow: auto;

.group {
.titleContainer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public class MapSearchComponent implements IsVueComponent, HasCreated, HasMounte
@Data SearchMessages i18n = SearchM.messages();

@Data String maxHeight;
@Data boolean scrolling;

@Ref HTMLElement resultsContainer;
@Ref HTMLElement input;
Expand All @@ -92,7 +91,7 @@ public Map<String, List<SearchSuggestion>> getResults() {
final Map<String, List<SearchSuggestion>> res = context.getResults().values().stream()
.collect(Collectors.groupingBy(v -> v.type, LinkedHashMap::new, Collectors.toList()));

res.values().forEach(v -> v.sort((o1, o2) -> Double.compare(o1.score, o2.score)));
res.values().forEach(v -> v.sort((o1, o2) -> -Double.compare(o1.score, o2.score)));

return res;
}
Expand Down Expand Up @@ -165,12 +164,17 @@ public void selectSuggestion(final SearchSuggestion value) {
}
}

@Computed
@Computed("isShowing")
public boolean isShowing() {
return context.isSearching()
|| hasResults();
}

@Watch("isShowing()")
public void onShowingChange() {
resize();
}

@Override
public void created() {
DomGlobal.window.addEventListener("resize", null);
Expand All @@ -186,7 +190,6 @@ public void mounted() {
private void resize() {
final ClientRect rect = resultsContainer.getBoundingClientRect();
maxHeight = "calc(100vh - " + rect.top + "px - 10px)";
scrolling = Window.getClientHeight() - rect.top - rect.height - 20 < 0;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
position: absolute;
top: 0px;
width: var(--search-width);
max-width: calc(100vw - 240px);
right: calc(60px);

div {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package nl.aerius.search.tasks;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -44,6 +45,8 @@
public class AssessmentAreaSearchService implements SearchTaskService {
private static final Logger LOG = LoggerFactory.getLogger(AssessmentAreaSearchService.class);

private static final long MAX_RESULTS = 20;

private final Map<String, Nature2000Area> areas;
private final Natura2000WfsInterpreter interpreter;

Expand Down Expand Up @@ -81,6 +84,8 @@ public Single<SearchTaskResult> retrieveSearchResults(final String query) {
.anyMatch(part -> area.getKey().contains(part)))
.map(Entry::getValue)
.map(v -> areaToSuggestion(normalizedQuery, v))
.sorted(Comparator.comparingDouble(SearchSuggestion::getScore).reversed())
.limit(MAX_RESULTS)
.collect(Collectors.toList());

result.setSuggestions(sugs);
Expand Down

0 comments on commit 79026bc

Please sign in to comment.