Search in sources :

Example 1 with QuickSearch

use of com.bakdata.conquery.util.search.QuickSearch in project conquery by bakdata.

the class FilterSearch method createSourceSearch.

/**
 * Create interactive Search for the selected filter based on its Template.
 * @param filter
 */
public static void createSourceSearch(AbstractSelectFilter<?> filter, CSVConfig parserConfig) {
    FilterTemplate template = filter.getTemplate();
    List<String> templateColumns = new ArrayList<>(template.getColumns());
    templateColumns.add(template.getColumnValue());
    File file = new File(template.getFilePath());
    String autocompleteKey = String.join("_", templateColumns) + "_" + file.getName();
    QuickSearch<FilterSearchItem> search = FilterSearch.search.get(autocompleteKey);
    if (search != null) {
        log.info("Reference list '{}' already exists ...", file.getAbsolutePath());
        filter.setSourceSearch(search);
        return;
    }
    log.info("Processing reference list '{}' ...", file.getAbsolutePath());
    final long time = System.currentTimeMillis();
    search = new QuickSearch.QuickSearchBuilder().withUnmatchedPolicy(QuickSearch.UnmatchedPolicy.IGNORE).withMergePolicy(QuickSearch.MergePolicy.UNION).withKeywordMatchScorer(FilterSearchType.CONTAINS::score).build();
    final CsvParser parser = parserConfig.createParser();
    try {
        IterableResult<String[], ParsingContext> it = parser.iterate(In.file(file).withUTF8().asReader());
        String[] header = it.getContext().parsedHeaders();
        for (String[] row : it) {
            FilterSearchItem item = new FilterSearchItem();
            for (int i = 0; i < header.length; i++) {
                String column = header[i];
                if (!templateColumns.contains(column)) {
                    continue;
                }
                item.setLabel(template.getValue());
                item.setOptionValue(template.getOptionValue());
                item.getTemplateValues().put(column, row[i]);
                if (column.equals(template.getColumnValue())) {
                    item.setValue(row[i]);
                }
                search.addItem(item, row[i]);
            }
        }
        filter.setSourceSearch(search);
        FilterSearch.search.put(autocompleteKey, search);
        final long duration = System.currentTimeMillis() - time;
        log.info("Processed reference list '{}' in {} ms ({} Items in {} Lines)", file.getAbsolutePath(), duration, search.getStats().getItems(), it.getContext().currentLine());
    } catch (Exception e) {
        log.error("Failed to process reference list '" + file.getAbsolutePath() + "'", e);
    } finally {
        parser.stopParsing();
    }
}
Also used : ParsingContext(com.univocity.parsers.common.ParsingContext) ArrayList(java.util.ArrayList) QuickSearch(com.bakdata.conquery.util.search.QuickSearch) CsvParser(com.univocity.parsers.csv.CsvParser) File(java.io.File)

Example 2 with QuickSearch

use of com.bakdata.conquery.util.search.QuickSearch in project conquery by bakdata.

the class ConceptsProcessor method autocompleteTextFilter.

/**
 * Autocompletion for search terms. For values of {@link AbstractSelectFilter<?>}.
 * Is used by the serach cache to load missing items
 */
