From f2ff937fe4a5782741886ef4920fd0e284775463 Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Thu, 27 Feb 2020 23:26:00 +0100 Subject: viewer: tag index bugfix Search from the URL requires a strict match instead of a loose match Category search was case sensitive Category + disambiguation was matching like an intersection of both tags instead of being hard-coupled Removed the logs for the release (coming soon) --- viewer/src/components/LdCommand.vue | 2 +- viewer/src/components/LdTagInput.vue | 2 +- viewer/src/services/indexfactory.ts | 36 ++++++++++++++++++++++------------ viewer/src/views/GalleryNavigation.vue | 1 - viewer/src/views/PanelLeft.vue | 2 +- 5 files changed, 27 insertions(+), 16 deletions(-) (limited to 'viewer') diff --git a/viewer/src/components/LdCommand.vue b/viewer/src/components/LdCommand.vue index 398107e..9afd121 100644 --- a/viewer/src/components/LdCommand.vue +++ b/viewer/src/components/LdCommand.vue @@ -55,7 +55,7 @@ export default class LdCommand extends Vue { } isEntryPoint(): boolean { - return history.state.ldgallery === "ENTRYPOINT"; // Set by MainLayout.vue + return history.state?.ldgallery === "ENTRYPOINT"; // Set by MainLayout.vue } parent(): RawLocation { diff --git a/viewer/src/components/LdTagInput.vue b/viewer/src/components/LdTagInput.vue index b2a2c58..bdb07bc 100644 --- a/viewer/src/components/LdTagInput.vue +++ b/viewer/src/components/LdTagInput.vue @@ -55,7 +55,7 @@ export default class LdTagInput extends Vue { } searchTags(filter: string) { - this.filteredTags = IndexFactory.searchTags(this.tagsIndex, filter) + this.filteredTags = IndexFactory.searchTags(this.tagsIndex, filter, false) .filter(newSearch => !this.model.find(currentSearch => currentSearch.tag === newSearch.tag)) .sort((a, b) => b.items.length - a.items.length); } diff --git a/viewer/src/services/indexfactory.ts b/viewer/src/services/indexfactory.ts index 6fed6cc..45abcd5 100644 --- a/viewer/src/services/indexfactory.ts +++ b/viewer/src/services/indexfactory.ts @@ -30,7 +30,6 @@ export default class IndexFactory { // Pushes all tags for a root item (and its children) to the index private static pushTagsForItem(tagsIndex: Tag.Index, item: Gallery.Item): void { - console.log("IndexingTagsFor: ", item.path); if (item.properties.type === "directory") { item.properties.items.forEach(item => this.pushTagsForItem(tagsIndex, item)); return; // Directories are not indexed @@ -39,27 +38,35 @@ export default class IndexFactory { const parts = tag.split(':'); let lastPart: string | null = null; for (const part of parts) { - if (!tagsIndex[part]) tagsIndex[part] = { tag: part, tagfiltered: Navigation.normalize(part), items: [], children: {} }; - if (!tagsIndex[part].items.includes(item)) tagsIndex[part].items.push(item); - if (lastPart) tagsIndex[lastPart].children[part] = tagsIndex[part]; + tagsIndex[part] = IndexFactory.pushPartToIndex(tagsIndex[part], part, item); + if (lastPart) { + const children = tagsIndex[lastPart].children; + children[part] = IndexFactory.pushPartToIndex(children[part], part, item); + } lastPart = part; } } } + private static pushPartToIndex(index: Tag.Node, part: string, item: Gallery.Item): Tag.Node { + if (!index) index = { tag: part, tagfiltered: Navigation.normalize(part), items: [], children: {} }; + if (!index.items.includes(item)) index.items.push(item); + return index; + } + // --- - public static searchTags(tagsIndex: Tag.Index, filter: string): Tag.Search[] { + public static searchTags(tagsIndex: Tag.Index, filter: string, strict: boolean): Tag.Search[] { let search: Tag.Search[] = []; if (tagsIndex && filter) { const operation = IndexFactory.extractOperation(filter); if (operation !== Operation.INTERSECTION) filter = filter.slice(1); if (filter.includes(":")) { const filterParts = filter.split(":"); - search = this.searchTagsFromFilterWithCategory(tagsIndex, operation, filterParts[0], filterParts[1]); + search = this.searchTagsFromFilterWithCategory(tagsIndex, operation, filterParts[0], filterParts[1], strict); } else { - search = this.searchTagsFromFilter(tagsIndex, operation, filter); + search = this.searchTagsFromFilter(tagsIndex, operation, filter, strict); } } return search; @@ -80,22 +87,27 @@ export default class IndexFactory { tagsIndex: Tag.Index, operation: Operation, category: string, - disambiguation: string + disambiguation: string, + strict: boolean ): Tag.Search[] { + category = Navigation.normalize(category); disambiguation = Navigation.normalize(disambiguation); return Object.values(tagsIndex) - .filter(node => node.tag.includes(category)) + .filter(node => strict || node.tagfiltered.includes(category)) + .filter(node => !strict || node.tagfiltered === category) .flatMap(node => Object.values(node.children) - .filter(child => child.tagfiltered.includes(disambiguation)) + .filter(child => strict || child.tagfiltered.includes(disambiguation)) + .filter(child => !strict || child.tagfiltered === disambiguation) .map(child => ({ ...child, parent: node, operation, display: `${operation}${node.tag}:${child.tag}` })) ); } - private static searchTagsFromFilter(tagsIndex: Tag.Index, operation: Operation, filter: string): Tag.Search[] { + private static searchTagsFromFilter(tagsIndex: Tag.Index, operation: Operation, filter: string, strict: boolean): Tag.Search[] { filter = Navigation.normalize(filter); return Object.values(tagsIndex) - .filter(node => node.tagfiltered.includes(filter)) + .filter(node => strict || node.tagfiltered.includes(filter)) + .filter(node => !strict || node.tagfiltered === filter) .map(node => ({ ...node, operation, display: `${operation}${node.tag}` })); } } diff --git a/viewer/src/views/GalleryNavigation.vue b/viewer/src/views/GalleryNavigation.vue index fafb2ed..7c6d11b 100644 --- a/viewer/src/views/GalleryNavigation.vue +++ b/viewer/src/views/GalleryNavigation.vue @@ -49,7 +49,6 @@ export default class GalleryNavigation extends Vue { @Watch("path") pathChanged() { - console.log("Path: ", this.path); this.$galleryStore.setCurrentPath(this.path); } diff --git a/viewer/src/views/PanelLeft.vue b/viewer/src/views/PanelLeft.vue index 54b9c63..5b3196a 100644 --- a/viewer/src/views/PanelLeft.vue +++ b/viewer/src/views/PanelLeft.vue @@ -72,7 +72,7 @@ export default class PanelLeft extends Vue { const query = Object.keys(route.query); if (query.length > 0) { const tagsIndex = this.$galleryStore.tagsIndex; - this.searchFilters = Object.keys(route.query).flatMap(filter => IndexFactory.searchTags(tagsIndex, filter)); + this.searchFilters = Object.keys(route.query).flatMap(filter => IndexFactory.searchTags(tagsIndex, filter, true)); this.$galleryStore.setCurrentSearch([...this.searchFilters]); } } -- cgit v1.2.3