diff --git a/search-client/src/main/java/nl/aerius/search/wui/context/SearchContext.java b/search-client/src/main/java/nl/aerius/search/wui/context/SearchContext.java index d40b21b..9ab9edb 100644 --- a/search-client/src/main/java/nl/aerius/search/wui/context/SearchContext.java +++ b/search-client/src/main/java/nl/aerius/search/wui/context/SearchContext.java @@ -38,7 +38,9 @@ public class SearchContext { public Map getResults() { final Map ret = new HashMap<>(); - ret.putAll(cache); + if (searching) { + ret.putAll(cache); + } ret.putAll(results); return ret; @@ -50,6 +52,10 @@ public void addResults(final Collection results) { } public void setCacheResults(final Collection results) { + if (!isSearching()) { + return; + } + this.cache.putAll(results.stream() .collect(Collectors.toMap(v -> v.id, v -> v))); } diff --git a/search-client/src/main/java/nl/aerius/search/wui/daemon/SearchDaemonAsynchronous.java b/search-client/src/main/java/nl/aerius/search/wui/daemon/SearchDaemonAsynchronous.java index 5bb27c1..1d6353b 100644 --- a/search-client/src/main/java/nl/aerius/search/wui/daemon/SearchDaemonAsynchronous.java +++ b/search-client/src/main/java/nl/aerius/search/wui/daemon/SearchDaemonAsynchronous.java @@ -74,6 +74,7 @@ interface SearchDaemonAsynchronousEventBinder extends EventBinder count) { + return; + } + cacheCounter.set(count); + context.setCacheResults(Stream.of(result.results) .collect(Collectors.toList())); } @@ -143,10 +153,10 @@ private void processResults(final SearchResult result, final Integer count) { } } - private void fetchSearchResults(final String uuid, final Integer count) { + private void fetchSearchResults(final String uuid, final int count) { SchedulerUtil.delay(() -> { if (!countMatches(count)) { - fetchOldResults(uuid); + fetchOldResults(count, uuid); return; } @@ -154,8 +164,8 @@ private void fetchSearchResults(final String uuid, final Integer count) { }, DELAY); } - private void fetchOldResults(final String uuid) { - service.retrieveSearchResults(uuid, AppAsyncCallback.create(this::processOldResults)); + private void fetchOldResults(final int count, final String uuid) { + service.retrieveSearchResults(uuid, AppAsyncCallback.create(v -> processOldResults(count, v))); } private void clear() {