The eclectic musings of a bitter software engineer.

Trogdor: Burninatingly fast search using Yahoo! BOSS

Tuesday November 25, 2008 @ 04:02 PM (PST)

Everyone and their dog seems to have written an example of how to use the Yahoo! Search BOSS API to build a simple search tool. I wanted to take that one step further and build something that would serve both as an example and as a usable service, and that could be extended and enhanced by other developers. Since my day job involves constant tradeoffs between making Yahoo! Search slower (by adding features) and making it faster (by optimizing those features), my primary goal here was to make something as fast as technically possible.

To do this, I wrote a very simple JavaScript module called Trogdor that uses dynamic script nodes to make cross-domain JSONP requests to the BOSS API as you type your query. Search results are returned and rendered almost instantly on each keystroke, and you can use the up and down arrow keys (or tab) and enter to quickly select the result you want—no mouse necessary.

Trogdor doesn’t require a JavaScript framework and works great in all modern browsers (and even some ancient, crappy browsers like IE6). The entire package (HTML, CSS and JS) weighs just a smidge under 2KB after minification and gzip, and it’s wonderfully fast.

Try it out for yourself at pieisgood.org/search and be sure to grab the heavily-commented source code on GitHub. If you’ve got ideas for features and improvements, fork the repo and go nuts (and be sure to let me know what you come up with). You’re also welcome to use Trogdor (modified or unmodified) in your own projects, although I do ask that you please use your own BOSS API key rather than the one included in the example.

Update, 11/26: Changed the name of the library from FastSearch to Trogdor, since dragons are awesome (and apparently there’s a Microsoft search product called FastSearch).

Comments

I really dig how fast the results render, cool example as well. Thanks.

Gravatar icon
Tuesday November 25, 2008 @ 06:18 PM (PST)

:-)

Great work!

Gravatar icon
joe
Tuesday November 25, 2008 @ 08:23 PM (PST)

Actually, I’ve already written a Yahoo! Search helper for Ramaze as part of Thoth. It’s what powers the search feature on wonko.com. You can find the source here. It uses the old Search API though, since I wrote it pre-BOSS.

Gravatar icon
Tuesday November 25, 2008 @ 08:59 PM (PST)

very cool ryan!

(and yes, i have an example of how to do use yahoo boss to build a search tool too! )

Gravatar icon
Wednesday November 26, 2008 @ 12:04 AM (PST)

But how long until the cease and desist from Homestar Runner?

Gravatar icon
juku retard
Friday November 28, 2008 @ 11:36 AM (PST)

http://pieisgood.org/search doesn’t work anymore

Gravatar icon
joe
Tuesday December 30, 2008 @ 12:38 PM (PST)

it works in firefox, but not in google chrome (1.0.154.42). i get these errors in the javascript console:
Uncaught SyntaxError: Unexpected number http://boss.yahooapis.com/ysearch/web/v1/p?appid=C82ywM3V34FSPr8EUqeE61WL6zQ1psBVArWY62MoVxyuljPRIfkcdnWSKDTKBuTkFsyMAkvp9Q--&format=jsonp&callback=Trogdor.results%5B'p'%5D (line 1)

Resource interpreted as script but transferred with MIME type text/html. http://boss.yahooapis.com/ysearch/web/v1/p?appid=C82ywM3V34FSPr8EUqeE61WL6zQ1psBVArWY62MoVxyuljPRIfkcdnWSKDTKBuTkFsyMAkvp9Q—&format=jsonp&callback=Trogdor.results%5B’p’%5D

Gravatar icon
joe
Tuesday December 30, 2008 @ 12:55 PM (PST)

looks like encodeURIComponent doesn’t deal with quotes on chrome. So I added a replace() at the end:

callback: encodeURIComponent(“Trogdor.results[’” + query.replace(/’/g, \

“\\’”) + “’]”).replace(/’/g,“%27”),

Gravatar icon
joe
Wednesday December 31, 2008 @ 10:36 AM (PST)

Thanks Joe, I’ve implemented the fix.

Gravatar icon
Wednesday December 31, 2008 @ 01:28 PM (PST)
New comment

required, won't be displayed

optional

Don't type anything here unless you're an evil robot:


And especially don't type anything here:

Basic XHTML (including links) is allowed, just don't try anything fishy. Your comment will be auto-formatted unless you use your own <p> tags for formatting. You're also welcome to use Textile.

Copyright © 2002-2009 Ryan Grove. All rights reserved.
Powered by Thoth.