A better Twitter search

If you’ve not noticed already the search in Twitter has been downgraded to 7 days history. In fact, that changed some time ago. I’ve had the good fortune to be able to ask Twitter employees directly about the history via attending Devnest and I’ve been assured the history is being kept.

That doesn’t solve the problem of how am I supposed to find that tweet such and such posted a while ago.

So I’ve written two things: 1) a simple history search for user timelines and 2) a micro library for search filtering.

Searching Further Back

I’ve written a very simple, purely JavaScript based search limited to an individual’s history or their favourites.

Currently you can’t search your “friend” timeline, but it’s a feature I’d be willing to add if people thought it would add a lot of value. If I did add it though, it would have to use Twitter’s oAuth and I’d host it on a Google App Engine (or similar), firstly because friend timelines require authentication (although historically they didn’t…annoyingly) and secondly, because I probably don’t need to host another app myself!

There’s also limits within the API calls I’m making, in particular:

  1. User timeline searches are limited to 200 tweets per hit
  2. Favourite searches are limited to 20 tweets (yeah, only 20!)

Check it out, bookmark it, make use of it:

http://snapbird.org/

Giving Back to Developers: Twitter Search Library

I figured search filtering is a pretty basic requirement, and it’s one that I’d add to a lot of my own apps/hacks and one I’d like to see in apps being built.

I’ve put the search filter library up on Github for people to pinch, share, upgrade and do as you will.

http://github.com/remy/twitter-search-js

The library supports the following search commands (from the existing Twitter search):

  • All these words. Example: cheese wine
  • This exact phrase. Example: “good weather”
  • Any of these words. Example: cheese OR @brucel
  • None of these words. Example: cheese -wine
  • From this person. Example: from:brucel
  • To this person. Example: to:brucel

This can be combined as per the current search in to more complicated search strings: font OR cheese -wife.

Usage

Include the library and you can pass the raw tweet objects to the filter – that’s the raw tweet and not the string (because it needs the tweet to assert the from this person).

if (twitterSearch.filter(tweet, searchString)) {
  // tweet passed search criteria
}

I’d love to see this library plugged in to widgets to allow live search filtering, or HTML based Twitter apps to apply dynamic search filters to any given result of tweets.

5 Responses to “A better Twitter search”

  1. Very cool. I actually had a use for this where I was too lazy to write the search parsing. I forked your code on github and made it a bit more generic (and made the filterTweets work, although renamed filterArray). (And added examples to the README).

    http://github.com/cdmoyer/twitter-search-js

  2. @Scott – true, but it’s not comprehensive, i.e. the results say:

    Results 1 – 10 of about 516

    Where I’m actually nearer 5,000 tweets. Equally, I do know friends who use Google Reader to create a complete backlog of their tweets, it doesn’t contain all the data, but does obviously include the actual tweet.

  3. [...] decided to click the link and had a quick play with the new app. Snap Bird is essentially an enhanced twitter search that Remy has built to find archived tweets which are more than seven days old. I liked the idea [...]

  4. Lovely!

    Just to clarify, however – does this search library (independent from Snapbird) search back further than 7 days? Or can this only be done if your searching back through a *specific person’s* tweets? The filtering idea is cool but, from my (very!) basic understanding, it’s not clear if it’s only filtering through the last 7 days.

    The reason I ask is that I’m putting together a wee app that currently searches *public* tweets using the standard search API (max 7 days/15 tweets), but I’d love to use your code to search the public timeline back a bit further.

    Cheers!

Leave a Reply
Not required

CODE: Please escape code and wrap in <pre><code>, doing so will automatically syntax highlight