Multiple Domains Guide
"How can I search across multiple domains?"
"How can I prioritize search results by domain?
"How can I filter by domain?"
This guide will demonstrate how to set-up Site Search with multiple domains.
Multiple domains are available within Pro and Premium plans.
You might have content located within various subdomains...
- blog.example.com
- community.example.com
- store.example.com
Or you might have several different domains:
- example.com
- anotherexample.com
- athirdexample.com
With all your content spread around, what if you want a centralized search experience?
One search experience to rule them all, so to speak!
Read on to learn more:
Adding Multiple Domains
But first: how to add a second domain.
During signup, you add your first domain.
After that, adding a second one can be done in two ways...
Adding a domain: Dashboard
Login to the Site Search dashboard.
Locate the Domains option within the left hand menu.
Click into it, and note the ADD A DOMAIN button in the top right:
You will then be prompted to add your domain.
Add it, like so, addressing any errors that may appear:
Adding a domain will initiate a crawl; its pages will be indexed.
Adding a domain: API
You can also use the API to add a domain.
Send in your auth_token
along with a domain object containing the new URL:
curl -X POST 'https://api.swiftype.com/api/v1/engines/[ENGINE_NAME]/domains.json' \
-H 'Content-Type: application/json' \
-d '{
"auth_token": "YOUR_API_KEY",
"domain": {"url": "https://seconddomain.com"}
}'
That's it!
A crawl will then take place to index the domain's pages.
Organize & Search
If we stopped here, we'd have one Engine containing all of our domains' documents.
They are in different sites, but they exist "as one" within your Site Search Engine.
But what about many domains?
And how can we search them all in an organized manner?
Filtering Results By Domain
The answer lies within meta tags.
A meta tag creates a new field within your documents.
Consider we have three domains:
- example1.com
- example2.com
- example3.com
Within each domain, we would place a meta tag unique to that domain.
A recommended pattern is to create an integer tag called domain-identifier
.
You would use this new field to filter by domain.
The content of each tag should be a simple number between 1
and n
, where n
is the total number of domains.
eg. example1.com's pages would have this tag within all pages:
<meta class="swiftype" name="domain-identifier" data-type="integer" content="1" />
example2.com's pages would have this tag within all pages:
<meta class="swiftype" name="domain-identifier" data-type="integer" content="2" />
And so on!
You can then apply a filter on the domain-identifier
field values:
curl -XGET 'https://search-api.swiftype.com/api/v1/public/engines/search.json' \
-H 'Content-Type: application/json' \
-d '{
"engine_key": "YOUR_ENGINE_KEY",
"q": "example query",
"filters":{
"page":{
"domain-identifier": "1"
}
}
}'
Prioritizing Search Results By Domain
A great pattern to use involves a site-priority
meta tag.
You would use this to get results from one domain first.
<meta class="swiftype" name="site-priority" data-type="integer" content="5" />
If you had one high priority domain, and many lower priority domains...
eg. example1.com is high priority:
<meta class="swiftype" name="site-priority" data-type="integer" content="2" />
example2.com, example3.com, example4.com are low priority:
<meta class="swiftype" name="site-priority" data-type="integer" content="1" />
You can apply a boost to determine domain order.
The following would multiply the relevance score of each document by the site-priority
value:
curl -XGET 'https://search-api.swiftype.com/api/v1/public/engines/search.json' \
-H 'Content-Type: application/json' \
-d '{
"engine_key": "YOUR_ENGINE_KEY",
"q": "example query",
"functional_boosts":{
"page":{
"site-priority": "linear"
}
}
}'
Documents within example1.com would be considered twice as valuable, appearing first.
After adding the site-priority meta tags to the relevant pages and triggering a new engine crawl, add the newly introduced field to your engine's Weights in order to use the site-priority values for result scoring.
Site Search is an excellent solution for searching over multiple domains.
With the knowledge of these two patterns, you can search across multiple domains however you wish.
Stuck? Looking for help? Contact support or check out the Site Search community forum!