How to structure a Search with Indexing Relations

Hi ! I write this down in my algolia brows :

 [
{
  "book_name": "Harry Potter and the Philosopher's Stone",
  "popularity": 1000
},
{
  "book_of": "Harry Potter and the Philosopher's Stone",
  "chapter_name": "The Boy Who Lived",
  "popularity": 900
},
{
  "book_of": "Harry Potter and the Philosopher's Stone",
  "chapter_name": "The Vanishing Glass",
  "popularity": 800
}
]

And i would like to have when i search a chapter something like this :

  1. Search “The Vanishing Glass” :

Harry Potter and the Philosopher’s Stone
_________________ The Vanishing Glass

  1. Search “Harry Potter” :

Harry Potter and the Philosopher’s Stone
_________________ The Boy Who Lived
_________________ The Vanishing Glass

I would like to show where the search come from or what the search has.

If anyone have ideas or solutions ? Thank you :slight_smile:

I think we can use the distinct parameter here.

[
{
  "book_name": "Harry Potter and the Philosopher's Stone",
  "book_id": 123,
  "type": 1,
  "chapter_name": ["The Boy Who Lived", "The Vanishing Glass"],
  "popularity": 1000
},
{
  "book_name": "Harry Potter and the Philosopher's Stone",
  "book_id": 123,
  "type": 2,
  "chapter_name": "The Boy Who Lived",
  "popularity": 900
},
{
  "book_name": "Harry Potter and the Philosopher's Stone",
  "book_id": 123,
  "type": 2,
  "chapter_name": "The Vanishing Glass",
  "popularity": 800
}
]

If you set distinct to 3, on the book_id attribute, you should get the correct results. Then you can use the type to differentiate them in your view.