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

Order tags based on best match to search query #9879

Merged
merged 2 commits into from
Jul 13, 2021

Conversation

17sushmita
Copy link
Member

Fixes #9623

  • PR is descriptively titled 📑 and links the original issue above 🔗
  • tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR -- or run tests locally with rake test
  • code is in uniquely-named feature branch and has no merge conflicts 📁
  • screenshots/GIFs are attached 📎 in case of UI updation
  • ask @publiclab/reviewers for help, in a comment below

@gitpod-io
Copy link

gitpod-io bot commented Jul 2, 2021

CASE
WHEN name LIKE "' + query + '" THEN 1
WHEN name LIKE "'+ query+'%" THEN 2
WHEN name LIKE "%'+ query +'" THEN 4
Copy link

Choose a reason for hiding this comment

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

Surrounding space missing for operator +.

CASE
WHEN name LIKE "' + query + '" THEN 1
WHEN name LIKE "'+ query+'%" THEN 2
WHEN name LIKE "%'+ query +'" THEN 4
Copy link

Choose a reason for hiding this comment

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

Surrounding space missing for operator +.

.order('
CASE
WHEN name LIKE "' + query + '" THEN 1
WHEN name LIKE "'+ query+'%" THEN 2
Copy link

Choose a reason for hiding this comment

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

Surrounding space missing for operator +.

.order('
CASE
WHEN name LIKE "' + query + '" THEN 1
WHEN name LIKE "'+ query+'%" THEN 2
Copy link

Choose a reason for hiding this comment

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

Surrounding space missing for operator +.

@codecov
Copy link

codecov bot commented Jul 2, 2021

Codecov Report

Merging #9879 (98bdff6) into main (1aaf43b) will decrease coverage by 56.01%.
The diff coverage is 30.76%.

❗ Current head 98bdff6 differs from pull request most recent head b1c2144. Consider uploading reports for the commit b1c2144 to get more accurate results
Impacted file tree graph

@@             Coverage Diff             @@
##             main    #9879       +/-   ##
===========================================
- Coverage   82.06%   26.05%   -56.02%     
===========================================
  Files          98       98               
  Lines        5945     7629     +1684     
===========================================
- Hits         4879     1988     -2891     
- Misses       1066     5641     +4575     
Impacted Files Coverage Δ
app/channels/room_channel.rb 0.00% <0.00%> (-71.43%) ⬇️
app/controllers/stats_controller.rb 0.00% <0.00%> (-71.58%) ⬇️
app/controllers/tag_controller.rb 0.00% <0.00%> (-79.82%) ⬇️
app/models/tag.rb 91.54% <0.00%> (-5.96%) ⬇️
app/helpers/application_helper.rb 37.50% <16.66%> (-47.92%) ⬇️
app/models/node.rb 76.11% <75.00%> (-14.90%) ⬇️
app/models/user.rb 76.51% <75.00%> (-9.51%) ⬇️
app/services/search_service.rb 64.70% <100.00%> (-30.35%) ⬇️
app/controllers/talk_controller.rb 0.00% <0.00%> (-100.00%) ⬇️
app/mailers/password_reset_mailer.rb 0.00% <0.00%> (-100.00%) ⬇️
... and 60 more

@@ -84,6 +84,13 @@ def search_tags(query, limit = 10)
.includes(:node)
.references(:node)
.where('node.status = 1')
.order('
CASE
Copy link
Member

@namangupta01 namangupta01 Jul 4, 2021

Choose a reason for hiding this comment

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

Hey!
Just a quick suggestion can we store the case string in a variable and then just use that inside order?
For example: tags_order = "CASE WHEN name like #{query} THEN 1 WHEN name LIKE #{query}% THEN 2 WHEN name LIKE %{query} THEN 4 ELSE 3"
and then just use order(tags_order).

Also, should we include one more case? WHEN name like %#{query}%

Copy link
Member Author

Choose a reason for hiding this comment

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

@namangupta01, the first suggestion seems to be a good idea to store the string as a variable and using it. I'm adding a commit with the changes.
As per WHEN name like %#{query}% case is concerned, I think it will show up in the ELSE condition as it is the only condition left for else ig. What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi @namangupta01, kindly give this another look when you get some time. Thanks and nice to you see around!

Copy link
Member

@namangupta01 namangupta01 left a comment

Choose a reason for hiding this comment

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

Just a couple of suggestions. Other than this everything looks great. 👍

@@ -78,12 +78,16 @@ def search_maps(input, limit = 25, order = :natural, type = :boolean)
# chained to the notes that are tagged with those values
def search_tags(query, limit = 10)
suggestions = []
# order tag autosuggestions by placing exact match of the tag on the top, then tags with query and some other text as suffix,
# then tags with some text as prefix or suffix and lastly the tags with some text as prefix
tags_order = 'CASE WHEN name LIKE ? OR name LIKE ? THEN 1 WHEN name LIKE ? OR name LIKE ? THEN 2 WHEN name LIKE ? OR name LIKE ? THEN 4 ELSE 3 END', "#{query}", "#{query.to_s.gsub(' ', '-')}", "#{query}%", "#{query.to_s.gsub(' ', '-')}%", "%#{query}", "%#{query.to_s.gsub(' ', '-')}"
Copy link

Choose a reason for hiding this comment

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

Prefer to_s over string interpolation.

@@ -78,12 +78,16 @@ def search_maps(input, limit = 25, order = :natural, type = :boolean)
# chained to the notes that are tagged with those values
def search_tags(query, limit = 10)
suggestions = []
# order tag autosuggestions by placing exact match of the tag on the top, then tags with query and some other text as suffix,
# then tags with some text as prefix or suffix and lastly the tags with some text as prefix
tags_order = 'CASE WHEN name LIKE ? OR name LIKE ? THEN 1 WHEN name LIKE ? OR name LIKE ? THEN 2 WHEN name LIKE ? OR name LIKE ? THEN 4 ELSE 3 END', "#{query}", "#{query.to_s.gsub(' ', '-')}", "#{query}%", "#{query.to_s.gsub(' ', '-')}%", "%#{query}", "%#{query.to_s.gsub(' ', '-')}"
Copy link

Choose a reason for hiding this comment

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

Prefer to_s over string interpolation.

@jywarren
Copy link
Member

jywarren commented Jul 6, 2021

Trying to resolve in #9873

@jywarren
Copy link
Member

jywarren commented Jul 6, 2021

Sorry this is so annoying! I actually just merged #9881 so if you'd like to try rebasing over it it might help!

@codeclimate
Copy link

codeclimate bot commented Jul 7, 2021

Code Climate has analyzed commit b1c2144 and detected 2 issues on this pull request.

Here's the issue category breakdown:

Category Count
Style 2

View more on Code Climate.

@publiclab publiclab deleted a comment from codeclimate bot Jul 7, 2021
Copy link
Collaborator

@cesswairimu cesswairimu left a comment

Choose a reason for hiding this comment

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

This is looking good 🎉 🎉

We can ignore code climate warnings...let me know if we are good to merge...Thanks @17sushmita 🎉 🎉

@17sushmita
Copy link
Member Author

This is looking good

We can ignore code climate warnings...let me know if we are good to merge...Thanks @17sushmita

Yes, we are good to merge @cesswairimu. Thanks 😄

@jywarren jywarren merged commit 6832a43 into publiclab:main Jul 13, 2021
@jywarren
Copy link
Member

Looks great! I resolved the CodeClimate and for some reason the CodeCov error just went away instantly. 🤷

@ebarry
Copy link
Member

ebarry commented Jul 21, 2021

this is so great!

@bhamster07
Copy link

Hooray, thanks so much everyone!! 😀

reginaalyssa pushed a commit to reginaalyssa/plots2 that referenced this pull request Oct 16, 2021
* order tags based on best match to search query

* minor changes in ordering tags based on best match
billymoroney1 pushed a commit to billymoroney1/plots2 that referenced this pull request Dec 28, 2021
* order tags based on best match to search query

* minor changes in ordering tags based on best match
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.

Existing tags not showing up as an exact match in search bar autosuggestions
6 participants