Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pref: search index #1241

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions apps/nestjs-backend/src/db-provider/db.provider.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ export interface IDbProvider {

searchQuery(
originQueryBuilder: Knex.QueryBuilder,
fieldMap?: { [fieldId: string]: IFieldInstance },
search?: [string, string?, boolean?]
searchFields: IFieldInstance[],
search?: [string, string?, boolean?],
withFullTextIndex?: boolean
): Knex.QueryBuilder;

searchIndexQuery(
Expand All @@ -143,15 +144,31 @@ export interface IDbProvider {
searchIndexRo: Partial<ISearchIndexByQueryRo>,
baseSortIndex?: string,
setFilterQuery?: (qb: Knex.QueryBuilder) => void,
setSortQuery?: (qb: Knex.QueryBuilder) => void
setSortQuery?: (qb: Knex.QueryBuilder) => void,
withFullTextIndex?: boolean
): Knex.QueryBuilder;

searchCountQuery(
originQueryBuilder: Knex.QueryBuilder,
searchField: IFieldInstance[],
searchValue: string
searchValue: string,
withFullTextIndex?: boolean
): Knex.QueryBuilder;

getSearchTsIndexSql(
originQueryBuilder: Knex.QueryBuilder,
dbTableName: string,
searchField: IFieldInstance[]
): string[];

getClearSearchTsIndexSql(
originQueryBuilder: Knex.QueryBuilder,
dbTableName: string,
searchField: IFieldInstance[]
): string[];

getExistFtsIndexSql(originQueryBuilder: Knex.QueryBuilder, dbTableName: string): string | null;

shareFilterCollaboratorsQuery(
originQueryBuilder: Knex.QueryBuilder,
dbFieldName: string,
Expand Down
61 changes: 52 additions & 9 deletions apps/nestjs-backend/src/db-provider/postgres.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ import { FilterQueryPostgres } from './filter-query/postgres/filter-query.postgr
import type { IGroupQueryExtra, IGroupQueryInterface } from './group-query/group-query.interface';
import { GroupQueryPostgres } from './group-query/group-query.postgres';
import { SearchQueryAbstract } from './search-query/abstract';
import { SearchQueryBuilder, SearchQueryPostgres } from './search-query/search-query.postgres';
import { FullTextSearchQueryPostgresBuilder } from './search-query/search-fts-query.postgres';
import {
SearchQueryPostgresBuilder,
SearchQueryPostgres,
} from './search-query/search-query.postgres';
import { SortQueryPostgres } from './sort-query/postgres/sort-query.postgres';
import type { ISortQueryInterface } from './sort-query/sort-query.interface';

Expand Down Expand Up @@ -320,22 +324,31 @@ export class PostgresProvider implements IDbProvider {

searchQuery(
originQueryBuilder: Knex.QueryBuilder,
fieldMap?: { [fieldId: string]: IFieldInstance },
search?: [string, string?, boolean?]
searchFields: IFieldInstance[],
search?: [string, string?, boolean?],
withFullTextIndex?: boolean
) {
return SearchQueryAbstract.factory(SearchQueryPostgres, originQueryBuilder, fieldMap, search);
return SearchQueryAbstract.appendQueryBuilder(
SearchQueryPostgres,
originQueryBuilder,
searchFields,
search,
withFullTextIndex
);
}

searchCountQuery(
originQueryBuilder: Knex.QueryBuilder,
searchField: IFieldInstance[],
searchValue: string
searchValue: string,
withFullTextIndex?: boolean
) {
return SearchQueryAbstract.buildSearchCountQuery(
SearchQueryPostgres,
originQueryBuilder,
searchField,
searchValue
searchValue,
withFullTextIndex
);
}

Expand All @@ -346,19 +359,49 @@ export class PostgresProvider implements IDbProvider {
searchIndexRo: ISearchIndexByQueryRo,
baseSortIndex?: string,
setFilterQuery?: (qb: Knex.QueryBuilder) => void,
setSortQuery?: (qb: Knex.QueryBuilder) => void
setSortQuery?: (qb: Knex.QueryBuilder) => void,
withFullTextIndex?: boolean
) {
return new SearchQueryBuilder(
return new SearchQueryPostgresBuilder(
originQueryBuilder,
dbTableName,
searchField,
searchIndexRo,
baseSortIndex,
setFilterQuery,
setSortQuery
setSortQuery,
withFullTextIndex
).getSearchIndexQuery();
}

getSearchTsIndexSql(
originQueryBuilder: Knex.QueryBuilder,
dbTableName: string,
searchField: IFieldInstance[]
) {
return new FullTextSearchQueryPostgresBuilder(
originQueryBuilder,
dbTableName,
searchField
).getSearchFieldIndexSql();
}

getClearSearchTsIndexSql(
originQueryBuilder: Knex.QueryBuilder,
dbTableName: string,
searchField: IFieldInstance[]
) {
return new FullTextSearchQueryPostgresBuilder(
originQueryBuilder,
dbTableName,
searchField
).getClearSearchTsIndexSql();
}

getExistFtsIndexSql(originQueryBuilder: Knex.QueryBuilder, dbTableName: string) {
return FullTextSearchQueryPostgresBuilder.getExistFtsIndexSql(originQueryBuilder, dbTableName);
}

shareFilterCollaboratorsQuery(
originQueryBuilder: Knex.QueryBuilder,
dbFieldName: string,
Expand Down
Loading
Loading