Skip to content

Commit

Permalink
fix: handle search string ending with colon
Browse files Browse the repository at this point in the history
fixes #110
  • Loading branch information
drodil committed Jan 8, 2024
1 parent 7371b18 commit 5e0248f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions plugins/qeta-backend/src/database/DatabaseQetaStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,17 @@ describe.each(databases.eachSupportedId())(
expect(noQuestions?.questions.length).toEqual(0);
});

it('should fetch list of questions with special characters in searchQuery', async () => {
await insertQuestion({
...question,
content: 'Cannot read config file:',
});
const ret = await storage.getQuestions('user1', {
searchQuery: 'Cannot read config file:',
});
expect(ret?.questions.length).toEqual(1);
});

it('should fetch questions with specific component', async () => {
const q1 = await storage.postQuestion(
'user1',
Expand Down
4 changes: 2 additions & 2 deletions plugins/qeta-backend/src/database/DatabaseQetaStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ export class DatabaseQetaStore implements QetaStore {
if (options.searchQuery) {
if (this.db.client.config.client === 'pg') {
query.whereRaw(
`(to_tsvector('english', questions.title || ' ' || questions.content) @@ websearch_to_tsquery('english', ?)
or to_tsvector('english', questions.title || ' ' || questions.content) @@ to_tsquery('english',?))`,
`(to_tsvector('english', questions.title || ' ' || questions.content) @@ websearch_to_tsquery('english', quote_literal(?))
or to_tsvector('english', questions.title || ' ' || questions.content) @@ to_tsquery('english',quote_literal(?)))`,
[
`${options.searchQuery}`,
`${options.searchQuery.replaceAll(/\s/g, '+')}:*`,
Expand Down

0 comments on commit 5e0248f

Please sign in to comment.