Azure search returns parent and child records

Our application manages user-owned books with a book containing multiple documents (pdfs, word docs, etc.). The main page lists all the books for the user with a swap button that downloads the next 10 books. Then when the user clicks on a book, it opens in a new screen and lists all documents for that book.

So far we have used WCF / entity framework to fetch all the books shown on the home page, then azure search (connected to sql view) to get documents for one book when it was opened, which worked well with paging and sorting.

Now, while we also want to list all the books for the user from the azure search so that we create a new table to store the book and document data, one row per document means that the parent book name and book ID are repeated for each row.

AzureSearchTable

Our azure search index is now pointing to this table and I have to figure out how to get the books for the user with a search call and possibly sorting. The problem is that I need a separate selection for the books, but the azure search makes no distinction and I don't know how many documents a book can have, so I cannot set the Top parameter to 10. A book can have 30 or 40 documents, which means that the first 40 lines, for example, can only be for one book.

I tried to use a facet on the book id, which works and gives me the id and number of documents for each book, but I cannot specify the sort order for the facet - the order is different from the order given for the request (BookId). I also don't know how to get all the books using a facet - I can set the count property to a facet, but I don't know how many books the user will have.

Our architect says that I have to get all the lines (which could be thousands) and filter them in C # code to get 10 books. This seems ineffective to me, although it doesn't feel right.

So I'm not sure if this is the correct approach.

  • Should I have separate azure leaf search indexes for book and document data (which use separate tables?
  • How to return the top Russian books from this table without knowing how many documents each book has?
  • Is it possible to specify the sort order for facets using c # sdk? (I think this is possible via the rest API)
  • How do I get a facet to return all books for the user?
+3


source to share


1 answer


Here are some thoughts:

Answer # 1:

If you intend to return a list of books based on DocumentName lookups, you probably want to keep them in the same index. Your architect's idea of ​​how to handle results in C # might not be as bad as you think. You can do GroupBy in LINQ. Azure search is fast as well as LINQ queries. Especially if the machine issuing the Azure search request is an Azure Web Application Server and is in the same region (communication within the datacenter). I've even used this approach with the Suggestion API for an autocomplete feature that should return results quickly (within a few hundred milliseconds) as the user types. I would say that it is at least worth trying to see what performance you get with maximum and typical datasets.

But if that doesn't work for you, consider restructuring your index schema so that DocumentName is of type Collection (Edm.String). It will look something like this:

{
    id: 20663,
    userId: 1,
    bookId: 2144,
    bookName: "ber",
    documentName: ["asdasd", "_318-1991.jpg", "wallhaven-13081.png", etc...],
    documentCount: 7
}

      

Now, if you need to allow the user to get detailed information about the documents of a particular book they select, you can simply do so with a database call to get the book information. Alternatively, here you can create another Azure Search Index for Documents with more detailed document information. But at this point in the user's workflow, unless you're going to provide another full-text search across the documents of this particular book, you probably just want to stick with the DB-type invocation type. / P>

Answer on pool # 2:

For the number of documents, you can simply create another field (as shown above) and sort / filter / facet.



Answer # 3:

Neither the SDK nor the Azure Search REST API provides a way to arrange faces, but keep in mind that you end up with full control over how you want to display facet information in the UI. If the SDK doesn't provide what you need, you can create a simple search class in your application to order your edges however you like. Something like that:

public class FacetDefinition
{
    public string FacetName { get; set; }
    public int FacetOrder { get; set; }
}

...

var myFacetDefinitions = new List<FacetDefinition>();
myFacetDefinitions.Add(new FacetDefinition() { FacetName = "SomeNameThatMatchesTheFacetThatAzureSearchSendsBack", FacetOrder = 1});
myFacetDefinitions.Add(new FacetDefinition() { FacetName = "SomeOtherNameThatMatchesTheFacetThatAzureSearchSendsBack", FacetOrder = 2});
...

      

Answer # 4:

To return all books for a specific user, you can simply add a filter expression like this:

userId eq <put_authenticated_userid_here>

      

An authenticated user is expected to be able to see only their own books. However, if you want to have a list of users in a facet to filter on one or more of them, then this would require another restructuring of the index schema to have a new field in the book document called something like "users" is a collection (Edm .String) of the username. Like this:

{
    ...
    users: ["Luke Skywalker", "Han Solo", "Chewbacca", etc...]
    ...
}

      

+3


source







All Articles