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

Existing tags not showing up as an exact match in search bar autosuggestions #9623

Closed
bhamster07 opened this issue May 12, 2021 · 3 comments · Fixed by #9879
Closed

Existing tags not showing up as an exact match in search bar autosuggestions #9623

bhamster07 opened this issue May 12, 2021 · 3 comments · Fixed by #9879
Labels
add-code-links discussion enhancement explains that the issue is to improve upon one of our existing features help wanted requires help by anyone willing to contribute

Comments

@bhamster07
Copy link

Please describe the problem (or idea)

What happened just before the problem occurred? Or what problem could this idea solve?

Not quite a bug, but more of an observation that I didn't realize was limiting the results I'd see when using the search bar: when previously searching for mapping content, I entered mapping into the search bar, and that tag didn't appear in the autosuggested list of tags (see screenshot). But today I saw the mapping tag on a post and clicked on it, and saw from the tag page that there's quite a lot of content there tagged with mapping!

mapping results

What did you expect to see that you didn't?

I expected to see mapping appear in the autosuggested list of tags as an exact match when entering that term into the search bar, given that the mapping tag page exists and there's lots of content attached to that tag.

Please show us where to look

Existing content with the mapping tag: https://publiclab.org/tag/mapping

What's your PublicLab.org username?

bhamster

@welcome
Copy link

welcome bot commented May 12, 2021

Thanks for opening your first issue! This space is protected by our Code of Conduct - and we're here to help.
Please follow the issue template to help us help you 👍🎉😄
If you have screenshots or a gif to share demonstrating the issue, that's really helpful! 📸
Do join our Gitter channel for some brainstorming discussions.

@jywarren jywarren added add-code-links discussion enhancement explains that the issue is to improve upon one of our existing features help wanted requires help by anyone willing to contribute labels May 18, 2021
@jywarren
Copy link
Member

Hi @bhamster07 thank you for a very clearly documented observation and idea! ✨

I'm going to try to tease out some details here to help. My questions:

  1. what is the current sorting?
  2. where in the code would we be able to insert an exact match to add it to the results?
  3. would it cause any slowdown to add a 2nd query? (autocompletes are very latency sensitive for the user - we want it to be as fast as possible)
  4. do we need to worry about filtering it out of the remaining results once we add it at the top? (this seems easy so why not)
  5. would adding the exact match at the top result in any other features on the site getting affected? (i.e. do we use this matching generator for other purposes where we don't want this modification?)

OK, so to 1) i see this endpoint where we're responding to autocompletion: https://publiclab.org/tag/suggested/mapping (only accessible via JavaScript):

def suggested
if !params[:id].empty? && params[:id].size > 2
@suggestions = SearchService.new.search_tags(params[:id])
render json: @suggestions.collect { |tag| tag.name }.uniq
else
render json: []
end
end

Note this is different from the tag autocompletion in the search box on https://publiclab.org/tags, which is from this segment of code.

As to 5) i want to cautiously say the only other place we're using this code is on https://publiclab.org/search/tags

I think that means we could insert the exact match at the top of the list in this deeper API code:

def search_tags(query, limit = 10)
suggestions = []
# filtering out tag spam by requiring tags attached to a published node
# also, we search for both "balloon mapping" and "balloon-mapping":
Tag.where('name LIKE ? OR name LIKE ?', "%#{query}%", "%#{query.to_s.gsub(' ', '-')}%")
.includes(:node)
.references(:node)
.where('node.status = 1')
.limit(limit).each do |tag|
suggestions << tag
end
suggestions
end

I'd like also to write a functional test for this to confirm that the top match is the exact match. I think this would be based on this test, and follow it, using an entire word like "spectrometer":

test 'shows suggested tags' do
get :suggested, params: { id: 'spectr' }
assert_equal 4, assigns(:suggestions).length
assert_equal ['question:spectrometer', 'spectrometer', 'activity:spectrometer', 'activities:spectrometer'].sort, JSON.parse(response.body).sort
end

This is great because for the partial match we'd still see this ordering:

assert_equal ['question:spectrometer', 'spectrometer', 'activity:spectrometer', 'activities:spectrometer'].sort, JSON.parse(response.body).sort

But in the exact match we'd see items 1 and 2 swap places. That should be a great and specific test.

I want to propose adding this to the Tagging project for our combined Outreachy and GSoC teams! cc @17sushmita @Manasa2850 (more soon on how your project plans may overlap! 🎉)

@jywarren jywarren added this to the Tagging and topics milestone May 18, 2021
@bhamster07
Copy link
Author

Thanks so much for building this issue out with all these details @jywarren ! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add-code-links discussion enhancement explains that the issue is to improve upon one of our existing features help wanted requires help by anyone willing to contribute
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants