Search code examples
azure-cognitive-searchazure-search-.net-sdk

Index movie duration


I'm trying to figure out how I'm intended to store my movies duration field (e.g. 02:20:13 for a movie that is 2 hrs, 20min, and 13 sec long) so that users searching the index can facet on movie duration.

Like in the facet they can select from 01:00:00 to 02:00:00 for movies that are between 1 to 2 hours long. I tried to store duration as a DateTime value and have that indexed but that includes dates which don't seem relevant to what I'm trying to achieve.


Solution

  • Probably the easiest solution would be to store duration as a field of type Edm.Int32 where the field value represents the total duration in seconds. While you could use Edm.DateTimeOffset to represent durations, it doesn't really buy you any additional functionality over using a plain integer. It's basically a tradeoff: If you use date/time, your app has to ignore the date part; If you use integers, your app needs UI logic to render them as durations in hh:mm:ss format.