diff options
author | zeroinformatique | 2021-07-03 00:48:53 +0200 |
---|---|---|
committer | GitHub | 2021-07-03 00:48:53 +0200 |
commit | b6605e2c4ee73ac8b994624098344db5e44ac07d (patch) | |
tree | 5ed06cc5ecdabe070f6fdb9bc4f9a8a3b435cbe6 /viewer/src/services/indexsearch.ts | |
parent | 08ac32103fb5f8cca1861267dfd07a7c0d2faf62 (diff) | |
parent | 1f0377c1b4c2959c73fe4e368673f057ef369917 (diff) | |
download | ldgallery-b6605e2c4ee73ac8b994624098344db5e44ac07d.tar.gz |
Merge pull request #302 from ldgallery/oz-types-normalization
viewer: types normalization
Diffstat (limited to 'viewer/src/services/indexsearch.ts')
-rw-r--r-- | viewer/src/services/indexsearch.ts | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/viewer/src/services/indexsearch.ts b/viewer/src/services/indexsearch.ts index 00f8cfc..57bd03c 100644 --- a/viewer/src/services/indexsearch.ts +++ b/viewer/src/services/indexsearch.ts | |||
@@ -17,27 +17,29 @@ | |||
17 | -- along with this program. If not, see <https://www.gnu.org/licenses/>. | 17 | -- along with this program. If not, see <https://www.gnu.org/licenses/>. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | import { Item } from "@/@types/gallery"; | ||
20 | import { Operation } from "@/@types/Operation"; | 21 | import { Operation } from "@/@types/Operation"; |
22 | import { TagSearch, TagSearchByOperation } from "@/@types/tag"; | ||
21 | 23 | ||
22 | export default class IndexSearch { | 24 | export default class IndexSearch { |
23 | // Results of the search (by tags) | 25 | // Results of the search (by tags) |
24 | public static search(searchTags: Tag.Search[]): Gallery.Item[] { | 26 | public static search(searchTags: TagSearch[]): Item[] { |
25 | const byOperation = this.extractTagsByOperation(searchTags); | 27 | const byOperation = this.extractTagsByOperation(searchTags); |
26 | const intersection = this.extractIntersection(byOperation); | 28 | const intersection = this.extractIntersection(byOperation); |
27 | const substraction = this.extractSubstraction(byOperation); | 29 | const substraction = this.extractSubstraction(byOperation); |
28 | return this.aggregateAll(byOperation, intersection, substraction); | 30 | return this.aggregateAll(byOperation, intersection, substraction); |
29 | } | 31 | } |
30 | 32 | ||
31 | private static extractTagsByOperation(searchTags: Tag.Search[]): Tag.SearchByOperation { | 33 | private static extractTagsByOperation(searchTags: TagSearch[]): TagSearchByOperation { |
32 | const byOperation: Tag.SearchByOperation = {}; | 34 | const byOperation: TagSearchByOperation = {}; |
33 | Object.values(Operation).forEach( | 35 | Object.values(Operation).forEach( |
34 | operation => (byOperation[operation] = searchTags.filter(tag => tag.operation === operation)) | 36 | operation => (byOperation[operation] = searchTags.filter(tag => tag.operation === operation)) |
35 | ); | 37 | ); |
36 | return byOperation; | 38 | return byOperation; |
37 | } | 39 | } |
38 | 40 | ||
39 | private static extractIntersection(byOperation: Tag.SearchByOperation): Set<Gallery.Item> { | 41 | private static extractIntersection(byOperation: TagSearchByOperation): Set<Item> { |
40 | const intersection = new Set<Gallery.Item>(); | 42 | const intersection = new Set<Item>(); |
41 | if (byOperation[Operation.INTERSECTION].length > 0) { | 43 | if (byOperation[Operation.INTERSECTION].length > 0) { |
42 | byOperation[Operation.INTERSECTION] | 44 | byOperation[Operation.INTERSECTION] |
43 | .map(tag => tag.items) | 45 | .map(tag => tag.items) |
@@ -48,8 +50,8 @@ export default class IndexSearch { | |||
48 | return intersection; | 50 | return intersection; |
49 | } | 51 | } |
50 | 52 | ||
51 | private static extractSubstraction(byOperation: Tag.SearchByOperation): Set<Gallery.Item> { | 53 | private static extractSubstraction(byOperation: TagSearchByOperation): Set<Item> { |
52 | const substraction = new Set<Gallery.Item>(); | 54 | const substraction = new Set<Item>(); |
53 | if (byOperation[Operation.SUBSTRACTION].length > 0) { | 55 | if (byOperation[Operation.SUBSTRACTION].length > 0) { |
54 | 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)); |
55 | } | 57 | } |
@@ -57,10 +59,10 @@ export default class IndexSearch { | |||
57 | } | 59 | } |
58 | 60 | ||
59 | private static aggregateAll( | 61 | private static aggregateAll( |
60 | byOperation: Tag.SearchByOperation, | 62 | byOperation: TagSearchByOperation, |
61 | intersection: Set<Gallery.Item>, | 63 | intersection: Set<Item>, |
62 | substraction: Set<Gallery.Item> | 64 | substraction: Set<Item> |
63 | ): Gallery.Item[] { | 65 | ): Item[] { |
64 | byOperation[Operation.ADDITION].flatMap(tag => tag.items).forEach(item => intersection.add(item)); | 66 | byOperation[Operation.ADDITION].flatMap(tag => tag.items).forEach(item => intersection.add(item)); |
65 | substraction.forEach(item => intersection.delete(item)); | 67 | substraction.forEach(item => intersection.delete(item)); |
66 | return [...intersection]; | 68 | return [...intersection]; |