Our app manages books owned by a user with a book containing multiple documents (pdfs, word docs etc). The home page lists all the books for a user with a button for paging that loads the next 10 books. Then when a user clicks on a book it opens in a new screen and lists all the documents for that book.
Up until now we were using WCF / entity framework to retrieve all books shown on the home page, then azure search (connected to a sql view) to get the documents for one book when it was opened, which worked well with paging and sorting.
Now though we also want to get the list of all books for a user from azure search so we created a new table to hold the book and document data, one row per document meaning the parent book name and book id is repeated for each row.
Our azure search index now points to this table and I have to figure out how to retrieve the books for a user with paging and possibly sorting also. The problem is that I need a distinct select for the books but azure search doesn't do distinct and I don't know how many documents a book might have, so I can't set the Top parameter to 10. A book could have 30 or 40 documents which means the first 40 rows for example could be just for one book.
I tried to use a facet on the book id which kind of works and gives me the id and count of documents for each book, but I can't seem to specify a sort order for the facet - the order is different to the order I set for the query (BookId). I also don't know how to get all the books using a facet - I can set a count property on the facet but I don't know how many books a user will have.
Our architect says I should get all rows (which could be thousands) and filter them in the C# code to get 10 books. This seems pretty inefficient to me though and doesn't feel right.
So I'm not sure if this is the right approach..
- should I have separate azure search indices for book and document data (that use separate tables?
- how do I return the top n books from this table without knowing how many documents each book has?
- can I specify a sort order for facets using the C# sdk? (I think it's possible via the rest API)
- how do I get a facet to return all books for a user?