From 92cb34b719b481faf417760f307241e8f6d777a9 Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Fri, 2 Jul 2021 22:59:56 +0200 Subject: viewer: types normalization - tag.d.ts GitHub: closes #301 --- viewer/src/services/indexsearch.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'viewer/src/services/indexsearch.ts') diff --git a/viewer/src/services/indexsearch.ts b/viewer/src/services/indexsearch.ts index eda1b27..57bd03c 100644 --- a/viewer/src/services/indexsearch.ts +++ b/viewer/src/services/indexsearch.ts @@ -19,25 +19,26 @@ import { Item } from "@/@types/gallery"; import { Operation } from "@/@types/Operation"; +import { TagSearch, TagSearchByOperation } from "@/@types/tag"; export default class IndexSearch { // Results of the search (by tags) - public static search(searchTags: Tag.Search[]): Item[] { + public static search(searchTags: TagSearch[]): Item[] { const byOperation = this.extractTagsByOperation(searchTags); const intersection = this.extractIntersection(byOperation); const substraction = this.extractSubstraction(byOperation); return this.aggregateAll(byOperation, intersection, substraction); } - private static extractTagsByOperation(searchTags: Tag.Search[]): Tag.SearchByOperation { - const byOperation: Tag.SearchByOperation = {}; + private static extractTagsByOperation(searchTags: TagSearch[]): TagSearchByOperation { + const byOperation: TagSearchByOperation = {}; Object.values(Operation).forEach( operation => (byOperation[operation] = searchTags.filter(tag => tag.operation === operation)) ); return byOperation; } - private static extractIntersection(byOperation: Tag.SearchByOperation): Set { + private static extractIntersection(byOperation: TagSearchByOperation): Set { const intersection = new Set(); if (byOperation[Operation.INTERSECTION].length > 0) { byOperation[Operation.INTERSECTION] @@ -49,7 +50,7 @@ export default class IndexSearch { return intersection; } - private static extractSubstraction(byOperation: Tag.SearchByOperation): Set { + private static extractSubstraction(byOperation: TagSearchByOperation): Set { const substraction = new Set(); if (byOperation[Operation.SUBSTRACTION].length > 0) { byOperation[Operation.SUBSTRACTION].flatMap(tag => tag.items).forEach(item => substraction.add(item)); @@ -58,7 +59,7 @@ export default class IndexSearch { } private static aggregateAll( - byOperation: Tag.SearchByOperation, + byOperation: TagSearchByOperation, intersection: Set, substraction: Set ): Item[] { -- cgit v1.2.3