I’m a backend developer trying to use Algolia for the client’s needs and I’m having a bit of trouble adapting to this indexing logic.
Database (Mongo) for the backend app has entities like Venue (a place and information about the location) and Market (a more abstract entity with information about schedule, and vendors present there).
which are interconnected with a foreign key. For example Market documents have field venueId which states what is the venue this market is currently at.
Currently, I think my indexing of these documents (sending these data to Algolia) is going to happen upon their creation and editing, meaning Algolia will have a truthful ‘copy’ of these two collections.
With this setup, I will have two indexes (market_index and venue_index) and my instant search (on frontend) can successfully (at least I think) lookup on:
A) markets named N (this is because Market has title field)
B) venues named N (this is because Venue has title field)
C) venues near location L (this is because Venue has _geoloc field)
but my question is: can it also lookup on:
D) markets near location L
With the above setup, i don’t think so? So as i thought about this, two options emerged:
- Change the database models to have all necessary information for the algolia search engine, meaning add _geoloc field to the Market field. A duplicate of information - yes, for the sake of Market index and searching for “markets near location L”
- Change the database models to not use foreign keys but nested documents, meaning convert Market’s venueId (type ObjectId) into venue (type Object) and thus allow (i guess?) “markets near location L” because _geoloc is also nested inside Market object.
- Change what is indexed, meaning that i don’t send copy of the database-like structure, but rather a structure from either point 1) and 2) just so that algolia can do these searches, and that i keep data as it is right now in the database
- Some other approach?
Points 1) and 2) are troublesome to me since they require me to drastically change how the database is interconnected just to adapt to some service like Algolia. Yes - the app is primarily for searching places - but should third party service really require database adapted just to it?
Point 3) is troublesome because I just don’t have the knowledge/information whether something like this should be done, and in what shape or form? Without examples i couldn’t figure out if my indexes should be some kind of aggregation based on some parameter, or should they be like collections in Mongo?
If someone could clarify this I am happy to give more concrete examples on the actual models, the app is not just Market and Venues but also Organizers and Brands/Vendors, so these questions are just problem-describing, not all picture just for sake of giving you enough information for me to form a question.