This example shows how to implement a search box that will either give you autocomplete
suggestions and redirect to the searchpage, or just redirect to the searchpage.
If you haven't included loop54-js-lib already, include this part and configure it to talk to your loop54 proxy
<script type="text/javascript" src="loop54-js-lib.js"></script>
<script type="text/javascript">
Loop54.setConfig({url: "https://helloworld.54proxy.se"}); // you will get this config from us when we have set up an engine
</script>
Then include the following function in a separate javascript file or last in your HTML body tag
<script type="text/javascript">
var redirectSearch = function(event, query, facet) {
var searchPageLocation = "http://d.loop54.com/"; // Change this to the URL or path of your searchpage. I.E. ("/search")
if(document.location.pathname === searchPageLocation) { return; } // Prevent redirect if you are on the searchpage already
if(event) {
event.preventDefault();
query = document.forms[event.target.id].search.value;
}
if(query.length > 1) {
/*
* This defines how you want a query to be formatted before sending,
* we are using hash (#) by default but feel free to change it to questionmark (?) if that's what you prefer.
*/
var redirectString = searchPageLocation + "#query=" + query;
// This also adds a facet if that was choosen in autocomplete
if(facet) { redirectString = redirectString + "&f=" + facet };
document.location = redirectString; // Changing document.location will redirect the browser to the new location
}
}
</script>
Then choose which version of the searchbox you want to use, with or without autocomplete.