Simple tags



  • Hey

    I found these 3 lines in https://github.com/NodeBB/NodeBB/blob/4f38a33702b78acf7707065fc73416f68d0a46b8/src/topics/tags.js

    tag = tag.trim().toLowerCase();
    tag = tag.replace(/[,\/#!$%\^\*;:{}=_`<>'"~()?\|]/g, '');
    tag = tag.substr(0, meta.config.maximumTagLength || 15).trim();
    

    These lines create rather simple tags, which are hard to use. We wanna create a set of tags, which the user then can choose from
    Eg. "CHR (CHR. HANSEN HOLDING)". I can see that this decision makes it easy to compare tags afterwards. Are there any other reasons for this? Or could this be changed so that tags are saves as they are written?

    Best regards


  • Admin

    You can probably remove those restrictions but be careful about what you allow, you most definitely want to run the tag through something like tag = validator.escape(tag) if you are going to allow more characters.

    Also if you don't lowercase tags NODEBB and NodeBB will be different tags.



  • Thanks for the response @baris.

    You are of course right, if I should do this, the tags need to be escaped. Secondly I was thinking along the lines of testing equality of two tags 'nodebb' and 'NodeBB' by comparing them in lower case. So the problem I see there is that if the first added as 'nodebb' then someone come along and creates tag 'NodeBB' then the first tag 'win' so to say even though the second is properly the more correct way.

    And then the question. If I where to make this change, and create a PR on Github, are there any chance this is adopted into the code base. Cause we really don't wanna have to patch our version of the forum before production.

    Best regards.


  • Admin

    I'm not sure if we want case sensitive tags in core.

    However you can easily create a plugin and replace the entire tag functionality. Then you don't have to do it again after updating to later versions of nodebb.

    For example in your plugin you can replace the entire tag creation functionality with

    var topics = module.parent.require('./topics);
    
    topics.createTags = function(tags, tid, timestamp, callback) {
    
    };
    
    topics.cleanUpTag = function(tag) {
    //apply your tag cleanup
    return tag;
    };
    

    Another possibility is to add a filter into topics.cleanUpTag so plugins can define their own logic for what they allow.

    The biggest issue to figure out is searching and displaying tags. Right now each tag stores a list of topic ids in tag:<tagname>:topics. So for nodebb its tag:nodebb:topics. Since we lowercase all tags topics tagged with any variation of NodeBB go into the same list. With your approach you won't have all the topics grouped under the same tag because you will have different sorted sets like tag:NodeBB:topics, tag:nodebb:topics, tag:Nodebb:topics and so on. And when a user searches for nodebb they won't necessarily get all the topics.



  • To avoid the database being filled with the same tag in different cases like tag:NodeBB:topics, tag:nodebb:topics, tag:Nodebb:topics and so on, couldn't we then just add tags in topics.createTags as the tag eg. NodeBB was first created. So even though the users types nodebb we still add the original NodeBB or are the other drawbacks to this.


  • Admin

    Yeah after the first tag is created as NodeBB, whenever a user enters a variation of it you need to check all posibilites if it exists in the database already. Like NoDeBb 🙂



  • I see the predicament. Nasty job to generalize that problem 🙂


  • Global Moderator

    @h_kirk said:

    I see the predicament. Nasty job to generalize that problem 🙂

    Strtolower solves 100% of issues.


Log in to reply
 


Looks like your connection to NodeBB was lost, please wait while we try to reconnect.