2023-05-30 –, Music Hall
What do you do when faceted search over your data isn’t enough? I’ll demonstrate how to build a powerful search tool over limitlessly related models and their fields.
Video: https://youtu.be/Ye3XfWbCbPE
Full text search and faceted search will get you a long way for most use cases: when your data is largely free text or when you don’t have complex data structures, these will usually be enough.
But what do we do as our datasets get larger, the relations between our tables more complex and when we want to combine text search with filters based on dates, categories or numbers?
To begin, we'll define a simple JSON-based DSL for representing a query and introduce some terminology and structure that will help us along the way.
We’ll express how our models connect to one another and how to search over those relations. We’ll then define which fields should be searchable and write generalisable logic to handle input data for different model fields.
We’ll put it all together into a recursive algorithm which can build a queryset from any valid query represented in our DSL.
But where could we take this next? I’ll outline the simplifications we've made, the performance limitations of this approach and what else lies beyond.
This will largely be an outline of the concepts rather than an in-depth guide to how you can build such a tool. We’ll get into some technical detail building up from the ORM primitives like Q and F objects but we’ll largely avoid getting our hands dirty with the internals of the Django ORM.
You’ll come out of this with a better understanding of how to utilise the flexibility of the Django ORM to build search tools that your users will love.
Head of Product Engineering at Beauhurst, a data platform of the high-growth companies, accelerators and funds in the UK.