Build a customized index widget

By vineet

 

Indexes help you create fun widgets to keep track of the coverage that topics of your interest are getting. The Index Creator in our labs section helps your create an index widget in few minutes with upto 12 topics/queries that you care about.

However, if you want an index widget with more customizations, you can use our News Indexer code to generate the data files for such a widget. Some examples of these customizations could be a an index with

  • more than 12 items (for e.g., CNNMoney's Meme-o-meter Index) OR
  • restrict the results to a particular set of sources (for e.g. Cruisedex restricts the results to travel sources only) OR
  • build an index with different durations to compare (for e.g. last month/this month index)

Remember, this code lets you generate the XML data files for an index widget. You will have to then build the UI for the widget that consumes this XML.

 

 


Solution

The indexer takes a list of queries as an input and generates a weekly index of number of mentions of each query term in the news in last 2 weeks. It also generates a list of 2 stories for each query term that were in the news in last 2 weeks.

You can specify the list of query terms either as a semi-colon separated list or as a URL to an input file that adheres to this format. The input xml file format has a list of tags with a "keyword" attribute. The string in the keyword attribute is what we use as the search term. The value of the tag is what you can use for friendly display. As you can see from our sample input file, we support all the logical operators such as AND, OR like any other binary search.

The index creator outputs an XML that you can use to render your own indexer. Here is how you can test the indexer -- using a input file or using a list of query terms.

This index creator is not the fastest and the performance degrades as you have more input terms. To implement a high performance application, we suggest that you get the response XML every 30 minutes by running this script as a cron job and cache the XML generated on your side to serve it to a live widget.

 

AttachmentSize
news-indexer.php_.zip3.37 KB