The purpose of this exercise is to demonstrate how URL query strings can be used to create search widgets that can be embedded in websites.
The basic premise of this exercise is that you can create customized searches by manipulating the URL of the hyperlink you are sending your viewer to. Our project will be to create a search plug-in for our users so that they can easily find Creative Commons images on Flickr.
First, let's look at what happens with the URL when you conduct a search. Using the concepts we will discover in this section, we will then create a custom search box in Part B that will allow us to direct our users to a list of results on Flickr based on the terms they entered in a search box on our site.
The basic pieces are simple enough, and once we put them all together we will have created a nice little search plug-in.
If you do a search in Flickr for 'Schipperke puppy photos' and then filter your results to
Creative Commons images only, you will get this URL:
https://www.flickr.com/search/?text=Schipperke%20puppy%20photos&sort=relevance&license=1%2C2%2C3%2C4%2C5%2C6
Can you spot the following query string in the full URL above?
Schipperke%20puppy%20photos
%20.]This means that we can substitute other terms and insert them into the URL to create an address that will take us to a search for those terms.
To search for 'baby pandas' we can use the query string:
baby%20pandas
And plug that into the URL above in place of the 'puppies' query string like so:
https://www.flickr.com/search/?text=baby%20pandas&sort=relevance&license=1%2C2%2C3%2C4%2C5%2C6
If we want to create a similar link to look up items in our library catalog, all we need to do
is figure out where the query string comes into play by doing a search in the catalog.
In the HSU Library
Articles+ database, a search for 'baby pandas' would give us this URL:
http://library.calstate.edu/humboldt/articles/results?query=baby+pandas
+ symbol instead of
the %20 encoding that was used in Flickr. These two can usually
be used interchangably and the browser will figure out how to get to the URL, but it is still
something to pay attention to.]This means that we can throw any terms at the end of this URL- the only trick is getting the terms we want and generating the custom URL. There are a few ways that we could use this on an actual site:
Here is an example of the third option, using the title of this exercise as the placeholder text. Test it out for yourself:
Before moving on to Part B, take some time to think about the various ways we can use these query strings. Try out your own searches and see if you can figure out how to manipulate the URL query strings to make your own searches.
After you have examined the query strings in some other URLs, move on to Part B to learn how we can use these basic principles to create a custom search box to embed anywhere on the Web. In Part B we will learn how to use JavaScript, HTML & CSS to create our own search box.
Move on to part B