Make it harder to break
Display banner ads
Add refined search capabilities
Develop cluster sets
OK. I already did that, but admit it: I had you going. Actually,
you’ll find the modified version in /ch01/js1.0/. Open
index.html in your browser
just like you did with the original. In this section, we’ll
browsers. There are three changes:
No array sorting (with the
A workaround for the
NN 2.x and MSIE 3.x do not support
files. The workaround for this is to embed the profiles array in
nav.html. The second change eliminates the call
resultSet.sort() in line 90. That means your
results will not be sorted in dictionary order, but by the way you
have them chronologically listed in profiles.
The last change is eliminating the
care of that, but it degrades performance.
That’s what my economics professor wrote on the chalkboard my freshman year at Florida State University. The translated acronym: Thar’ Ain’t No Such Thang As A Free Lunch. In other words, these changes give you older browser version compatibility, but cost you in functionality and code management.
Without support for
.js files, you have to dump
that profiles array into your
will be quite unsightly and more unmanageable if you want to include
those records in other searches.
sort() method, while not critical to the
operation, is a great feature. People might have to view all subsets
of matched records because the records are in no particular order. Of
course, you could place the results in the array alphabetically, but
that’s no picnic either. Or you write your own sort method for
split() method is arguably the
workaround, so it really isn’t an issue.
As it stands, you can pass the pipe character as part of the search query. Why not add the functionality to remove any characters from the query used as the string delimiters? That makes the app harder to break.
How? Try this. Suppose you want to randomly display five banner ads (no particular order in this case). If you have several ad image URLs in an array, you could pick one to load at random. Here’s the array.
var adImages = new Array("pcAd.gif", "modemAd.gif", "webDevAd.gif");
Then you might randomly display one on the results page like so:
document.writeln('<IMG SRC=' + ads[Math.floor(Math.random(ads.length))] + '>');
Consider displaying a set of checkboxes under the text field in
nav.html.Maybe like this:
<INPUT TYPE=CHECKBOX NAME="group" VALUE="97">1997 Records<BR> <INPUT TYPE=CHECKBOX NAME="group" VALUE="98">1998 Records<BR> <INPUT TYPE=CHECKBOX NAME="group" VALUE="99">1999 Records<BR>
Use this checkbox group to determine which arrays to search, in this case profiles97, profiles98, or profiles99.
There are many things you can add to increase the user’s ability to refine searches. One easy one is to offer case-sensitive and case-insensitive queries. As it stands now, case does not matter, but you can change that by adding a checkbox allowing either style.
Record must contain both terms on the left and right of AND.
Record can contain either of the terms on the left and right of OR.
Record must not contain the term(s) to the right of NOT.
Record must contain this and only this record.
Record can contain term(s) spelled like or sounding like.
This takes some work (especially LIKE ), but users would be quite amazed at your wizardry.
Another popular and useful technique is to establish cluster sets. Cluster sets are predefined word groups that automatically return predefined results. For example, if a user includes the term “mutual funds” anywhere in the query string, you could automatically generate results containing records featuring your company’s financial products. This technique takes a bit more planning, but it would be a great feature in a search application.