I'm trying find out if there's performant way to search through my current data structures, or if I have to restructure them.
I have the following structure for my indices:
- Publication (attributes:
id
,title
,keywords
) - PublicationFile (attributes:
id
,publication_id
,text
,page_number
)
A publication has many publication files, publication file contains the contents of the file and the page it was found in (text
and page_number
).
title
, keywords
, and text
are the searchable attributes, so if someone searches for 'economy' I want to search through both my indices.
I would like to perform a search that searches through both indices and returns the results in a manner that allows me to do something like this:
Publication1
keyword1 keyword2
Found results in Publication1's file contents in: [file a (pages: 1, 2, 3), file b (pages: 5)]
So I kind of want the search that happens to return results grouped by a publication's ID. The only way I can think of right now is to search both indices and then loop through the results and link the file/page matches to a publication.
In summary my questions are:
- Is there a way I can structure my data to avoid the nested loops to process it?
- Is there a way I can do this through Algolia without having to modify my structure? I would ideally want to re-use Algolia's frontend searching code and avoid processing this data on my backend.