Gianna Giavelli
Gianna Giavelli

Reputation: 1

SOLR how to manage combined company data in single docbase

I am developing a Saas and I was wondering if there was a way I could store say 5 companies documents (say 1000 docs each) in a unified docbase using a field (companyId) and then adding that to my query.

I believe this cannot work because it will not force that one field to match perfectly.

so are there any other strategies people have to do this? It might be a bit costly to spool up a full SOLR instance for each customer as we many have many small trial customers.

Upvotes: 0

Views: 30

Answers (1)

MatsLindh
MatsLindh

Reputation: 52892

Keeping multiple customers in a single collection will work fine, as long as you make sure you're keeping, and sending, in a companyId each time. The companyId field would be an indexed string field (so that it's not analyzed in any way) and can be used for only exact matches. You'd then use a filter query (fq) to limit the result set to only documents that match this term:

&fq=companyId:123

To make this approach more secure (i.e. so that you don't end up in a situation where you forget to include a companyId filter query), you can set a default value that doesn't match any documents in your request handler.

<lst name="defaults">
  <str name="fq">companyId:0</str>
</lst>

There is a few downsides with keeping everything in a single collection / core, and that is scoring for documents for a single customer will be affected by what the other customers have indexed. Since the number of terms present will be across the entire collection, this might give slightly weird results for terms that isn't common with one customer, but very common with another customer.

The alternative is to create a separate collection for each customer (saas_123) - since you use a configSet when creating the collection, the configuration will be shared for all the customers. You can then also use Solr's built-in authentication and authorization to have user accounts that can only access a single collection (and store this user information together with the user in your main application). This will add an additional level of security.

I'd recommend extending the Solr client (or creating your own API internally instead of using the Solr client directly) to make sure you're setting everything up as expected (with a required companyId for example).

Upvotes: 2

Related Questions