Skip to content

Commit

Permalink
Merge pull request #3376 from ingef/fix/search-totals
Browse files Browse the repository at this point in the history
Fix: total search result for empty search
  • Loading branch information
awildturtok authored Apr 8, 2024
2 parents 5b11240 + 2eb9ec6 commit 1310f67
Show file tree
Hide file tree
Showing 12 changed files with 246 additions and 173 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.bakdata.conquery.apiv1.frontend.FrontendValue;
import com.bakdata.conquery.io.cps.CPSType;
import com.bakdata.conquery.io.jackson.serializer.NsIdRef;
import com.bakdata.conquery.io.storage.NamespaceStorage;
import com.bakdata.conquery.models.config.IndexConfig;
import com.bakdata.conquery.models.datasets.Dataset;
import com.bakdata.conquery.models.datasets.concepts.Searchable;
Expand Down Expand Up @@ -40,7 +39,7 @@
@ToString
@Slf4j
@CPSType(id = "CSV_TEMPLATE", base = SearchIndex.class)
public class FilterTemplate extends IdentifiableImpl<SearchIndexId> implements Searchable<SearchIndexId>, SearchIndex {
public class FilterTemplate extends IdentifiableImpl<SearchIndexId> implements Searchable, SearchIndex {

private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -90,7 +89,7 @@ public boolean isSearchDisabled() {
return false;
}

public TrieSearch<FrontendValue> createTrieSearch(IndexConfig config, NamespaceStorage storage) {
public TrieSearch<FrontendValue> createTrieSearch(IndexConfig config) {

final URI resolvedURI = FileUtil.getResolvedUri(config.getBaseUrl(), getFilePath());
log.trace("Resolved filter template reference url for search '{}': {}", this.getId(), resolvedURI);
Expand Down
71 changes: 71 additions & 0 deletions backend/src/main/java/com/bakdata/conquery/apiv1/LabelMap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.bakdata.conquery.apiv1;

import java.util.List;
import java.util.stream.Collectors;

import com.bakdata.conquery.apiv1.frontend.FrontendValue;
import com.bakdata.conquery.models.config.IndexConfig;
import com.bakdata.conquery.models.datasets.concepts.Searchable;
import com.bakdata.conquery.models.identifiable.ids.specific.FilterId;
import com.bakdata.conquery.models.query.FilterSearch;
import com.bakdata.conquery.util.search.TrieSearch;
import com.google.common.collect.BiMap;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.experimental.Delegate;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.StopWatch;

@Getter
@RequiredArgsConstructor
@Slf4j
@EqualsAndHashCode
public class LabelMap implements Searchable {

private final FilterId id;
@Delegate
private final BiMap<String, String> delegate;
private final int minSuffixLength;
private final boolean generateSearchSuffixes;

@Override
public TrieSearch<FrontendValue> createTrieSearch(IndexConfig config) {

final TrieSearch<FrontendValue> search = config.createTrieSearch(true);

final List<FrontendValue> collected = delegate.entrySet().stream()
.map(entry -> new FrontendValue(entry.getKey(), entry.getValue()))
.collect(Collectors.toList());

if (log.isTraceEnabled()) {
log.trace("Labels for {}: `{}`", getId(), collected.stream().map(FrontendValue::toString).collect(Collectors.toList()));
}

StopWatch timer = StopWatch.createStarted();
log.trace("START-SELECT ADDING_ITEMS for {}", getId());

collected.forEach(feValue -> search.addItem(feValue, FilterSearch.extractKeywords(feValue)));

log.trace("DONE-SELECT ADDING_ITEMS for {} in {}", getId(), timer);

timer.reset();
log.trace("START-SELECT SHRINKING for {}", getId());

search.shrinkToFit();

log.trace("DONE-SELECT SHRINKING for {} in {}", getId(), timer);

return search;
}

@Override
public boolean isGenerateSuffixes() {
return generateSearchSuffixes;
}

@Override
public boolean isSearchDisabled() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static NamespaceSetupData createNamespaceSetup(NamespaceStorage storage, final C

JobManager jobManager = new JobManager(storage.getDataset().getName(), config.isFailOnError());

FilterSearch filterSearch = new FilterSearch(storage, jobManager, config.getCsv(), config.getIndex());
FilterSearch filterSearch = new FilterSearch(config.getIndex());
return new NamespaceSetupData(injectables, indexService, communicationMapper, preprocessMapper, jobManager, filterSearch);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import com.bakdata.conquery.apiv1.frontend.FrontendValue;
import com.bakdata.conquery.io.jackson.serializer.NsIdRef;
import com.bakdata.conquery.io.storage.NamespaceStorage;
import com.bakdata.conquery.models.config.IndexConfig;
import com.bakdata.conquery.models.datasets.concepts.Searchable;
import com.bakdata.conquery.models.events.MajorTypeId;
Expand All @@ -26,7 +25,7 @@
@Setter
@NoArgsConstructor
@Slf4j
public class Column extends Labeled<ColumnId> implements NamespacedIdentifiable<ColumnId>, Searchable<ColumnId> {
public class Column extends Labeled<ColumnId> implements NamespacedIdentifiable<ColumnId>, Searchable {

public static final int UNKNOWN_POSITION = -1;

Expand Down Expand Up @@ -75,7 +74,7 @@ public Dataset getDataset() {
* We create only an empty search here, because the content is provided through {@link com.bakdata.conquery.models.messages.namespaces.specific.RegisterColumnValues} and filled by the caller.
*/
@Override
public TrieSearch<FrontendValue> createTrieSearch(IndexConfig config, NamespaceStorage storage) {
public TrieSearch<FrontendValue> createTrieSearch(IndexConfig config) {

return config.createTrieSearch(isGenerateSuffixes());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,23 @@
package com.bakdata.conquery.models.datasets.concepts;

import java.util.List;

import javax.validation.constraints.Min;

import com.bakdata.conquery.apiv1.frontend.FrontendValue;
import com.bakdata.conquery.io.storage.NamespaceStorage;
import com.bakdata.conquery.models.config.IndexConfig;
import com.bakdata.conquery.models.datasets.Dataset;
import com.bakdata.conquery.models.identifiable.Identifiable;
import com.bakdata.conquery.models.identifiable.ids.Id;
import com.bakdata.conquery.models.query.FilterSearch;
import com.bakdata.conquery.util.search.TrieSearch;
import com.fasterxml.jackson.annotation.JsonIgnore;

/**
* @implNote This class is tightly coupled with {@link FilterSearch} and {@link com.bakdata.conquery.models.datasets.concepts.filters.specific.SelectFilter}.
* <p>
* Searchable classes describe how a search should be constructed, and provide the values with getSearchValues.
*/
public interface Searchable<ID extends Id<? extends Identifiable<? extends ID>>> extends Identifiable<ID> {

public Dataset getDataset();
public interface Searchable {

/**
* All available {@link FrontendValue}s for searching in a {@link TrieSearch}.
*/
TrieSearch<FrontendValue> createTrieSearch(IndexConfig config, NamespaceStorage storage);

/**
* The actual Searchables to use, if there is potential for deduplication/pooling.
*
* @implSpec The order of objects returned is used to also sort search results from different sources.
*/
@JsonIgnore
default List<Searchable<?>> getSearchReferences() {
//Hopefully the only candidate will be Column
return List.of(this);
}
TrieSearch<FrontendValue> createTrieSearch(IndexConfig config);

/**
* Parameter used in the construction of {@link com.bakdata.conquery.util.search.TrieSearch}, defining the shortest suffix to create.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,16 @@
import java.util.stream.Collectors;

import com.bakdata.conquery.apiv1.FilterTemplate;
import com.bakdata.conquery.apiv1.LabelMap;
import com.bakdata.conquery.apiv1.frontend.FrontendFilterConfiguration;
import com.bakdata.conquery.apiv1.frontend.FrontendValue;
import com.bakdata.conquery.io.jackson.View;
import com.bakdata.conquery.io.jackson.serializer.NsIdRef;
import com.bakdata.conquery.io.storage.NamespaceStorage;
import com.bakdata.conquery.models.config.ConqueryConfig;
import com.bakdata.conquery.models.config.IndexConfig;
import com.bakdata.conquery.models.datasets.concepts.Searchable;
import com.bakdata.conquery.models.datasets.concepts.filters.SingleColumnFilter;
import com.bakdata.conquery.models.events.MajorTypeId;
import com.bakdata.conquery.models.exceptions.ConceptConfigurationException;
import com.bakdata.conquery.models.identifiable.ids.specific.FilterId;
import com.bakdata.conquery.models.query.FilterSearch;
import com.bakdata.conquery.util.search.TrieSearch;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.google.common.collect.BiMap;
Expand All @@ -30,15 +26,14 @@
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.StopWatch;
import org.jetbrains.annotations.NotNull;

@Setter
@Getter
@NoArgsConstructor
@Slf4j
@JsonIgnoreProperties({"searchType"})
public abstract class SelectFilter<FE_TYPE> extends SingleColumnFilter<FE_TYPE> implements Searchable<FilterId> {
public abstract class SelectFilter<FE_TYPE> extends SingleColumnFilter<FE_TYPE> {

/**
* user given mapping from the values in the columns to shown labels
Expand Down Expand Up @@ -71,19 +66,25 @@ public void configureFrontend(FrontendFilterConfiguration.Top f, ConqueryConfig
@JsonIgnore
public abstract String getFilterType();

@Override
public List<Searchable<?>> getSearchReferences() {
final List<Searchable<?>> out = new ArrayList<>();

/**
* The actual Searchables to use, if there is potential for deduplication/pooling.
*
* @implSpec The order of objects returned is used to also sort search results from different sources.
*/
@JsonIgnore
public List<Searchable> getSearchReferences() {
final List<Searchable> out = new ArrayList<>();

if (getTemplate() != null) {
out.add(getTemplate());
}

if (!labels.isEmpty()) {
out.add(this);
out.add(new LabelMap(getId(), labels, searchMinSuffixLength, generateSearchSuffixes));
}

out.addAll(getColumn().getSearchReferences());
out.add(getColumn());

return out;
}
Expand All @@ -105,51 +106,4 @@ public boolean isNotUsingTemplateAndLabels() {

return (getTemplate() == null) != labels.isEmpty();
}

@Override
@JsonIgnore
public boolean isGenerateSuffixes() {
return generateSearchSuffixes;
}

@Override
@JsonIgnore
public int getMinSuffixLength() {
return searchMinSuffixLength;
}

/**
* Does not make sense to distinguish at Filter level since it's only referenced when labels are set.
*/
@Override
@JsonIgnore
public boolean isSearchDisabled() {
return false;
}

@Override
public TrieSearch<FrontendValue> createTrieSearch(IndexConfig config, NamespaceStorage storage) {

final TrieSearch<FrontendValue> search = config.createTrieSearch(true);

if(log.isTraceEnabled()) {
log.trace("Labels for {}: `{}`", getId(), collectLabels().stream().map(FrontendValue::toString).collect(Collectors.toList()));
}

StopWatch timer = StopWatch.createStarted();
log.trace("START-SELECT ADDING_ITEMS for {}", getId());

collectLabels().forEach(feValue -> search.addItem(feValue, FilterSearch.extractKeywords(feValue)));

log.trace("DONE-SELECT ADDING_ITEMS for {} in {}", getId(), timer);

timer.reset();
log.trace("START-SELECT SHRINKING for {}", getId());

search.shrinkToFit();

log.trace("DONE-SELECT SHRINKING for {} in {}", getId(), timer);

return search;
}
}
Loading

0 comments on commit 1310f67

Please sign in to comment.