Skip to content

fix(search-service): fix global search issue#2561

Open
Sourav-kashyap wants to merge 1 commit into
masterfrom
GH-2553
Open

fix(search-service): fix global search issue#2561
Sourav-kashyap wants to merge 1 commit into
masterfrom
GH-2553

Conversation

@Sourav-kashyap

Copy link
Copy Markdown
Contributor

fix global search issue
GH-2553

Description

In Global Search, users are unable to see search results when searching for names containing . (dot), for example: Deal 10.1.
The issue originates from the _formatAndSanitize method in query.builder.ts, which is used by search.provider.ts.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • Performed a self-review of my own code
  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes

@Sourav-kashyap Sourav-kashyap self-assigned this Jun 10, 2026
@Sourav-kashyap Sourav-kashyap requested review from a team and akshatdubeysf as code owners June 10, 2026 11:11
@Sourav-kashyap Sourav-kashyap added the bug Something isn't working label Jun 10, 2026
@Sourav-kashyap Sourav-kashyap force-pushed the GH-2553 branch 2 times, most recently from e242a42 to 8e3d9eb Compare June 10, 2026 11:34
@a-ganguly a-ganguly requested a review from Copilot June 10, 2026 11:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes PostgreSQL global-search token sanitization so search terms containing dots (e.g., Deal 10.1) are preserved instead of being split/removed, and adds unit coverage for the updated sanitization behavior.

Changes:

  • Update PsqlQueryBuilder._formatAndSanitize to allow . in tokens and strip unsafe to_tsquery operators.
  • Add unit tests covering dotted terms (decimals, project names, IPs) and mixed punctuation.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
services/search-service/src/classes/psql/query.builder.ts Adjusts match sanitization/tokenization to preserve dots for PostgreSQL full-text search queries.
services/search-service/src/tests/unit/psql/query.builder.unit.ts Adds targeted unit tests for _formatAndSanitize with dotted search terms and mixed characters.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +80 to +84
_formatAndSanitize(param: string) {
return param
.replace(/[^A-Za-z\s0-9]/g, ' ')
.split(' ')
.filter(p => p)
.map(p => `${p}:*`)
.join('<->');
}
    let result = param;
    while (result.endsWith('.')) {
      result = result.slice(0, -1);
    }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

@sonarqubecloud

Copy link
Copy Markdown

SonarQube reviewer guide

Summary: Add comprehensive unit tests and improve sanitization logic for the _formatAndSanitize method to preserve dots in search terms while properly handling PostgreSQL full-text search special characters.

Review Focus: The sanitization logic change is critical—verify that the new regex patterns correctly preserve dots in identifiers (e.g., "Deal 10.1", "testlift.QA") while removing PostgreSQL tsquery special characters, and ensure the trailing dot removal doesn't introduce edge cases. Confirm the test cases adequately cover expected input patterns.

Start review at: services/search-service/src/classes/psql/query.builder.ts. This is where the core logic change occurs—the refactored _formatAndSanitize method directly impacts search functionality and requires careful validation that the new regex patterns and filtering logic are correct and performant.

💬 Please send your feedback

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
51.0% Duplication on New Code

See analysis details on SonarQube Cloud

@vaibhavbhalla2505

Copy link
Copy Markdown
Contributor

I have checked it, and it's working fine now.

before:
Screenshot 2026-06-10 at 4 30 44 PM

now:
Screenshot 2026-06-10 at 4 31 45 PM

Comment on lines +81 to +91
let result = param;
while (result.endsWith('.')) {
result = result.slice(0, -1);
}

return result
.replace(/[!&|<>():'"]/g, ' ') // Remove PostgreSQL tsquery special chars
.replace(/[^A-Za-z0-9.\s]/g, ' ') // Keep dots, remove other symbols
.split(/\s+/) // Split on any whitespace (not just spaces)
.filter(p => p && p !== '.') // Filter empty and standalone dots
.map(p => `${p}:*`) // Add prefix match operator

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need a fix in mysql builder as well
check and confirm

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This issue is specific to PostgreSQL's tsquery syntax requirements. MySQL's full-text search handles dots correctly by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

In Global Search, users are unable to see search results when searching for names containing . (dot).

5 participants