Previous | Next
WireHose Developers Guide

Tagging items

In addition to using whatever categories were specified for an item in its RSS feed, the Hello World crawler will also assign tags based on the feed's categories.

  1. Add this method to
    static void tagItemsForFeed(EOEditingContext ec, NSArray items, RSSFeed feed) {
        // use this to get a tagpath without "Feeds/" at the beginning
        // for example, "Consumer/Gardening" instead of "Feeds/Consumer/Gardening"
        WHTag feedAncestor = WHTag.tagForPath(ec, "Feeds", false);
        NSMutableArray tags = new NSMutableArray();
        String path;
        WHTag tag;
        // iterate through the feed's tags
        // and build an array of tags to assign to items
        for (int i=0, count=feed.tags().count(); i<count; i++) {
            tag = (WHTag)feed.tags().objectAtIndex(i);
            // get a tagpath that starts with "Content/" instead of "Feeds/"
            // e.g., "Content/Consumer/Gardening"
            path = "Content/"+tag.tagPath(feedAncestor, "/");
            // add a tag for that path
            tags.addObject(WHTag.tagForPath(ec, path, true));
            // and add a tag for that path, plus the feed's name
            // e.g., "Consumer/Gardening/ Botany"
            tags.addObject(WHTag.tagForPath(ec, path+"/", true));
        RSSItem item;
        // iterate through items
        for (int i=0, count=items.count(); i<count; i++) {
            item = (RSSItem)items.objectAtIndex(i);
            // associate the item with the feed
            item.addObjectToBothSidesOfRelationshipWithKey(feed, "feed");
            // and add tags to the item
            WHTag.addTags(item, tags);

Previous | Next