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

Improve search algorithm #7955

Merged
merged 1 commit into from
Oct 22, 2024
Merged

Improve search algorithm #7955

merged 1 commit into from
Oct 22, 2024

Conversation

ijreilly
Copy link
Collaborator

We were previously checking for matching with each search term independently. Ex searching for "felix malfait" we were searching for correspondances with "felix" and "malfait".
As a result record A with name "Marie-Claude Mala" and email "[email protected]" had a biggest search score than record B "Felix Malfait" with email [email protected] for search "felix ma":
for record A we had 0 match with felix and 3 matches with "ma" ("marie", "mala", "ma")
for record B we had 1 match with felix and 1 match with "ma" (with "malfait").

So we want to give more weight to a row that would combine matches with both terms, considering "felix malfait" altogether.

.orderBy(
`ts_rank("${SEARCH_VECTOR_FIELD.name}", to_tsquery(:searchTerms))`,
`ts_rank_cd("${SEARCH_VECTOR_FIELD.name}", to_tsquery(:searchTerms))`,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ts_rank_cd gives weight to terms proximity which makes sense here as we potentially have more than one term.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This pull request improves the search algorithm by implementing a combined 'AND' and 'OR' search approach, addressing issues with search result relevance and ranking.

  • Modified graphql-query-search-resolver.service.ts to introduce separate 'AND' and 'OR' search term formatting
  • Updated query builder to use both 'AND' and 'OR' conditions in the WHERE clause
  • Implemented new ranking method using ts_rank_cd for 'AND' terms and ts_rank for 'OR' terms
  • Removed dependency on FeatureFlagService, simplifying the implementation
  • Enhanced formatSearchTerms method to support both 'AND' and 'OR' operators, improving search flexibility

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

@charlesBochet charlesBochet merged commit f0a2d38 into main Oct 22, 2024
18 checks passed
@charlesBochet charlesBochet deleted the improve-algo branch October 22, 2024 13:47
Weiko pushed a commit that referenced this pull request Oct 25, 2024
The recent addition of a "orWhere" condition to[ improve the search algo
quality](#7955) accidentally
broke the filter, being considered an independent "or" wondition while
we still want the filter to apply.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants