From af3da121b5c656486746100910e865286af79e6b Mon Sep 17 00:00:00 2001
From: michael-lewis How do I add a search box to my site
If you only have a Basic listing, or don't want to use the API, a simple alternative is to - have a form which takes a query and appends "+domain:<domain> " to the query string (q parameter) and - sends to https://searchmysite.net/search/ . The plus before the domain is to - ensure that term is mandatory, i.e. that all results must come from that domain, and the space after the actual domain is to separate - that term from any other query terms. For example, the form could take "antarctica book" and - redirect to https://searchmysite.net/search/?q=%2Bdomain%3Amichael-lewis.com+antarctica+book - (noting that the + before domain is URL encoded as %2B and the space after the actual domain is encoded in this case as a +). - A simple form to do this could look like: + have a form which takes a query and a domain hidden parameter containing the value of + the domain to which to want to restrict results, e.g. (for michael-lewis.com):
-<script>
- window.onload = function() {
- document.getElementById('searchForm').onsubmit = function() {
- var searchQuery = document.getElementById('searchQuery');
- searchQuery.value = "+domain:michael-lewis.com " + searchQuery.value;
- };
- };
-</script>
-<form id="searchForm" action="https://searchmysite.net/search/">
- <input id="searchQuery" type="search" name="q" ></input>
+<form action="https://searchmysite.net/search/">
+ <input type="search" name="q" ></input>
+ <input type="hidden" name="domain" value="michael-lewis.com"></input>
<input type="submit" value="Search"></input>
</form>