Use JavaScript to Enhance Database Searches in Millennium Catalogs


Sometime last year our E-Resources Librarian brought to my attention a suggestion from a patron that we enable the ability to do a keyword search of databases. In III’s Millennium “WebPAC,” by default, users can only perform a title search of databases. But users don’t always know the name of the database they need, instead preferring to enter search terms that describe their research topic.

Compounding the problem, databases often have names that don’t even come close to representing the content they hold. If nobody ever explaiend to you what JSTOR or LexisNexis or Project Muse is good for, a title search isn’t going to help you. A keyword search of their descriptions might. For example, if you want to find a database of newspapers, and you enter “newspaper” as a search term, you will get no results unless you subscribe to a database with “Newspaper” as the first word of its title. In my library, this search would return one result. But there are in fact 26 e-resource records in our system that contain the word “newspapers.” THAT list would be far more useful to researchers. So how do we get it?

If you ask III’s tech support, as I did, they’ll tell you that they can add a new index for you to enable this type of search — for a price. But to me, this seemed like such a basic functionality that we shouldn’t have to pay extra for it. So I found a workaround using JavaScript. Here’s how I did it:

Step 1:
The goal is to be able to perform a regular keyword search, but only apply it to e-resource records. The easiest way to do that is to include a like term in each e-resource record that will not appear in other types of records. That way, if we include that term in a keyword search, only e-resource records will be returned. And if we include that term along with the word “newspaper”, only e-resource records that contain “newspaper” will be returned.

We used the term “eResource” and we put it in the Resource ID field (the “p” field for us) of each e-resource record, because a keyword search will look in that field. If you don’t have the ERM and are using regular bib records, you can still do this using the same strategy, as long as the term is put into a field that will be searched by a keyword search.

Step 2:
Next, in order for this to work, we need to convert our “newspaper” search to “newspaper eResource” as the search is being submitted. I used a JavaScript function in the database search page to accomplish this. Go to the Web Master mode in the Administration module. Then, within the <head> tag of the srchhelp_y.html file, add this function:

function iiiSearchValidate(){ 
try{
if(document.getElementById(‘SEARCH’).value==null ||
document.getElement ById(‘SEARCH’).value==””){
return false;
}
}
catch(err){
}
document.getElementById(‘SEARCH’).value =
document.getElementById(‘SEARCH’.value + “ eResource”;
return true;
}

Step 3:
This is where all of the magic happens. We need to call the function in Step 2 at the moment the user submits the search. Simultaneously, we need to tell the system not to run a standard database name search, but instead switch it at the last second to a keyword search. And finally, we want to hide the alterations we’re making so that users don’t get confused. This is all accomplished by adding the following script near the end of the srchhelp_y.html file, just before the <!--botlogo--> token:

<script language=”JavaScript” type=”text/javascript”>
document.getElementById(“search”).setAttribute(“onSubmit”,
“return iiiSearchValidate()”);
document.getElementById(“search”).setAttribute(“action”,
“/search/X/”);
window.onbeforeunload = function{
document.getElementById(‘SEARCH’).value = “”;
}
</script>

Step 4:
Once these functions are in place, the database search page will successfully perform a keyword search instead of a title search. However, on the results page the term “eResource” will still appear in the search box. You may want to remove that so that users aren’t confused by the appearance of a term they didn’t enter. If so, you can do this by adding this function to the bibdisplay.js file:

function replaceText(){ 
if (document.getElementById(“searcharg”) != null){
var teststring =
document.getElementById(“searcharg”).value;
var newstring = teststring.replace(“eResource”,””);
document.getElementById(“searcharg”).setAttribute(“value”, newstring);
}
}

Then, go to the Web Options mode. Find the BODYPARAM web option and add onload=”replaceText();” to it. So, our full BODYPARAM web option looks like this:

“bgcolor=”#FFFFFF” onload=”replaceText()”

The BODYPARAM option applies to all system-generated pages, which includes the search results pages. So when the search results page loads, it will run the function that removes “eResource” from the input field.

And that’s it! Now, when we perform a database search for “newspaper,” instead of getting one database in the results, we get all 26 databases where the word “newspaper” appears. This strategy can be applied to give your users the power to keyword-search any subset of your collection without having to create a new index in your system.