Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/log around autocomplete #2217

Merged
merged 2 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions backend/src/main/java/com/bakdata/conquery/apiv1/FilterSearch.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package com.bakdata.conquery.apiv1;

import com.bakdata.conquery.models.datasets.concepts.filters.specific.AbstractSelectFilter;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.bakdata.conquery.models.datasets.Dataset;
import com.bakdata.conquery.models.datasets.concepts.filters.specific.AbstractSelectFilter;
import com.bakdata.conquery.models.jobs.JobManager;
import com.bakdata.conquery.models.jobs.SimpleJob;
import com.bakdata.conquery.models.worker.DatasetRegistry;
Expand All @@ -14,9 +21,6 @@
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.util.*;


@Slf4j
public class FilterSearch {
Expand All @@ -34,7 +38,7 @@ public enum FilterSearchType {
@Override
public double score(String candidate, String keyword) {
/* Sort ascending by length of match */
if (keyword.startsWith(candidate)) {
if (keyword.startsWith(candidate)) {
return 1d / candidate.length();
}
return -1d;
Expand Down Expand Up @@ -152,12 +156,12 @@ public static void createSourceSearch(AbstractSelectFilter<?> filter, CsvParser
filter.setSourceSearch(search);

FilterSearch.search.put(autocompleteKey, search);
log.info("Processed reference list '{}' in {} ms", file.getAbsolutePath(), System.currentTimeMillis() - time);
log.info("Processed reference list '{}' in {} ms ({} Items)", file.getAbsolutePath(), System.currentTimeMillis() - time, search.getStats().getItems());
} catch (Exception e) {
log.error("Failed to process reference list '"+file.getAbsolutePath()+"'", e);
}
}

public static void clear() {
search.clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ public List<FEValue> load(Pair<AbstractSelectFilter<?>, String> filterAndSearch)

log.trace("Calculating a new search cache for the term \"{}\" on filter[{}]", searchTerm, filter.getId());

return autocompleteTextFilter(filter, searchTerm);
final List<FEValue> result = autocompleteTextFilter(filter, searchTerm);

log.debug("Got {} results for {}", result.size(), filterAndSearch);

return result;
}

});
Expand Down Expand Up @@ -199,10 +203,11 @@ public AutoCompleteResult autocompleteTextFilter(AbstractSelectFilter<?> filter,
private static List<FEValue> autocompleteTextFilter(AbstractSelectFilter<?> filter, String text) {
if (Strings.isNullOrEmpty(text)) {
// If no text provided, we just list them
return filter.getSourceSearch().listItems()
.stream()
.map(item -> new FEValue(item.getLabel(), item.getValue(), item.getTemplateValues(), item.getOptionValue()))
.collect(Collectors.toList());
final List<FilterSearchItem> items = filter.getSourceSearch().listItems();
return items
.stream()
.map(item -> new FEValue(item.getLabel(), item.getValue(), item.getTemplateValues(), item.getOptionValue()))
.collect(Collectors.toList());
}

List<FEValue> result = new LinkedList<>();
Expand Down