Saturday, September 25, 2004
Implementing a focussed Google search facility
Ever since my my last blog entry on implementing a search facility I've been wondering whether I can come up with something better. The main problem with the solution I arrived at was that the JavaScript adds extra search terms to the input text field itself, which means that if the user begins to type in a string beginning with the same few characters the browser (or at least my browser) tries to be helpful and fills in what it thinks could be what the user intends to type - which includes the added terms. (It took me a few days to discover this.)
After several hours of experimentation yesterday and today I've finally arrived at this solution for the StudentWeb search facility...
|
|
This avoids the problem I referred to above, it's compact, and it's pretty flexible/generic.
I first tried constructing a custom LSBU search facility similar to the main LSBU search page (all it needs is an extra hidden "domains=lsbu.ac.uk" assignment), but I decided that I prefer pure Google search results pages rather than customised LSBU search results pages. There are so many decisions in web design that just boil down to a question of personal taste!
It took me ages to arrive at this solution. I had many more complicated versions along the way, building on the "getSelectedRadio" function from this web page.
Once I had it working I found that I could simplify it considerably, and the resulting JavaScript code is now very straightforward. It's satisfying, but I also feel a bit frustrated that there's no evidence of all the hours expended!
Note (added 20/9/04)
I've just realised that I could have created a BCIM-specific search by adding an "inurl:" ("inurl:lsbu.ac.uk/bcim") instead of simply adding "www.lsbu.ac.uk bcim".
Note (added 5/1/05)
I've just come across Google's Advanced Search Operators page and discovered various other operators that might be useful in addition to inurl:, such as...
site:intitle:allintitle:allinurl: