Intersect indexes that return Array and Ref

I need to combine two or more indexes for my product collection to provide search filters in my application. Per example, the user can be filter by lower or higher price, by category (shirts, skirts, dresses, …), and so on. But, my problem is that I need to sort some of this indexes by your field, per instance, all_products_by_lower_price return an array of the price and the ref where the price determines the order, while the the index all_products_by_category return only the refs. So, I need an approach to intersect the results of each index.

This answer might be helpful?

1 Like

I need to order by price (low or high) and intersect with the by category index, but when using Join to get only the refs (dropping prices) the order is broken. How to use Join keeping the original ordering the by price index?

Paginate(
  Intersection(
    Join(
      Match(Index("all_products_by_category"), "blusas"),
      Lambda("ref", Match("product_ref_by_ref", Var("ref")))
    ),
    Join(
      Match(Index("all_products_by_price_asc")),
      Lambda(["price", "ref"], Match(Index("product_ref_by_ref"), Var("ref")))
    ),
    Join(
      Match(Index("all_products_by_views")),
      Lambda(["views", "ref"], Match(Index("product_ref_by_ref"), Var("ref")))
    )
  )
)

err… it’s not a great solution but you could make an index that uses join to resort the intersected set. term = ref, values = (price, ref)

Does it work to move the join up a level. Where all of the Match indexes return just ref (default no values provided) and then they are joined with a ref_by_ref index that does the sorting. The latter would change depending on which is the dotted field, or if multiple sorts are provided.

Join(
  Intersection(Match(...), Match(...)),
  Index("product_ref_by_ref_SORTED")
)

Point being, I think it is the second Index that defines the order returned, but I can’t remember and am away from computer ATM.