private static List<FEValue> autocompleteTextFilter(AbstractSelectFilter<?> filter, String text) {
    if (Strings.isNullOrEmpty(text)) {
        // If no text provided, we just list them
        // Filter might not have a source search (since none might be defined).
        // TODO unify these code paths, they are quite the mess, maybe also create source search for key-value also
        final Stream<FEValue> fromSearch = filter.getSourceSearch() == null ? Stream.empty() : filter.getSourceSearch().listItems().stream().map(item -> new FEValue(item.getLabel(), item.getValue(), item.getTemplateValues(), item.getOptionValue()));
        final Stream<FEValue> fromLabels = filter.getLabels().entrySet().stream().map(entry -> new FEValue(entry.getValue(), entry.getKey()));
        return Stream.concat(fromLabels, fromSearch).sorted().collect(Collectors.toList());
    }
    List<FEValue> result = new LinkedList<>();
    QuickSearch<FilterSearchItem> search = filter.getSourceSearch();
    if (search != null) {
        result = createSourceSearchResult(filter.getSourceSearch(), Collections.singletonList(text), OptionalInt.empty(), FilterSearch.FilterSearchType.CONTAINS::score);
    }
    String value = filter.getValueFor(text);
    if (value != null) {
        result.add(new FEValue(text, value));
    }
    return result;
}
Also used : ConceptTreeChild(com.bakdata.conquery.models.datasets.concepts.tree.ConceptTreeChild) ConnectorId(com.bakdata.conquery.models.identifiable.ids.specific.ConnectorId) LoadingCache(com.google.common.cache.LoadingCache) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Pair(org.apache.commons.lang3.tuple.Pair) DatasetId(com.bakdata.conquery.models.identifiable.ids.specific.DatasetId) ToString(lombok.ToString) TreeConcept(com.bakdata.conquery.models.datasets.concepts.tree.TreeConcept) QuickSearch(com.bakdata.conquery.util.search.QuickSearch) Collection(java.util.Collection) Concept(com.bakdata.conquery.models.datasets.concepts.Concept) Set(java.util.Set) ConceptConfigurationException(com.bakdata.conquery.models.exceptions.ConceptConfigurationException) Collectors(java.util.stream.Collectors) FEList(com.bakdata.conquery.apiv1.frontend.FEList) Dataset(com.bakdata.conquery.models.datasets.Dataset) FilterId(com.bakdata.conquery.models.identifiable.ids.specific.FilterId) CacheLoader(com.google.common.cache.CacheLoader) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) Ability(com.bakdata.conquery.models.auth.permissions.Ability) Optional(java.util.Optional) CacheBuilder(com.google.common.cache.CacheBuilder) Setter(lombok.Setter) FilterSearchItem(com.bakdata.conquery.apiv1.FilterSearchItem) Getter(lombok.Getter) Subject(com.bakdata.conquery.models.auth.entities.Subject) OptionalInt(java.util.OptionalInt) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) NamespaceStorage(com.bakdata.conquery.io.storage.NamespaceStorage) FERoot(com.bakdata.conquery.apiv1.frontend.FERoot) LinkedList(java.util.LinkedList) SearchScorer(com.bakdata.conquery.util.search.SearchScorer) Iterator(java.util.Iterator) ConceptElementId(com.bakdata.conquery.models.identifiable.ids.specific.ConceptElementId) FEValue(com.bakdata.conquery.apiv1.frontend.FEValue) IdLabel(com.bakdata.conquery.apiv1.IdLabel) CalculatedValue(com.bakdata.conquery.util.CalculatedValue) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) AbstractSelectFilter(com.bakdata.conquery.models.datasets.concepts.filters.specific.AbstractSelectFilter) Data(lombok.Data) FilterSearch(com.bakdata.conquery.apiv1.FilterSearch) FrontEndConceptBuilder(com.bakdata.conquery.models.datasets.concepts.FrontEndConceptBuilder) DatasetRegistry(com.bakdata.conquery.models.worker.DatasetRegistry) Preconditions(com.google.common.base.Preconditions) Comparator(java.util.Comparator) AllArgsConstructor(lombok.AllArgsConstructor) Collections(java.util.Collections) FilterSearchItem(com.bakdata.conquery.apiv1.FilterSearchItem) ToString(lombok.ToString) FEValue(com.bakdata.conquery.apiv1.frontend.FEValue) LinkedList(java.util.LinkedList)

Aggregations

QuickSearch (com.bakdata.conquery.util.search.QuickSearch)2 ArrayList (java.util.ArrayList)2 FilterSearch (com.bakdata.conquery.apiv1.FilterSearch)1 FilterSearchItem (com.bakdata.conquery.apiv1.FilterSearchItem)1 IdLabel (com.bakdata.conquery.apiv1.IdLabel)1 FEList (com.bakdata.conquery.apiv1.frontend.FEList)1 FERoot (com.bakdata.conquery.apiv1.frontend.FERoot)1 FEValue (com.bakdata.conquery.apiv1.frontend.FEValue)1 NamespaceStorage (com.bakdata.conquery.io.storage.NamespaceStorage)1 Subject (com.bakdata.conquery.models.auth.entities.Subject)1 Ability (com.bakdata.conquery.models.auth.permissions.Ability)1 Dataset (com.bakdata.conquery.models.datasets.Dataset)1 Concept (com.bakdata.conquery.models.datasets.concepts.Concept)1 FrontEndConceptBuilder (com.bakdata.conquery.models.datasets.concepts.FrontEndConceptBuilder)1 AbstractSelectFilter (com.bakdata.conquery.models.datasets.concepts.filters.specific.AbstractSelectFilter)1 ConceptTreeChild (com.bakdata.conquery.models.datasets.concepts.tree.ConceptTreeChild)1 TreeConcept (com.bakdata.conquery.models.datasets.concepts.tree.TreeConcept)1 ConceptConfigurationException (com.bakdata.conquery.models.exceptions.ConceptConfigurationException)1 ConceptElementId (com.bakdata.conquery.models.identifiable.ids.specific.ConceptElementId)1 ConnectorId (com.bakdata.conquery.models.identifiable.ids.specific.ConnectorId)1