Skip to main content

Implementation/Code

Several types of search forms are available. The examples below were updated February 12, 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 this website</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="filter" value="(contenttype:html OR *)"/>
	<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 website</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="advanced" value="false"/>
	<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">
// SearchBlox form prep
$(document).ready(function() {
    $(".searchblox input").each(function(i) {
        // Undo any previous encoding
        $(this).val(decodeURIComponent($(this).val()));
    });

    $(".searchblox form").submit(function(e) {
        // Encode filter field on submit
        var filterField = $(this).find("input[name='filter']");
        if (filterField.val().startsWith('http') && !filterField.val().startsWith('url')) {
            // If filter doesn't have url: prefix, add it with quotation marks
            // Second part of filter favors HTML results over other file types
            filterField.val('url:"' + filterField.val() + '*" AND (contenttype:html OR *)');
        }
        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 website</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="col" value="19"/>
	<input type="hidden" name="filter" value="(contenttype:html OR *)"/>
	<input type="submit">Search</button>
	</form>
</div>

The form above searches these three root URLs/allow paths specified in collection 19: