Coder Social home page Coder Social logo

Comments (22)

neatchee avatar neatchee commented on August 26, 2024

I think this is an easy fix; it looks like a change was made in 2019 that changed the sort order, but then it was changed back, and the field name to sort on was changed, and it was never updated again to sort with the new field name. Testing a fix now...

from mastodon.

neatchee avatar neatchee commented on August 26, 2024

Well, this is rather complicated...

The sorting function is set up to sort from values in the tags sql table, which does not store the actual occurrence count. The "uses this week" value is an aggregate value generated at runtime from recent tag history. Sorting was set up to use a "score" which is built over time, and is now recorded as "max_score"

So we could easily redo the sorting to use the max_score but that does NOT produce a sorted list by "uses this week"; for example "mastodogs" appears above "mastodon" because at some point mastodogs got super popular and bursted above the average usage of 'mastodon'.

I've got a version deployed that feels a bit better but still isn't great. It'd be a substantive refactor to actually sort by "uses this week" unfortunately.

from mastodon.

neatchee avatar neatchee commented on August 26, 2024

This is the tags table schema:

---------------------+-----------------------------
 id                  | bigint
 name                | character varying
 created_at          | timestamp without time zone 
 updated_at          | timestamp without time zone 
 usable              | boolean 
 trendable           | boolean
 listable            | boolean
 reviewed_at         | timestamp without time zone
 requested_review_at | timestamp without time zone
 last_status_at      | timestamp without time zone
 max_score           | double precision
 max_score_at        | timestamp without time zone
 display_name        | character varying

And this is the current deployed sorting code for Urusai as of now:

def search_for(term, limit = 5, offset = 0, options = {})
    stripped_term = term.strip

    query = Tag.listable.matches_name(stripped_term)
    query = query.merge(matching_name(stripped_term).or(where.not(reviewed_at: nil))) if options[:exclude_unreviewed]

    query.order(Arel.sql('max_score ASC, name ASC'))
         .limit(limit)
         .offset(offset)
  end

Currently checked in upstream is:

query.order(Arel.sql(length(name) ASC, name ASC'))
         .limit(limit)
         .offset(offset)

from mastodon.

neatchee avatar neatchee commented on August 26, 2024

Well, the real answer here is to just do what's intended to get better autosuggestion/search: set up elasticsearch integration.

So that's what I'm doing :D

We can try to make this better too, if we want, but IMO it's low prio since there's a preferred solution

from mastodon.

deanveloper avatar deanveloper commented on August 26, 2024

Think this is worth reopening, doesn't seem fixed, even with elasticsearch :/

image

from mastodon.

neatchee avatar neatchee commented on August 26, 2024

from mastodon.

deanveloper avatar deanveloper commented on August 26, 2024

Oh just looked at the code snippet, you probably want to order by score DESC right? ASC would sort it least-to-most

from mastodon.

neatchee avatar neatchee commented on August 26, 2024

from mastodon.

deanveloper avatar deanveloper commented on August 26, 2024

Hmm... I'll see if I can mess around with it and see if I can figure something out. Seems weird because the current behavior seems correct on other hashtags, like this is exactly what I would expect:

image
image

from mastodon.

neatchee avatar neatchee commented on August 26, 2024

from mastodon.

deanveloper avatar deanveloper commented on August 26, 2024

Hashtag ordering seems to work fine on Megalodon... I wonder if this is just some weird edge case in the browser

from mastodon.

neatchee avatar neatchee commented on August 26, 2024

from mastodon.

deanveloper avatar deanveloper commented on August 26, 2024

Nope, it looks like the frontend is doing something weird... The request seems to return the hashtags in the right order. Wonder what's happening.

image

However... when redux gets updated, looks like they're out of order. Weird...

image

from mastodon.

neatchee avatar neatchee commented on August 26, 2024

from mastodon.

deanveloper avatar deanveloper commented on August 26, 2024

It looks like some kind of transformation gets applied before it gets put in redux, trying to figure out where this happens (which seems a bit weird, not like suggestions really need to be stored in global state...)

EDIT - Guessing it has something to do with this line. (app/javascript/flavours/glitch/reducers/compose.js)

return mergeLocalHashtagResults(sortHashtagsByUse(state, tags.map(item => ({ ...item, type: 'hashtag' }))), token.slice(1), state.get('tagHistory'));

from mastodon.

deanveloper avatar deanveloper commented on August 26, 2024

This seems so weird... I can't seem to replicate the behavior in Node, even if I copy the behavior nearly line-for-line

Browser
image

Node
image

The browser one starts correctly, but then ends incorrectly, and I have no clue why

from mastodon.

neatchee avatar neatchee commented on August 26, 2024

from mastodon.

deanveloper avatar deanveloper commented on August 26, 2024

Yup, reproduces in all browsers. Although I've got it reproducing in node now, so that's good! Maybe I was just copying it over incorrectly.

from mastodon.

deanveloper avatar deanveloper commented on August 26, 2024

Oh man, I figured it out. I'll file this bug with mastodon as well.

It only occurs if:

  1. You have used the hashtag in this browser, which puts it in your tagHistory.
  2. The tag in your tagHistory matches (case sensitive) one of the suggested hashtags.

If both of these cases happen, it's supposed to promote it to the top, as it's a suggested hashtag which you have used before. However, the sorting algorithm is reversed, and case-sensitive, making it (inconsistently) demote it to the bottom.

from mastodon.

neatchee avatar neatchee commented on August 26, 2024

from mastodon.

deanveloper avatar deanveloper commented on August 26, 2024

Ahh, the bug appears to have been introduced in glitch-soc, I assume mastodon fixed it but glitch-soc never brought the fix over?

from mastodon.

neatchee avatar neatchee commented on August 26, 2024

from mastodon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.