How to add scoring function of type Freshness to a field of type Collections(Edm.ComplexType) in Azure Cognitive Search?

Vadiraj Rao 0 Reputation points
2023-03-29T07:01:17.79+00:00

I have configured and indexed the data for Azure Cognitive Search, the indexed data contains a field TimeSlots of type Collections(Edm.ComplexType) which looks like


"TimeSlots": [

                {

                    "Slot": "2020-11-23T08:00:00-08:00"

                },

                {

                    "Slot": "2020-11-23T09:00:00-08:00"

                },

                {

                    "Slot": "2023-11-23T10:00:00-08:00"

                }

]

I wish to add a scoring function such that the search results are ordered by the latest TimeSlot on the top. The scoring function type Freshness allows us to get the document with latest DateTimeOffset on top of the search result, but this function does not work on the field type Collections(Edm.ComplexType)

Also, the number of slots for each document is variable, hence we cannot set up separate fields for each slot.

What steps do I need to take in order to sort my search results based on AvailableTimeSlots?

I tried converting the field type of TimeSlots to Collection(Edm.DateTimeOffset) but even this field type was not accepted.

Azure AI Search
Azure AI Search
An Azure search service with built-in artificial intelligence capabilities that enrich information to help identify and explore relevant content at scale.
947 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Grmacjon-MSFT 17,886 Reputation points
    2023-03-30T05:44:45.56+00:00

    Hi @Vadiraj Rao thanks for the question.

    The Freshness scoring function is not supported for fields of type Collections(Edm.ComplexType)

    To sort search results based on the latest TimeSlot, you can use the $orderby parameter in your search query. However, since the number of slots for each document is variable, you cannot set up separate fields for each slot.

    One approach to solve this problem is to create a new field in your index that contains the latest TimeSlot for each document. You can use an indexer skill to extract the latest TimeSlot from the TimeSlots field and populate the new field.

    Once you have the new field, you can use the $orderby parameter to sort search results based on the new field.

    Here are the high-level steps to implement this approach:

    1. Create a new field in your index to store the latest TimeSlot for each document.
    2. Use an indexer skill to extract the latest TimeSlot from the TimeSlots field and populate the new field.
    3. Use the $orderby parameter in your search query to sort search results based on the new field.

    Hope this helps! Let us know if you have any further questions.

    -Grace


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.