1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Extend autocomplete for tags

Discussion in 'Resource and Add-on Requests' started by ForestForTrees, Feb 6, 2016.

  1. ForestForTrees

    ForestForTrees Well-Known Member

    Currently, when you are adding tags, autocomplete doesn't include many tags that might be useful to the user. For example, if you have a tag called "migraines and headaches," it won't appear if the user starts typing headaches. Apparently, it only looks for exact, from-the-start, matches.

    When members use existing tags rather than creating new tags, the tagging system is less fragmented and more useful. As a result, users will create new tags rather than using existing tags. This makes the tagging system less useful and decreases the SEO benefit because of thin content.

    If the right hook exists, it should be pretty simple to write an addon that would broaden the search called by autocomplete. Specifically, it would return any tag where a word in the user's string matches any substring of an existing tag.

  2. ForumCube

    ForumCube Active Member

  3. Mouth

    Mouth Well-Known Member

    Perhaps worth a suggestion to https://xenforo.com/community/resources/tag-essentials.4572/ ?
  4. Chris D

    Chris D XenForo Developer Staff Member

    If you're open to doing a small code edit, you may not need an add on at all.

    Haven't got the code in front of me right now but it's literally a case of changing one line of code from "r" to "lr".

    It would then search the database like "%tag%" instead of "tag%".

    Don't normally condone code edits but with it being such a simple one it might not hurt. Conversely it should be relatively simple to create an add on for it but it may well actually need to overwrite the existing function which may have an adverse effect if other add ons try to extend the same code.
    Last edited: Feb 8, 2016
    ForestForTrees, Mouth and Daniel Hood like this.
  5. Daniel Hood

    Daniel Hood Well-Known Member

    In /library/XenForo/Model/Tag.php this is the function Chris is referring to:

    public function autoCompleteTag($tag$limit 10)
                    SELECT *
                    FROM xf_tag
                    WHERE tag LIKE " 
    XenForo_Db::quoteLike($tag'r') . "
                        AND (use_count > 0 OR permanent = 1)
                    ORDER BY tag
    ), 'tag_id');
    For an add-on to do this, the entire function has to be overwritten otherwise you can change the bolded r to "lr" like Chris mentioned.

    [edit] I just realized you can't bold within php tags. Change "::quoteLike($tag, 'r')" to "::quoteLike($tag, 'lr')".
    Last edited: Feb 8, 2016
    sapph, ForestForTrees and Mouth like this.
  6. ForestForTrees

    ForestForTrees Well-Known Member

    Wow, thanks so much for your help and community spirit, @Chris D and @Daniel Hood. I'll go ahead and do that and will report back here as to how it goes.
    Mouth likes this.

Share This Page