-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.ts
More file actions
18 lines (15 loc) · 883 Bytes
/
search.ts
File metadata and controls
18 lines (15 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { solveShapeQueryContainment } from 'query-shape-detection';
import type { IQuery } from 'query-shape-detection';
import type { CatalogEntity, CatalogRecord, SearchCatalogResult, SearchEntityResult } from './types';
import { toResult } from './result/result';
function searchEntity(entity: CatalogEntity, query: IQuery): SearchEntityResult {
const result = solveShapeQueryContainment({ query, shapes: entity.shapes });
return { entity: entity.entity, entityType: entity.entityType, result: toResult(result) };
}
function searchCatalog(record: CatalogRecord, query: IQuery): SearchCatalogResult {
const entities = record.entities.map(entity => searchEntity(entity, query));
return { catalog: record.id, entities };
}
export function search(store: CatalogRecord[], query: IQuery): SearchCatalogResult[] {
return store.map(record => searchCatalog(record, query));
}