A few days ago I blogged about an Aggregator UDF I was working on. This UDF took a set of RSS feeds and returned a "joined" query, like MXNA, FullAsAGoog, or Feed-Squirrel. I've worked on this a bit more and have updated it to be a full CFC. I've made some interesting changes I think folks may like as well.
First off - the CFFEED tag returns a query that contains as much information as possible about the RSS feed. But if you are working with dynamic/multiple feeds at once, it is a bit difficult to write one query to output the results for all of them. So for example, the linkhref column is used for Atom feeds while rsslink is used for RSS. In order to use the right column, you would normally check the metadata returned from the cffeed tag. Consider this example from the ColdFusion 8 docs:
<cfoutput query = "myQuery">
<cfif myProps.version IS "atom_1.0">
<h3><a href = "#linkhref#">#title#</a></h3>
<p><b>Published:</b> #DateFormat(publisheddate)#</p>
<cfelse>
<h3><a href = "#rsslink#">#title#</a></h3>
<p><b>Published:</b> #publisheddate#</p>
</cfif>
<p>#content#</p>
</cfoutput>
So one of the first things I added was a new column, link. This column will contain the appropriate column based on the feed type.
Another problem is the difference in date formats. Atom has a format and RSS has another format. Again - don't worry. I combine this into a new Date column. (Thanks to Jared for help parsing the Atom feed.) This fix also makes the sorting work nicer as well.
So along with an aggregator method, I added search. Want to search RSS feeds for a particular search term?
<cfset aggregator = createObject("component", "aggregator")>
<cfset feeds2 = "http://weblogs.macromedia.com/mxna/xml/rss.cfm?query=byMostRecent&languages=1,http://www.riaforge.org/index.cfm?event=page.rss,http://feeds.feedburner.com/RaymondCamdensColdfusionBlog,http://www.protogenius.com/atom/example-03.atom">
<!--- Test Search --->
<cfset results = aggregator.search(listToArray(feeds2), "ray")>
<cfdump var="#results#">
So test it out and let me know what you think. This will be the core of my new RSSWatcher.com site, when I find the time to build it. ;) If you use the sample code above, you may notice MXNA doesn't return a value from dates. This is a known bug in CFFEED and has been reported.
Archived Comments
How about a third parameter in search() for caseSensitive? Either that or just make the dang thing insensitive...I hate that about QofQ.
Actually, that is what I wanted and I just forgot. So by default it will be case insensitive, and I'll allow you to make it sensitive.
You know how do to that yourself, right? Without waiting for me I mean.
I do. I also have a few other mods in progress if you'd like me to share.
PS - not getting any emails from comments here on the blog. And I'm sure I subscribed.
Another issue: If the feed is malformed or errors out in some way we have an issue. You have a catch where you look for thread.entries and if it doesn't exist you create an empty query - but your [date] column bombs out:
Error:
The following information is meant for the website developer for debugging purposes.
Error Occurred While Processing Request
The column name [date] is invalid.
Column names must be valid variable names. They must start with a letter and can only include letters, numbers, and underscores.
The error occurred in C:\inetpub\wwwroot\test\agg\aggregator.cfc: line 84
82 : <cfset results["result_#x#"] = thread.entries>
83 : <cfelse>
84 : <cfset results["result_#x#"] = queryNew(variables.collist)>
85 : </cfif>
86 : </cfloop>
Surrounding the reserved word 'date' with brackets is a fix for when you are using variables.collist for the QofQ - but the brackets won't work in queryNew().
Probably best to name it pubdate or something else...
Good catch there. I escape it for search, I need to escape it there.
Hey - if you want to send those mods todya, please do. I'd like to release this up on RIAForge (and yes, I know I've said in the past that individual CFCs don't really belong on RIAForge, but oh well :)