I'm building a complex search feature for a real estate listing site. To be able to search by a property category attributes I defined the model like this:
- Each Property has a Category. Categories are nested.
- Each Category holds a JSON specification for attributes it supports.
- Each Property has a list of attributes (as JSON field)
Here are the entities (keys, relationships, methods are omitted):
class Property(db.Model):
name = db.Column(db.String(255), nullable=False)
description = db.Column(db.Text, nullable=False)
address_line = db.Column(db.String(255), nullable=False)
price = db.Column(MoneyType, nullable=False)
attributes = db.Column(JSONB)
class Category(db.Model, BaseNestedSets):
name = db.Column(db.String(255), index=True, nullable=False)
spec = db.Column(JSONB)
override_spec = db.Column(db.BOOLEAN, default=True)
So searching by categories-attributes (without FTS) would require a user to drill down the categories tree, pick a category, provide a search input based on available textboxes, dropdowns for supported attributes.
We also have address, description, name which, I think, should be searched using FTS engine.
I know I can build a search index when creating new Property record with all necessary data and then use a faceted search (this requires some explanation).
How can I combine aspects 1-2 or 2-3 with mind? Can you explain the routine?