Multisite results in single site

Hi there, I am using the instantsearch in a website of a client, but I have an issue I’m not quite able to solve myself:

Site info:
The site uses woocommerce to sell products.
The site is a multisite.

The plugin that connects the algolia app is only enabled on one of the 2 sites. But when I use the search function on either the app or on my website, I get results of both webshops. For example:
When I search for “Spiegel Wiesbaden Novi geborsteld messing” 2 results show up, one of either sites.

Is there any way to exclude these products from the instantsearch?

@lamper-design welcome to the community!

If you are unable to split the sites up into their own index (this is the recommended way), you’ll want to apply a filter to the search operation. Are you using the ‘WP Search with Algolia’ plugin? You should be able to more information here in their documentation (note - we don’t officially support this plugin but still happy to help).

The filter should pick up on an attribute that differentiates between the sites, for example:

Example record:

{
  ...
  "site": "site_a"
}

Example filter:

{
  filters: "NOT site:site_b"
}

Happy to help further, let us know! Thanks!

Chiming in as one of the support engineers helping to maintain and support the “WP Search with Algolia” plugin.

Each site in the multisite definitely should get their own index, and there’s ways to prefix the index created for each site in the network, via UI settings.

That said, including attributes related to the site a piece of content comes from is also a viable solution, as Michael King mentions.

Side note as I’m trying to monitor Discourse here for requests with the plugin, our public support forum over at [WP Search with Algolia] Support | WordPress.org is also actively monitored by me, in cases where someone may want more targeted support.

2 Likes

Hi guys, sorry for the delay on my reply, things got busy over here…

I understand that every site should have an index on its own, however I thought I already did that, and I can’t find a way to check this. Can you guys tell me how?

Secondly, There is no attribute that differentiates the two products, the only thing different is the permalink, and I haven’t found a way to filter on this either…

For the index issue, I think the prefix may be your issue as @tw2113 mentioned. Are both sites using the same prefix? Correcting this issue makes implementing the attribute not needed.

Regarding the attribute, your best bet would be to transform the data before it goes into the index, as there is not a filter option for a CONTAINS or some similar query.

For example, if the record looks like so:

{
  ...
  "permalink": "https://www.my-site-a.com/products/1512"
}

You could extract the domain from the URL (using a regular expression or your method of choice) and save this as an attribute for the record. Then you could use this attribute to filter the record. You’ll want to set this facet up as ‘filter-only’ since it won’t really be used otherwise.

{
  ...
  "permalink": "https://www.my-site-a.com/products/1512",
  "domain": "my-site-a.com"
}

But, as I mentioned above, let’s double-check your settings on both sites as correcting them sharing the same index is the easiest fix and is probably better long term (for recommendations and our other advanced features)

As mentioned in the original question, only one of my sites is using the algolia plugin. But it still shows products from the other site.

So, no, the sites are not using the same prefix. Back to trying with the attributes then.

The code that you show, I’ve never seen this before, I can set up the plugin with an API key, and configure settings in the algolia app. Where in the app can I change the records for this?