Skip to main content

Implementation/Code

Several types of search forms are available. The examples below were updated April 19, 2018. Please refer to the SearchBlox documentation on search parameters to further customize your form or results.

Northwestern Search

This code will search all Northwestern collections:


<div class="searchblox">
	<form action="https://searchsite.northwestern.edu/searchblox/default_frontend/index.html" method="get" role="search">
	<label class="hide-label" for="q-desktop">Search web or people</label>
	<input type="text" id="q-desktop" name="query" placeholder="Search web or people"/>
	<input type="hidden" name="advanced" value="false"/>
	<input type="hidden" name="tune.field" value="size"/>
	<input type="hidden" name="t.size.factor" value="10"/>
	<input type="hidden" name="t.size.modifier" value="reciprocal"/>
	<button type="submit">Search</button>
	</form>
</div>

Search Within Site

This code will restrict (filter) results to a single site (in this example Web Communications) within Northwestern's collections:


<div class="searchblox">
	<form action="https://searchsite.northwestern.edu/searchblox/default_frontend/index.html" method="get" role="search">
	<label class="hide-label" for="q-desktop">Search this site</label>
	<input type="text" id="q-desktop" name="query" placeholder="Search this site"/>
	<input type="hidden" name="filter" value="http://www.northwestern.edu/univ-relations/webcomm"/>
	<input type="hidden" name="sitetitle" value="Web Communications"/>
	<input type="hidden" name="advanced" value="false"/>
	<input type="hidden" name="tune.field" value="size"/>
	<input type="hidden" name="t.size.factor" value="10"/>
	<input type="hidden" name="t.size.modifier" value="reciprocal"/>
	<button type="submit">Search</button>
	</form>
</div>

Please note that there is no trailing slash on the filter URL. In addition, the following Javascript must be used to escape the filter field:

<script type="text/javascript">
$(document).ready(function() {
    $(".searchblox form").submit(function(e) {
        // Encode filter field on submit
        var filterField = $(this).find("input[name='filter']");
        filterField.val(decodeURIComponent(filterField.val()));
        if (filterField.val() != undefined && filterField.val().startsWith('http') && !filterField.val().startsWith('url')) {
            // If filter doesn't have url: prefix, add it with quotation marks
            filterField.val('url:"' + filterField.val() + '*"');
        }
        filterField.val(encodeURIComponent(filterField.val()));
        return true;
    });
});
</script>

The above code can be added to an external scripts file or inline on any page using jQuery. It is also included in the department templates 2.0 scripts file.

Search Within a Collection

To request a search collection containing multiple subdomains, contact webcomm-support@northwestern.edu. Once the collection has been indexed, add its ID to your search form like so:


<div class="searchblox">
	<form action="https://searchsite.northwestern.edu/searchblox/default_frontend/index.html" method="get" role="search">
	<label class="hide-label" for="q-desktop">Search this site</label>
	<input type="text" id="q-desktop" name="query" placeholder="Search this site"/>
	<input type="hidden" name="advanced" value="false"/>
	<input type="hidden" name="col" value="19"/>
	<input type="hidden" name="sitetitle" value="Northwestern Now"/>
	<input type="hidden" name="tune.field" value="size"/>
	<input type="hidden" name="t.size.factor" value="10"/>
	<input type="hidden" name="t.size.modifier" value="reciprocal"/>
	<input type="submit">Search</button>
	</form>
</div>

The form above searches root URLs/allow paths specified in collection 19.