diff options
author | Zero~Informatique | 2021-07-02 22:59:56 +0200 |
---|---|---|
committer | Zero~Informatique | 2021-07-03 00:05:22 +0200 |
commit | 92cb34b719b481faf417760f307241e8f6d777a9 (patch) | |
tree | ba33af35b8bb07e6c1c19b84f6c3af37c791584c /viewer/src/services/indexsearch.ts | |
parent | 9165cc1efcf7791f78b61b2c51a9de651b1b09aa (diff) | |
download | ldgallery-92cb34b719b481faf417760f307241e8f6d777a9.tar.gz |
viewer: types normalization - tag.d.ts
GitHub: closes #301
Diffstat (limited to 'viewer/src/services/indexsearch.ts')
-rw-r--r-- | viewer/src/services/indexsearch.ts | 13 |
1 files changed, 7 insertions, 6 deletions
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 @@ | |||
19 | 19 | ||
20 | import { Item } from "@/@types/gallery"; | 20 | import { Item } from "@/@types/gallery"; |
21 | import { Operation } from "@/@types/Operation"; | 21 | import { Operation } from "@/@types/Operation"; |
22 | import { TagSearch, TagSearchByOperation } from "@/@types/tag"; | ||
22 | 23 | ||
23 | export default class IndexSearch { | 24 | export default class IndexSearch { |
24 | // Results of the search (by tags) | 25 | // Results of the search (by tags) |
25 | public static search(searchTags: Tag.Search[]): Item[] { | 26 | public static search(searchTags: TagSearch[]): Item[] { |
26 | const byOperation = this.extractTagsByOperation(searchTags); | 27 | const byOperation = this.extractTagsByOperation(searchTags); |
27 | const intersection = this.extractIntersection(byOperation); | 28 | const intersection = this.extractIntersection(byOperation); |
28 | const substraction = this.extractSubstraction(byOperation); | 29 | const substraction = this.extractSubstraction(byOperation); |
29 | return this.aggregateAll(byOperation, intersection, substraction); | 30 | return this.aggregateAll(byOperation, intersection, substraction); |
30 | } | 31 | } |
31 | 32 | ||
32 | private static extractTagsByOperation(searchTags: Tag.Search[]): Tag.SearchByOperation { | 33 | private static extractTagsByOperation(searchTags: TagSearch[]): TagSearchByOperation { |
33 | const byOperation: Tag.SearchByOperation = {}; | 34 | const byOperation: TagSearchByOperation = {}; |
34 | Object.values(Operation).forEach( | 35 | Object.values(Operation).forEach( |
35 | operation => (byOperation[operation] = searchTags.filter(tag => tag.operation === operation)) | 36 | operation => (byOperation[operation] = searchTags.filter(tag => tag.operation === operation)) |
36 | ); | 37 | ); |
37 | return byOperation; | 38 | return byOperation; |
38 | } | 39 | } |
39 | 40 | ||
40 | private static extractIntersection(byOperation: Tag.SearchByOperation): Set<Item> { | 41 | private static extractIntersection(byOperation: TagSearchByOperation): Set<Item> { |
41 | const intersection = new Set<Item>(); | 42 | const intersection = new Set<Item>(); |
42 | if (byOperation[Operation.INTERSECTION].length > 0) { | 43 | if (byOperation[Operation.INTERSECTION].length > 0) { |
43 | byOperation[Operation.INTERSECTION] | 44 | byOperation[Operation.INTERSECTION] |
@@ -49,7 +50,7 @@ export default class IndexSearch { | |||
49 | return intersection; | 50 | return intersection; |
50 | } | 51 | } |
51 | 52 | ||
52 | private static extractSubstraction(byOperation: Tag.SearchByOperation): Set<Item> { | 53 | private static extractSubstraction(byOperation: TagSearchByOperation): Set<Item> { |
53 | const substraction = new Set<Item>(); | 54 | const substraction = new Set<Item>(); |
54 | if (byOperation[Operation.SUBSTRACTION].length > 0) { | 55 | if (byOperation[Operation.SUBSTRACTION].length > 0) { |
55 | byOperation[Operation.SUBSTRACTION].flatMap(tag => tag.items).forEach(item => substraction.add(item)); | 56 | byOperation[Operation.SUBSTRACTION].flatMap(tag => tag.items).forEach(item => substraction.add(item)); |
@@ -58,7 +59,7 @@ export default class IndexSearch { | |||
58 | } | 59 | } |
59 | 60 | ||
60 | private static aggregateAll( | 61 | private static aggregateAll( |
61 | byOperation: Tag.SearchByOperation, | 62 | byOperation: TagSearchByOperation, |
62 | intersection: Set<Item>, | 63 | intersection: Set<Item>, |
63 | substraction: Set<Item> | 64 | substraction: Set<Item> |
64 | ): Item[] { | 65 | ): Item[] { |