How can I boost results in relation to the source domain?

I’ve created an engine from 3 domains, and I offer a search box on each domain/site. I’d like users to be able to find content from each of the domains, but I want to give preference to the site they’re currently visiting.

More specifically: if I’m searching on my docs site, I’d like the top 5 results to come from the docs site, and then after that I’m ok with a mix of results from all three sites (docs, blog, www).

Controlling domain based relevancy is a two-step process. The first step is to include domain information in your indexed documents using Swiftype meta tags. For each domain, you’ll want to include a numeric value representing the current domain. Say for example you have three domains, one.com, two.com and three.com. For pages on two.com include the following meta tags:

<meta class="swiftype" name="onecom" data-type="integer" content="1" />
<meta class="swiftype" name="twocom" data-type="integer" content="2" />
<meta class="swiftype" name="threecom" data-type="integer" content="1" />

For each of the other domains, change the content attribute from 1 to 2 to match the domains.

After adding the meta tags, request a recrawl from the Swiftype dashboard.

Once you have the domain fields indexed, you can control relevancy at query time using the functional boosts feature. When on the two.com domain, the query syntax will be something like:

curl -XGET 'https://api.swiftype.com/api/v1/engines/bookstore/document_types/books/search.json' \
  -H 'Content-Type: application/json' \
  -d '{
        "auth_token": "YOUR_API_KEY",
        "q":"my search",
        "functional_boosts":{
          "page":{
            "twocom":"exponential"
          }
        }
      }'

This structure of this query says that the user is on the two.com domain, therefore apply a logarithmic boost to the twocom field. The twocom field will be indexed as 1 for the domain two.com and 0 for all others.

When on the three.com domain, the query syntax will change to apply a functional boost to the threecom field ("threecom":"logarithmic").