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

fix: sqlite search index e2e #1202

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,47 @@ export class SearchQueryBuilder {
this.setSortQuery = setSortQuery;
}

getSearchQuery() {
const { queryBuilder, searchIndexRo, searchField } = this;
const { search } = searchIndexRo;
const searchValue = search?.[0];

if (!search || !searchField?.length || !searchValue) {
return queryBuilder;
}

return searchField.map((field) => {
const searchQueryBuilder = new SearchQuerySqlite(queryBuilder, field, searchValue);
if (field.isMultipleCellValue) {
switch (field.cellValueType) {
case CellValueType.DateTime:
return searchQueryBuilder.getMultipleDateSqlQuery();
case CellValueType.Number:
return searchQueryBuilder.getMultipleNumberSqlQuery();
case CellValueType.String:
if (field.isStructuredCellValue) {
return searchQueryBuilder.getMultipleJsonSqlQuery();
} else {
return searchQueryBuilder.getMultipleTextSqlQuery();
}
}
}

switch (field.cellValueType) {
case CellValueType.DateTime:
return searchQueryBuilder.getDateSqlQuery();
case CellValueType.Number:
return searchQueryBuilder.getNumberSqlQuery();
case CellValueType.String:
if (field.isStructuredCellValue) {
return searchQueryBuilder.getJsonSqlQuery();
} else {
return searchQueryBuilder.getTextSqlQuery();
}
}
});
}

getSearchIndexQuery() {
const {
queryBuilder,
Expand All @@ -242,16 +283,18 @@ export class SearchQueryBuilder {
setFilterQuery,
setSortQuery,
} = this;
const { search, take, skip, filter, orderBy, groupBy } = searchIndexRo;
const { search, filter, orderBy, groupBy } = searchIndexRo;
const knexInstance = queryBuilder.client;

if (!search || !searchField?.length) {
return queryBuilder;
}

const searchQuerySql = this.getSearchQuery() as string[];

queryBuilder.with('search_field_union_table', (qb) => {
for (let index = 0; index < searchField.length; index++) {
const currentWhereRaw = searchField[index];
const currentWhereRaw = searchQuerySql[index];
const dbFieldName = searchField[index].dbFieldName;

// boolean field or new field which does not support search should be skipped
Expand Down
Loading