Configuring Custom Encore Search Tools

You can configure custom Encore searches for your website in the following ways:

JavaScript Form Validation

As a best practice, Innovative recommends adding JavaScript validation to your search box to make search term a required field that prompts the user to enter a term if left blank.

Many good resources for setting up JavaScript validation are available on the Web, such as the W3schools page located at http://www.w3schools.com/js/js_form_validation.asp.

Add an Encore Passthrough Search Box

To add an Encore passthrough search box, include the following code on an appropriate web page.

The modified example script requires the following:

  • The onsubmit form tag attribute must be formatted as follows:
    onsubmit="return searchEncore()"
  • The search input requires a unique ID. In the example, the default ID is "encoreSearchInput". If you change this value, you must match the changed value with the formSearchInputID variable value.
  • A hidden input using id="encoreBase" and a value that is the URL of your Encore server up to the /search path. For example:
    <input type="hidden" id="encoreBase" value="http://encore.mylibrary.com/iii/encore/search/"/>

When customizing the script for your use, substitute the following values with your system settings:

Value Description
<ENCORE_FQDN> The fully-qualified domain name for your Encore server. This value is required.
<Scope_#> The facet number.
<Scope Label> The facet label.
<Language_Code> The language code. For example, spi or frc.

 

<script type="text/javascript">
   function searchEncore(){
        var encoreBaseURLInput,encoreBaseURL, searchInput, scopeInput, searchString, scopeString, locationHref, charRegExString, base64Regex;
       /*base64_encoding_map includes special characters that need to be
        encoded using base64 - these chars are "=","/", "\", "?"
        character : base64 encoded */
        var base64_encoding_map = {"=":"PQ==", "/": "Lw==", "\\":"XA==", "?":"Pw=="};

        var escapeRegExp = function(string) {
            return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
        }
       encoreBaseURLInput = document.getElementById("encoreBase");
       searchInput = document.getElementById("encoreSearchInput");

        if (searchInput && encoreBaseURLInput) {
            encoreBaseURL = encoreBaseURLInput.value;
            searchString = searchInput.value;
            for(var specialChar in base64_encoding_map) {
                charRegExString = escapeRegExp(specialChar);
                base64Regex = new RegExp(charRegExString, "g");
                searchString = searchString.replace(base64Regex, base64_encoding_map[specialChar])
            }
            searchString = encodeURIComponent(searchString);

            scopeInput = document.getElementById('encoreSearchLocation');

            if (scopeInput) {
                scopeString = scopeInput.value;
            }

            if (scopeString) {
                scopeString = encodeURIComponent(scopeString);
                locationHref = encoreBaseURL + "C__S" + searchString + scopeString +  "__Orightresult__U";
            } else {
                locationHref = encoreBaseURL + "C__S" + searchString + "__Orightresult__U";
            }
			
			languageSetting = document.getElementById("encoreLanguage");
			
			if (languageSetting) {
				locationHref = locationHref + "?lang=" + languageSetting.value;
			}
			
            window.location.href = locationHref;
        }
        return false;
    }
</script>

<form action="?" onsubmit="return searchEncore()">
    
	<!-- REQUIRED with id="encoreSearchInput" -->
    <input id="encoreSearchInput" type="text"/>

    <!-- REQUIRED INPUT with id="encoreBase": <ENCORE_FQDN> fully qualified domain name such as "encore.mylibrary.com" -->
    <input type="hidden" id="encoreBase" value="http://<ENCORE_FQDN>/iii/encore/search/" />

    <!-- OPTIONAL search location hidden field to limit to a predefined scope -->
    <!-- <input type="hidden" id="encoreSearchLocation" value="__Lf:facetcollections:<Scope_#>:<Scope_#>:<Scope Label>::" /> -->
	
	<!-- OPTIONAL non-english language setting: <Language_Code> is code such as "spi" for spanish -->
	<!-- <input type="hidden" id="encoreLanguage" value="<Language_Code>" /> -->
    

    <input type="submit" value="SUBMIT" />
</form> 

Add a Pre-scoped Encore Search Box

