* Perform the actual index lookup based on the hint.
(
indexManager: NonNullable<GraphSource<any>["indexManager"]>,
label: string,
hint: IndexHint,
)
| 2444 | * Perform the actual index lookup based on the hint. |
| 2445 | */ |
| 2446 | #performIndexLookup( |
| 2447 | indexManager: NonNullable<GraphSource<any>["indexManager"]>, |
| 2448 | label: string, |
| 2449 | hint: IndexHint, |
| 2450 | ): Set<ElementId> | undefined { |
| 2451 | switch (hint.type) { |
| 2452 | case "hash": { |
| 2453 | const hashIndex = indexManager.getHashIndex(label, hint.property); |
| 2454 | if (!hashIndex) return undefined; |
| 2455 | |
| 2456 | if (hint.operation === "equals") { |
| 2457 | return new Set(hashIndex.lookup(hint.value)); |
| 2458 | } else if (hint.operation === "in") { |
| 2459 | return hashIndex.lookupMany(hint.value as readonly unknown[]); |
| 2460 | } |
| 2461 | return undefined; |
| 2462 | } |
| 2463 | |
| 2464 | case "btree": { |
| 2465 | const btreeIndex = indexManager.getBTreeIndex(label, hint.property); |
| 2466 | if (!btreeIndex) return undefined; |
| 2467 | |
| 2468 | const value = hint.value as number | string; |
| 2469 | |
| 2470 | switch (hint.operation) { |
| 2471 | case "equals": |
| 2472 | return btreeIndex.lookup(value); |
| 2473 | case "lessThan": |
| 2474 | return btreeIndex.lookupLessThan(value); |
| 2475 | case "lessThanOrEqual": |
| 2476 | return btreeIndex.lookupLessThanOrEqual(value); |
| 2477 | case "greaterThan": |
| 2478 | return btreeIndex.lookupGreaterThan(value); |
| 2479 | case "greaterThanOrEqual": |
| 2480 | return btreeIndex.lookupGreaterThanOrEqual(value); |
| 2481 | default: |
| 2482 | return undefined; |
| 2483 | } |
| 2484 | } |
| 2485 | |
| 2486 | case "fulltext": { |
| 2487 | const fulltextIndex = indexManager.getFullTextIndex(label, hint.property); |
| 2488 | if (!fulltextIndex) return undefined; |
| 2489 | |
| 2490 | const value = hint.value as string; |
| 2491 | let results: Set<ElementId>; |
| 2492 | |
| 2493 | switch (hint.operation) { |
| 2494 | case "startsWith": |
| 2495 | results = fulltextIndex.searchTermPrefix(value); |
| 2496 | break; |
| 2497 | case "contains": |
| 2498 | results = fulltextIndex.searchContains(value); |
| 2499 | break; |
| 2500 | case "search": { |
| 2501 | const searchResults = fulltextIndex.search(value); |
| 2502 | results = new Set(searchResults.map((r) => r.elementId)); |
| 2503 | break; |
no test coverage detected