Making a search command – part 2

A few days have passed since my first post Making a search command – the easy way!, and a few new features have been implemented, most of which were suggested by readers – so keep up filling the suggestion box!

Picture this

Most notably, it is now possible to include a thumbnail in the preview, which will be automatically formatted and inserted to the left of the preview text. This is especially useful for search-sites which display images to help identify the result – such as books, cd, movies, etc…

As an example, here is the Wikipedia command redone with this enhancement:

CmdUtils.makeSearchCommand({
  name: "Amazon",
  url: "http://www.amazon.com/s/ref=nb_ss_gw?url=search-alias%3Dstripbooks&field-keywords={QUERY}",
  parser: {container: "div.listView",
           title: "div.productTitle a",
           preview: "div.productTitle span.ptBrand",
           thumbnail: "div.productImage"}
});

You will also note the lack of an icon and description, but if you try it out (in latest source) you’ll see that it makes no difference. If left out, they are automatically generated from url and name respectively.

Search preview with thumbnails

Search preview with thumbnails

Correcting errors

Some sites (like Amazon) have a tendency to return weird results in the middle of the set, without any real indication that it isn’t an actual result, and this can cause the parser to become confused (say, if the number of titles and the number of preview do not match up, which belongs to which?), and before, it would give you a warning in console and then most likely die before returning any output to the user. Now, it will fall back to just supplying a list of titles, and explain to the user why the previews are missing.

Search with broken preview

Search with broken preview

What’s next?

The next thing I’ll be looking into, is allowing makeSearchCommand to use services that return JSON encoded data. This will enable us to use APIs made public by many search engines instead of scraping the HTML, and is a feature that has not only been requested by early adopters, but will also make it possible (and/or easier) to switch over to this new parser system for all of our default search commands.

As usual, I encourage you all to try out the new features, and see if anything breaks or behaves unexpectedly. And of course, if they do: let me know! :-)

3 thoughts on “Making a search command – part 2

  1. Pingback: Making a search command - part 3 « Geeks By Nature

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>