Tags Suggest
started by: Giovanni SavastanoGiovanni Savastano
on: 1213010691|%e %b %Y, %H:%M %Z|agohover
number of posts: 1
rss icon RSS: new posts
Tags Suggest
Giovanni SavastanoGiovanni Savastano 1213010691|%e %b %Y, %H:%M %Z|agohover

Hi all,
I'm trying to implement some new features in wikidot v1
one of these is "tags suggest". this feature works as usersearch do. while you type a tag in the form PageTagsModule, it "suggest" you what similar tags you have already used in other pages.

this is the main function (a poor copy&past&modify from PageLookupQModule….):

class TagsLookupQModule extends QuickModule {    
    public function process($data){
        // does not use data

        $search = $_GET['q'];
        $siteId = $_GET['s'];
        if(!is_numeric($siteId)) return;
        if($search == null || strlen($search) ==0) return;

        $search1 = pg_escape_string(preg_quote($search));
        $search2 = pg_escape_string($search);

        Database::init();
        $q1 = "SELECT tag, tag_id FROM page_tag WHERE " .
                "tag ~* '^$search1' AND tag != '$search2' AND site_id = '$siteId'";
        $q1 .= "ORDER BY tag LIMIT 20";
        $q2 = "SELECT tag, user_id FROM page_tag WHERE " .
                "tag = '$search2'  AND site_id ='$siteId'";
        $db = Database::connection();

        $result1 = $db->query($q1);
        $result1 = $result1->fetchAll();
        $result2 = $db->query($q2);
        $result2 = $result2->fetchAll();

        if($result1 == null && $result2 != null) $result = $result2;
        if($result2 == null && $result1 != null) $result = $result1;
        if($result1 != null && $result2 != null){
            $result = array_merge($result2, $result1);
        }

        return array('tags' => $result);
    }

}

now I need to modify PageTagsModule.js in order to allow search operation.
anyone can help me? I think this feature would be very usefull for everyone.

thanks,
Gio

unfold Tags Suggest by Giovanni SavastanoGiovanni Savastano, 1213010691|%e %b %Y, %H:%M %Z|agohover
new post
Unless stated otherwise Content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License