|
|
@@ -27,7 +27,7 @@ import { DefaultSearchPluginInitOptions } from './types';
|
|
|
*/
|
|
|
@Injectable()
|
|
|
export class FulltextSearchService {
|
|
|
- private searchStrategy: SearchStrategy;
|
|
|
+ private _searchStrategy: SearchStrategy;
|
|
|
private readonly minTermLength = 2;
|
|
|
|
|
|
constructor(
|
|
|
@@ -52,8 +52,8 @@ export class FulltextSearchService {
|
|
|
input: SearchInput,
|
|
|
enabledOnly: boolean = false,
|
|
|
): Promise<Omit<Omit<SearchResponse, 'facetValues'>, 'collections'>> {
|
|
|
- const items = await this.searchStrategy.getSearchResults(ctx, input, enabledOnly);
|
|
|
- const totalItems = await this.searchStrategy.getTotalCount(ctx, input, enabledOnly);
|
|
|
+ const items = await this._searchStrategy.getSearchResults(ctx, input, enabledOnly);
|
|
|
+ const totalItems = await this._searchStrategy.getTotalCount(ctx, input, enabledOnly);
|
|
|
return {
|
|
|
items,
|
|
|
totalItems,
|
|
|
@@ -68,7 +68,7 @@ export class FulltextSearchService {
|
|
|
input: SearchInput,
|
|
|
enabledOnly: boolean = false,
|
|
|
): Promise<Array<{ facetValue: FacetValue; count: number }>> {
|
|
|
- const facetValueIdsMap = await this.searchStrategy.getFacetValueIds(ctx, input, enabledOnly);
|
|
|
+ const facetValueIdsMap = await this._searchStrategy.getFacetValueIds(ctx, input, enabledOnly);
|
|
|
const facetValues = await this.facetValueService.findByIds(ctx, Array.from(facetValueIdsMap.keys()));
|
|
|
return facetValues.map((facetValue, index) => {
|
|
|
return {
|
|
|
@@ -86,7 +86,7 @@ export class FulltextSearchService {
|
|
|
input: SearchInput,
|
|
|
enabledOnly: boolean = false,
|
|
|
): Promise<Array<{ collection: Collection; count: number }>> {
|
|
|
- const collectionIdsMap = await this.searchStrategy.getCollectionIds(ctx, input, enabledOnly);
|
|
|
+ const collectionIdsMap = await this._searchStrategy.getCollectionIds(ctx, input, enabledOnly);
|
|
|
const collections = await this.collectionService.findByIds(ctx, Array.from(collectionIdsMap.keys()));
|
|
|
return collections.map((collection, index) => {
|
|
|
return {
|
|
|
@@ -108,21 +108,29 @@ export class FulltextSearchService {
|
|
|
* Sets the SearchStrategy appropriate to th configured database type.
|
|
|
*/
|
|
|
private setSearchStrategy() {
|
|
|
- switch (this.connection.rawConnection.options.type) {
|
|
|
- case 'mysql':
|
|
|
- case 'mariadb':
|
|
|
- this.searchStrategy = new MysqlSearchStrategy(this.connection, this.options);
|
|
|
- break;
|
|
|
- case 'sqlite':
|
|
|
- case 'sqljs':
|
|
|
- case 'better-sqlite3':
|
|
|
- this.searchStrategy = new SqliteSearchStrategy(this.connection, this.options);
|
|
|
- break;
|
|
|
- case 'postgres':
|
|
|
- this.searchStrategy = new PostgresSearchStrategy(this.connection, this.options);
|
|
|
- break;
|
|
|
- default:
|
|
|
- throw new InternalServerError(`error.database-not-supported-by-default-search-plugin`);
|
|
|
+ if (this.options.searchStategy) {
|
|
|
+ this._searchStrategy = this.options.searchStategy;
|
|
|
+ } else {
|
|
|
+ switch (this.connection.rawConnection.options.type) {
|
|
|
+ case 'mysql':
|
|
|
+ case 'mariadb':
|
|
|
+ this._searchStrategy = new MysqlSearchStrategy();
|
|
|
+ break;
|
|
|
+ case 'sqlite':
|
|
|
+ case 'sqljs':
|
|
|
+ case 'better-sqlite3':
|
|
|
+ this._searchStrategy = new SqliteSearchStrategy();
|
|
|
+ break;
|
|
|
+ case 'postgres':
|
|
|
+ this._searchStrategy = new PostgresSearchStrategy();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ throw new InternalServerError(`error.database-not-supported-by-default-search-plugin`);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public get searchStrategy(): SearchStrategy {
|
|
|
+ return this._searchStrategy;
|
|
|
+ }
|
|
|
}
|