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

#226 Improve Kosh searching results order #227

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

tsingh777
Copy link
Contributor

Followed this example: https://www.codexworld.com/how-to/sort-results-order-by-best-match-using-like-in-mysql/

The order would be
1 - if the query matches the words
2 - if the query matches the beginning of the word
3 - if the query matches the end of the word
4 - if the query matches the definition
5 - if the query matches the beginning of the definition
6 - if the query matches the end of the definition

Also adds a new end point that searches only on words and not definitions.

@tsingh777 tsingh777 linked an issue Jan 3, 2021 that may be closed by this pull request
tarunsingh5
tarunsingh5 previously approved these changes Jan 4, 2021
tarunsingh5
tarunsingh5 previously approved these changes Jan 4, 2021
Copy link
Collaborator

@tarunsingh5 tarunsingh5 left a comment

Choose a reason for hiding this comment

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

sql lgtm

@ManjotS
Copy link
Contributor

ManjotS commented Jan 4, 2021 via email

@tsingh777
Copy link
Contributor Author

Adding an if then in a query is a performance killer and not scalable (in any database).

On Mon, Jan 4, 2021 at 7:52 AM tsingh777 @.> wrote: @.* commented on this pull request. ------------------------------ In api/controllers/kosh.js <#227 (comment)> : > + WHEN wordUni LIKE ? THEN 2 + WHEN word LIKE ? THEN 3 + WHEN wordUni LIKE ? THEN 3 + ELSE 4 + END`; + const rows = await conn.query(q, [ + match, + match, + match, + match, + fullMatch, + fullMatch, + startMatch, + startMatch, + endMatch, + endMatch, Will prioritize #113 <#113> next so these things can be caught earlier. — You are receiving this because your review was requested. Reply to this email directly, view it on GitHub <#227 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAE5OFODGI3QK4XQVJNQ3FTSYHP25ANCNFSM4VSFTE4A .

@ManjotS What do you recommend?

@tarunsingh5
Copy link
Collaborator

Adding an if then in a query is a performance killer and not scalable (in any database).

On Mon, Jan 4, 2021 at 7:52 AM tsingh777 @.> wrote: @.* commented on this pull request. ------------------------------ In api/controllers/kosh.js <#227 (comment)> : > + WHEN wordUni LIKE ? THEN 2 + WHEN word LIKE ? THEN 3 + WHEN wordUni LIKE ? THEN 3 + ELSE 4 + END`; + const rows = await conn.query(q, [ + match, + match, + match, + match, + fullMatch, + fullMatch, + startMatch, + startMatch, + endMatch, + endMatch, Will prioritize #113 <#113> next so these things can be caught earlier. — You are receiving this because your review was requested. Reply to this email directly, view it on GitHub <#227 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAE5OFODGI3QK4XQVJNQ3FTSYHP25ANCNFSM4VSFTE4A .

there isn't a logical work around - what you could do is either pre-stage that data by setting up intermediary tables or you can reduce the # of conditions you are checking for.

@tsingh777
Copy link
Contributor Author

What about UNION ?

SELECT w.ID AS id, w.Word AS word, w.WordUni AS wordUni,
                  d.DefGurmukhi AS definition, d.DefGurmukhiUni AS definitionUni
                FROM MahanKoshWords w
                LEFT JOIN MahanKoshDefinitions d ON w.Definition = d.ID
                WHERE w.Word LIKE ? 
UNION 
SELECT w.ID AS id, w.Word AS word, w.WordUni AS wordUni,
                  d.DefGurmukhi AS definition, d.DefGurmukhiUni AS definitionUni
                FROM MahanKoshWords w
                LEFT JOIN MahanKoshDefinitions d ON w.Definition = d.ID
                WHERE w.WordUni LIKE BINARY ?
UNION 
SELECT w.ID AS id, w.Word AS word, w.WordUni AS wordUni,
                  d.DefGurmukhi AS definition, d.DefGurmukhiUni AS definitionUni
                FROM MahanKoshWords w
                LEFT JOIN MahanKoshDefinitions d ON w.Definition = d.ID
                WHERE d.DefGurmukhi LIKE ?
UNION 
SELECT w.ID AS id, w.Word AS word, w.WordUni AS wordUni,
                  d.DefGurmukhi AS definition, d.DefGurmukhiUni AS definitionUni
                FROM MahanKoshWords w
                LEFT JOIN MahanKoshDefinitions d ON w.Definition = d.ID
                WHERE d.DefGurmukhiUni LIKE BINARY ?

@tarunsingh5
Copy link
Collaborator

this should work, another thing to make this faster may be to do the where clause prior to the join

@AkalUstat
Copy link
Collaborator

@tsingh777 whats the status on this?

@tsingh777
Copy link
Contributor Author

Need to run some performance tests. will update soon.

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.

Better kosh search sorting
5 participants