filter name optimalization

This commit is contained in:
SPRINX0\prochazka
2024-12-16 16:23:55 +01:00
parent 358a641449
commit bf4841bca4
5 changed files with 73 additions and 42 deletions

View File

@@ -36,6 +36,37 @@ export function filterName(filter: string, ...names: string[]) {
return true; return true;
} }
export function filterNameCompoud(
filter: string,
namesMain: string[],
namesChild: string[]
): 'main' | 'child' | 'both' | 'none' {
if (!filter) return 'both';
// const camelVariants = [name.replace(/[^A-Z]/g, '')]
const tokens = filter.split(' ').map(x => x.trim());
const namesCompactedMain = _compact(namesMain);
const namesCompactedChild = _compact(namesChild);
let isMainOnly = true;
let isChildOnly = true;
for (const token of tokens) {
const foundMain = namesCompactedMain.find(name => camelMatch(token, name));
const foundChild = namesCompactedChild.find(name => camelMatch(token, name));
if (!foundMain && !foundChild) return 'none';
if (!foundMain) isMainOnly = false;
if (!foundChild) isChildOnly = false;
}
if (isMainOnly && isChildOnly) return 'both';
if (isMainOnly) return 'main';
if (isChildOnly) return 'child';
return 'none';
}
export function tokenizeBySearchFilter(text: string, filter: string): { token: string; isMatch: boolean }[] { export function tokenizeBySearchFilter(text: string, filter: string): { token: string; isMatch: boolean }[] {
const tokens = filter.split(' ').map(x => x.trim()); const tokens = filter.split(' ').map(x => x.trim());

View File

@@ -34,13 +34,31 @@
let expandLimited = false; let expandLimited = false;
$: matcher = module.createMatcher && module.createMatcher(filter, passProps?.searchSettings); $: matcher = module.createMatcher && module.createMatcher(filter, passProps?.searchSettings);
$: childMatcher = module.createChildMatcher && module.createChildMatcher(filter, passProps?.searchSettings);
$: dataLabeled = _.compact( $: dataLabeled = _.compact(
(list || []).map(data => { (list || []).map(data => {
const isMatched = !matcher || matcher(data); const matchResult = matcher ? matcher(data) : true;
const isChildMatched =
module.disableShowChildrenWithParentMatch && isMatched ? false : !childMatcher || childMatcher(data); let isMatched = true;
let isChildMatched = true;
if (matchResult == false) {
isMatched = false;
isChildMatched = false;
} else if (matchResult == 'child') {
isMatched = true;
isChildMatched = true;
} else if (matchResult == 'main') {
isMatched = true;
isChildMatched = false;
} else if (matchResult == 'none') {
isMatched = false;
isChildMatched = false;
} else if (matchResult == 'both') {
isMatched = true;
isChildMatched = !module.disableShowChildrenWithParentMatch;
}
const group = groupFunc ? groupFunc(data) : undefined; const group = groupFunc ? groupFunc(data) : undefined;
return { group, data, isMatched, isChildMatched }; return { group, data, isMatched, isChildMatched };
}) })

View File

@@ -3,13 +3,11 @@
export const createMatcher = filter => props => { export const createMatcher = filter => props => {
const { _id, displayName, server } = props; const { _id, displayName, server } = props;
const databases = getLocalStorage(`database_list_${_id}`) || []; const databases = getLocalStorage(`database_list_${_id}`) || [];
return filterName(filter, displayName, server, ...databases.map(x => x.name)); return filterNameCompoud(
}; filter,
export const createChildMatcher = filter => props => { [displayName, server],
if (!filter) return false; databases.map(x => x.name)
const { _id } = props; );
const databases = getLocalStorage(`database_list_${_id}`) || [];
return filterName(filter, ...databases.map(x => x.name));
}; };
export function openConnection(connection, disableExpand = false) { export function openConnection(connection, disableExpand = false) {
if (connection.singleDatabase) { if (connection.singleDatabase) {
@@ -106,7 +104,7 @@
openedConnections, openedConnections,
openedSingleDatabaseConnections, openedSingleDatabaseConnections,
} from '../stores'; } from '../stores';
import { filterName } from 'dbgate-tools'; import { filterName, filterNameCompoud } from 'dbgate-tools';
import { showModal } from '../modals/modalTools'; import { showModal } from '../modals/modalTools';
import ConfirmModal from '../modals/ConfirmModal.svelte'; import ConfirmModal from '../modals/ConfirmModal.svelte';
import InputTextModal from '../modals/InputTextModal.svelte'; import InputTextModal from '../modals/InputTextModal.svelte';

View File

@@ -5,42 +5,25 @@
export const createMatcher = export const createMatcher =
(filter, cfg = DEFAULT_SEARCH_SETTINGS) => (filter, cfg = DEFAULT_SEARCH_SETTINGS) =>
({ schemaName, pureName, objectComment, tableEngine, columns, objectTypeField, createSql }) => { ({ schemaName, pureName, objectComment, tableEngine, columns, objectTypeField, createSql }) => {
const filterArgs = []; const mainArgs = [];
if (cfg.schemaName) filterArgs.push(schemaName); const childArgs = [];
if (cfg.schemaName) mainArgs.push(schemaName);
if (objectTypeField == 'tables') { if (objectTypeField == 'tables') {
if (cfg.tableName) filterArgs.push(pureName); if (cfg.tableName) mainArgs.push(pureName);
if (cfg.tableComment) filterArgs.push(objectComment); if (cfg.tableComment) mainArgs.push(objectComment);
if (cfg.tableEngine) filterArgs.push(tableEngine); if (cfg.tableEngine) mainArgs.push(tableEngine);
for (const column of columns || []) { for (const column of columns || []) {
if (cfg.columnName) filterArgs.push(column.columnName); if (cfg.columnName) childArgs.push(column.columnName);
if (cfg.columnComment) filterArgs.push(column.columnComment); if (cfg.columnComment) childArgs.push(column.columnComment);
if (cfg.columnDataType) filterArgs.push(column.dataType); if (cfg.columnDataType) childArgs.push(column.dataType);
} }
} else { } else {
if (cfg.sqlObjectName) filterArgs.push(pureName); if (cfg.sqlObjectName) mainArgs.push(pureName);
if (cfg.sqlObjectText) filterArgs.push(createSql); if (cfg.sqlObjectText) childArgs.push(createSql);
} }
const res = filterName(filter, ...filterArgs); const res = filterNameCompoud(filter, mainArgs, childArgs);
return res;
};
export const createChildMatcher =
(filter, cfg = DEFAULT_SEARCH_SETTINGS) =>
({ columns, objectTypeField, createSql }) => {
const filterArgs = [];
if (objectTypeField == 'tables') {
for (const column of columns || []) {
if (cfg.columnName) filterArgs.push(column.columnName);
if (cfg.columnComment) filterArgs.push(column.columnComment);
if (cfg.columnDataType) filterArgs.push(column.dataType);
}
} else {
if (cfg.sqlObjectText) filterArgs.push(createSql);
}
const res = filterName(filter, ...filterArgs);
return res; return res;
}; };
@@ -929,6 +912,7 @@
import { import {
extractDbNameFromComposite, extractDbNameFromComposite,
filterName, filterName,
filterNameCompoud,
generateDbPairingId, generateDbPairingId,
getAlterDatabaseScript, getAlterDatabaseScript,
getConnectionLabel, getConnectionLabel,

View File

@@ -167,7 +167,7 @@ export const DEFAULT_SEARCH_SETTINGS = {
tableName: true, tableName: true,
viewName: true, viewName: true,
columnName: true, columnName: true,
columnDataType: true, columnDataType: false,
tableComment: true, tableComment: true,
columnComment: true, columnComment: true,
sqlObjectName: true, sqlObjectName: true,