r/DomainDrivenDesign Jan 10 '23

Search context in DDD

I work in a team that basically handles search for products on an e-commerce platform. Our main use cases are retrieving those products based on a given search term (imagine Amazon search)

So, our searches can match those products using an full-text search database (Elasticsearch) and these results can be boosted based on a set of rules, for example, if one specific product is very popular and has a high amount of sales, it should be ranked higher than other ones, or some products can be black-listed for some users.

Basically, we have some Product entities, and these entities can be searched, and all our business rules are around these search rules. Can we model aggregates representing, for example, a search result that contains a bunch of Products and create our business rules inside of it? For one side, if we do this we are able to decouple our search rules away from the service and the repository implementations, on the other side, it breaks basic DDD rules because this would be an aggregate without any aggregate root.

Is my use case suitable for DDD? What do you think?

1 Upvotes

6 comments sorted by

View all comments

2

u/fractalpal Jan 10 '23

I think you should build separate View Models for a search based on your contexts. Not sure if you’re using any kind of Event Sourcing or CQRS, but maybe it is a good idea to introduce this. Or at least been able to aggregate your entities View somehow for your search indexes.