public Boolean destroy(final QueryKey queryKey,
                           final DestroyReason destroyReason) {
        if (LOGGER.isDebugEnabled()) {
            String json = JsonUtil.writeValueAsString(queryKey);
            LOGGER.debug("/destroy called with queryKey:\n{}", json);
        }

        final Supplier<Boolean> supplier = taskContextFactory.contextResult("Destroy search",
                taskContext -> {
                    taskContext.info(queryKey::getUuid);
                    LOGGER.debug(() -> "remove called for queryKey " + queryKey);
                    final Optional<ResultStore> resultStore = getIfPresent(queryKey);
                    resultStore.ifPresent(store -> {
                        checkPermissions(store);
                        if (destroyReason == null) {
                            destroyAndRemove(queryKey, store);
                        } else {
                            switch (destroyReason) {
                                case NO_LONGER_NEEDED, MANUAL -> destroyAndRemove(queryKey, store);
                                case TAB_CLOSE -> {
                                    final ResultStoreSettings resultStoreSettings = store.getResultStoreSettings();
                                    if (resultStoreSettings.getStoreLifespan()
                                            .isDestroyOnTabClose()) {
                                        destroyAndRemove(queryKey, store);
                                    } else if (resultStoreSettings.getSearchProcessLifespan()
                                            .isDestroyOnTabClose()) {
                                        store.terminate();
                                    }
                                }
                                case WINDOW_CLOSE -> {
                                    final ResultStoreSettings resultStoreSettings = store.getResultStoreSettings();
                                    if (resultStoreSettings.getStoreLifespan()
                                            .isDestroyOnWindowClose()) {
                                        destroyAndRemove(queryKey, store);
                                    } else if (resultStoreSettings.getSearchProcessLifespan()
                                            .isDestroyOnWindowClose()) {
                                        store.terminate();
                                    }
                                }
                            }
                        }
                    });
                    return true;
                });
        final Executor executor = executorProvider.get();
        final CompletableFuture<Boolean> completableFuture = CompletableFuture.supplyAsync(supplier, executor);
        try {
            return completableFuture.get();
        } catch (final InterruptedException | ExecutionException e) {
            LOGGER.debug(e::getMessage, e);
            return false;
        }
    }
Destroy a result store for the specified query key.

@param queryKey The key of the result store to destroy.
stroom-query/stroom-query-common/src/main/java/stroom/query/common/v2/ResultStoreManager.java