aboutsummaryrefslogtreecommitdiff
path: root/viewer/src/services/indexsearch.ts
diff options
context:
space:
mode:
Diffstat (limited to 'viewer/src/services/indexsearch.ts')
-rw-r--r--viewer/src/services/indexsearch.ts17
1 files changed, 9 insertions, 8 deletions
diff --git a/viewer/src/services/indexsearch.ts b/viewer/src/services/indexsearch.ts
index 00f8cfc..eda1b27 100644
--- a/viewer/src/services/indexsearch.ts
+++ b/viewer/src/services/indexsearch.ts
@@ -17,11 +17,12 @@
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
20import { Item } from "@/@types/gallery";
20import { Operation } from "@/@types/Operation"; 21import { Operation } from "@/@types/Operation";
21 22
22export default class IndexSearch { 23export default class IndexSearch {
23 // Results of the search (by tags) 24 // Results of the search (by tags)
24 public static search(searchTags: Tag.Search[]): Gallery.Item[] { 25 public static search(searchTags: Tag.Search[]): Item[] {
25 const byOperation = this.extractTagsByOperation(searchTags); 26 const byOperation = this.extractTagsByOperation(searchTags);
26 const intersection = this.extractIntersection(byOperation); 27 const intersection = this.extractIntersection(byOperation);
27 const substraction = this.extractSubstraction(byOperation); 28 const substraction = this.extractSubstraction(byOperation);
@@ -36,8 +37,8 @@ export default class IndexSearch {
36 return byOperation; 37 return byOperation;
37 } 38 }
38 39
39 private static extractIntersection(byOperation: Tag.SearchByOperation): Set<Gallery.Item> { 40 private static extractIntersection(byOperation: Tag.SearchByOperation): Set<Item> {
40 const intersection = new Set<Gallery.Item>(); 41 const intersection = new Set<Item>();
41 if (byOperation[Operation.INTERSECTION].length > 0) { 42 if (byOperation[Operation.INTERSECTION].length > 0) {
42 byOperation[Operation.INTERSECTION] 43 byOperation[Operation.INTERSECTION]
43 .map(tag => tag.items) 44 .map(tag => tag.items)
@@ -48,8 +49,8 @@ export default class IndexSearch {
48 return intersection; 49 return intersection;
49 } 50 }
50 51
51 private static extractSubstraction(byOperation: Tag.SearchByOperation): Set<Gallery.Item> { 52 private static extractSubstraction(byOperation: Tag.SearchByOperation): Set<Item> {
52 const substraction = new Set<Gallery.Item>(); 53 const substraction = new Set<Item>();
53 if (byOperation[Operation.SUBSTRACTION].length > 0) { 54 if (byOperation[Operation.SUBSTRACTION].length > 0) {
54 byOperation[Operation.SUBSTRACTION].flatMap(tag => tag.items).forEach(item => substraction.add(item)); 55 byOperation[Operation.SUBSTRACTION].flatMap(tag => tag.items).forEach(item => substraction.add(item));
55 } 56 }
@@ -58,9 +59,9 @@ export default class IndexSearch {
58 59
59 private static aggregateAll( 60 private static aggregateAll(
60 byOperation: Tag.SearchByOperation, 61 byOperation: Tag.SearchByOperation,
61 intersection: Set<Gallery.Item>, 62 intersection: Set<Item>,
62 substraction: Set<Gallery.Item> 63 substraction: Set<Item>
63 ): Gallery.Item[] { 64 ): Item[] {
64 byOperation[Operation.ADDITION].flatMap(tag => tag.items).forEach(item => intersection.add(item)); 65 byOperation[Operation.ADDITION].flatMap(tag => tag.items).forEach(item => intersection.add(item));
65 substraction.forEach(item => intersection.delete(item)); 66 substraction.forEach(item => intersection.delete(item));
66 return [...intersection]; 67 return [...intersection];