Split all tags? Sort tags by length?

I have a large list of records that includes a ton of badly formatted entries. As a result, tag lists use inconsistent formatting and when imported, often wind up as one giant conglomeration of tags instead of separate tags. These are too big for the database, and crash the Zotero client when I try to edit them during a sync.

Is there a way to split the entire tag list? Or alternatively, to sort the tag list by tag length so I can see which ones are overly large?
  • You can get a list of all your tags as described here. Too-long tags should be obvious.
    https://forums.zotero.org/discussion/97395/is-there-any-way-to-get-a-list-of-current-tags
  • I'm afraid it's not obvious. There are many pages of tags, and nothing to immediately visually distinguish a huge tag from a bunch of regular tags.
  • edited 27 days ago
    So you got a one-tag-per-line list of all your tags including the badly imported long tags from running the code at the link above ?

    If scrolling through that list is too difficult to find the long tags (you could copy and paste the list into a text editor or word processor to make viewing easier), then there are various ways to sort a text list by line length ... eg
    https://onlinetexttools.com/sort-text-lines
    https://www.browserling.com/tools/line-length-sort

    PS Forget that. ;) I just modified the code there to produce a list of tags sorted by length ...

    var rows = await Zotero.DB.queryAsync("SELECT name AS tagname, COUNT(*) AS num FROM tags JOIN itemTags USING (tagID) GROUP BY tagname ORDER BY LENGTH(tagname) DESC");
    var lines = [];
    for (let row of rows) {
    lines.push(row.tagname + '\t' + row.num);
    }
    return lines.join('\n');
Sign In or Register to comment.