You can add a pre-scoped Encore search box to any page by using JavaScript with the HTML pass-through form for Encore.

  1. Reference Javascripts in the header.
  2. Add the encorelocationfacet.js file to your HTML directory.

  3. Add the search box to your web page.

Reference Javascripts

Reference the following Javascript in the <head> element of your web page:

<script type="text/Javascript" src="/screens/encorelocationfacet.js">
//script to refine encore search results to a collection
</script>

Add the encorelocationfacet.js File

Using a text editor of your choice, create a file called encorelocationfacet.js and include the following to the file:

function gosearch() {
var searchstring = document.getElementById('target').value + document.getElementById('searchlocation').value;
var searchsite = document.getElementById('encorebase').value;
var searchurl = searchsite + searchstring;

window.location.href = searchurl;
}

function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
{
gosearch();
return false;
}
else
return true;
}

Upload the encorelocationfacet.js file to your http/screens directory.

Add the Search Box

Add the Encore passthrough search box to your web page:

<!-- start search box -->
<fieldset>
<div style="display:none;">
<input type="hidden" name="encorebase" id="encorebase" value="http:// <ENCORE_FQDN>/iii/encore/search/C|S"/>
<input type="hidden" name="searchlocation" id="searchlocation" value="|Lf:facetcollections:<Scope_#>:<Scope_#>:<Scope Label>::|Orightresult?lang=eng&suite=def" /></div>
<div id="search_box">
<input type="text" name="target" value="" id="target" onKeyPress="return submitenter(this,event)"/>
<input type="image" src="/screens/submit.gif" width="22" height="22" id="go" onclick="gosearch();"/>
</div>
</fieldset>
<!-- end search box -->

Customize the sections in blue text for:

Element Description
<ENCORE_FQDN> The fully-qualified domain name for your Encore server.
<Scope_#> The facet number
<Scope Label> The facet label

A quick way to find the facet number and label is to run any search in Encore, refine the desired facet, and read the values from the URL of your test search, ignoring any instances of the escape characters (%3A).

Note that the scope number Encore uses does not match what you see in the Scope Menu in Sierra or Millennium.

For example, using the following URL:

http://encorelib.cat.edu//iii/encore/search/C__SSearchterm__Ff%3Afacetcollections%3A8%3A8%3AE-books%3A%3A__Orightresult?lang=eng&suite=cobalt

Your search box input values for the facet number and facet label are:

<input type="hidden" name="searchlocation" id="searchlocation" value="|Lf:facetcollections:8:8:E-books|Orightresult?lang=eng&suite=def" />

Modifying the Search Box to Limit by Facets

You can optionally modify your search box to offer a modifiable facet limit. Edit the following line:

|Lf:facetcollections:<Scope_#>:<Scope_#>:<Scope Label>::|

Change to:

|Ff:facetfields:title:title:Title::|

Changing the Lf value to Ff enables users to remove facet limits. The facetfields value limits the search to results with the search term is found in the title.

To limit to a material type, edit the following line:

|Lf:facetcollections:<Scope_#>:<Scope_#>:<Scope Label>::|

Change to:

|Ff:facetmediatype:a:a:Book::|

For other material types, replace both a: codes with the appropriate material type. Replace the Book label with the label your library uses.

Construct Stable URLs

Use the following syntax to construct stable URLs:

Passing a Search Term to Encore

To pass a search term to Encore, use the following syntax:

http://[encore server domain]/iii/encore/search/C__S[search term]__Orightresult

  • Replace [encore server domain] with the fully-qualified domain name of your Encore server.
  • Replace [search term] with your search term (for example, art%20history where %20 is encoding for a space).

Linking Directly to a Record in Encore

To link directly to a record in Encore, use the following syntax:

http://[encore server domain]/iii/encore/record/C__R[record number]

  • Replace [encore server domain] with the fully-qualified domain name of your Encore server.
  • Replace [record number] with the record number, starting with the record type indicator (for example, b1401495 for a bibliographic record, e1001265 for a resource record).
    Do not include the record number check digit or a check-digit wildcard ("a") as part of the record number in your URL. For example, enter b1209907 in the stable URL for bibliographic record b12099077, excluding the ending 7 check digit.