-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathsearcher-factory.ts
38 lines (36 loc) · 1.52 KB
/
searcher-factory.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { Config } from './config.js';
import { DefaultDynamicSearcher } from './dynamic-searchers/default-dynamic-searcher.js';
import { DynamicSearcher } from './interfaces/dynamic-searcher.js';
import { EntitySearcherFactory } from './entity-searchers/entity-searcher-factory.js';
import { TimingDynamicSearcher } from './dynamic-searchers/timing-dynamic-searcher.js';
/**
* Factory for creating dynamic searchers.
*/
export class SearcherFactory {
/**
* Creates a new dynamic searcher.
* @typeParam TEntity The type of the entities.
* @typeParam TId The type of the entity ids.
* @param config The config to use.
*/
public static createSearcher<TEntity, TId>(config: Config): DynamicSearcher<TEntity, TId> {
const mainSearcher = EntitySearcherFactory.createSearcher<TEntity, TId>(config);
const secondarySearcher = EntitySearcherFactory.createSearcher<TEntity, TId>(config);
let dynamicSearcher: DynamicSearcher<TEntity, TId> = new DefaultDynamicSearcher<TEntity, TId>(
config.maxQueryLength,
mainSearcher,
secondarySearcher
);
dynamicSearcher = new TimingDynamicSearcher<TEntity, TId>(dynamicSearcher);
return dynamicSearcher;
}
/**
* Creates a new default dynamic searcher.
* @typeParam TEntity The type of the entities.
* @typeParam TId The type of the entity ids.
*/
public static createDefaultSearcher<TEntity, TId>(): DynamicSearcher<TEntity, TId> {
const defaultConfig: Config = Config.createDefaultConfig();
return this.createSearcher(defaultConfig);
}
}