One of biggest pains when writing a new DQSD search is massaging the correct HTML FORM into well-formed XML. I finally got annoyed enough to
write a little utility to do some of the work for me. I call it Dave's Quick Search Deskbar Search Wizard.
What does it do and why would I want to use it?
In a nutshell, it generates a DQSD search from the page currently displayed in your browser.
If you have no desire to ever write a search for DQSD, then don't read any further. If you do write searches from time to time, or at least want to, then you may find the wizard useful.
The first thing I typically do when creating a new search is to view the source for the page and strip out everything but the FORM for the search. This is tedious. And, often it's hard to find the right FORM when there are multiple FORMs in the page. Also, the process of converting the FORM's HTML to well-formed XML is error-prone (I always forget to close the INPUT elements with "/>"). There had to be an easier way.
If you don't, simply right-click on the IE toolbar, and click 'Customize...'. Add the button labeled "DQSD Search Wizard" in the list of available toolbar buttons.
Go to the web page containing the search you want to add to DQSD.
Click in the field that contains the search string.
Start up the wizard by clicking on its Internet Explorer toolbar button.
You should see a dialog that looks something like the following. Some of the fields will be automatically filled in. Enter an abbreviation and a title for the new search. The abbreviation is the string that will invoke the search and will be used for the file name, so keep it short and simple.
(Hold your cursor over the different fields to see their description.)
In the list of FORM elements, make sure at least one FORM is checked. If you clicked in a field before invoking the wizard, the FORM containing that field should be already be checked. Selecting a FORM in the list and expanding the dialog by clicking the HTML button will show the HTML content of the FORM. Selecting a FORM will also change the background and outline of the FORM on the web page in most cases. This is really just to provide some help in determining which FORM(s) you need include. You can check multiple FORMs, all of which will be included in the search file.
Hit OK and you'll be prompted to save the search file to your DQSD 'searches' directory.
After saving the file, it will come up in Notepad by default. (Click 'Options...' to change the editor to something other than Notepad.)
In the screenshot above, I went to http://www.loc.gov (the US Library of Congress) and clicked in the search field...
Then I clicked the 'DQSD Search Wizard' button. All FORM elements in the page are listed (in this case only one), with the one checked that contains the 'active' element. I entered an abbreviation and a title (the title appears in the menu and help). Finally, I pressed 'OK' and I was prompted to save 'loc.xml' to the 'searches' subdirectory of my DQSD installation.
The resulting XML file search file will look something like the following. And, in spite of the comment at the top of the file, this search just works. Woo hoo! (Well, I find it fairly exciting.) Granted, complicated searches won't 'just work', but the wizard will at least do a bunch of the tedious work for you.
Even though this XML search will probably load and is a good start
toward a completed search, please be aware that this search will probably
not work as is and will probably require some changes.
Library of CongressReferenceGlenn Carr
glenn at glenncarr dot com
Search the Library of Congress
The following applies if this file is included and distributed with Dave's Quick Search Deskbar:
Copyright (c) 2002 David Bau; Distributed under the terms of the GNU Public License, Version 2 (http://www.gnu.org/copyleft/gpl.txt)
This search file was initially created on 10/23/02 at 09:42:52
by Dave's Quick Search Deskbar Search Wizard version 1.0.0 ,
Copyright (c) 2002 Glenn Carr; Distributed under the terms of the GNU General Public License, Version 2
The 'parseArgs' utility method has become the convention for parsing switches for searches. If you enter some switches in the 'Switches:' field of the search wizard...
...the generated search will now include basic code for parsing the switches:
// Parse switches with parseArgs:
// parseArgs usage:
// q - string from the search function
// expectedSwitches - list or array of the expected switch values
// expandSwitches - optional parameter [default = true] used to determine
// if the switch shortcuts should be expanded (i.e. /f becomes /foo)
// Returns an object with these properties:
// q - the input string with the switches removed
// switches - array of objects with these two properties:
// name: expanded name of the matched switch (i.e. foo as in /foo:bar)
// value: value of switch (i.e. bar as in /foo:bar)
// switch_val - associative array with the switch name as the key with the switch value
// as the value. (i.e. switch_val["foo"] = "bar" as in /foo:bar)
//var args = parseArgs(q, "news, sports, business");
//if ( args.switches.length > 0 )
// switch( args.switches.name )
// case "news":
// case "sports":
// case "business":
// } //end-switch
Anyway, that's the gist of it. It still needs a lot of testing, and there is plenty of room for improvement. It's also open source like DQSD, so feel free to hack away and send in bug fixes.
October 23, 2002
David Bau for such a cool tool. Aren't the best things in life usually the simplest?
Tim Tabor for sharing his code. Probably couldn't (and for sure wouldn't) have done it without those examples.