YouTube Talks Search Index For Metadata
Searching for a specific video on YouTube can sometimes be a hassle, especially if it’s newly released. It could take a while for the site to update search results with that new video. There’s a way around that for developers.
Jeff Posnick, YouTube API team member, issued a pop quiz today on the YouTube API blog. They asked developers to spot the difference between three different URLs. It was found that only one of the URLs returned fresh results whereas the other two would suffer from latency which prevented videos uploaded in the past few hours from showing up.
This is caused by a request going against the YouTube search index. The index contains cached data whereas the up-to-date information comes from requests that get data directly from their backend database. Posnick offers up some advice on getting a request through to the backend database:
If your request only includes the max-results and/or start-index query parameters, then it should go against the backend database and the results will be fresh. A few other parameters that change the way the feed is formatted, like prettyprint, callback, or alt, can also be used without triggering the search index. Although it does filter results out of the feed, the fields parameter can also be used while still going against the backend database, because the filtering is performed server-side after the data has been retrieved.
If your request contains other parameters, there’s a good chance it will end up against the search index. Some common parameters that will always trigger a search are q and orderby.
The use of either the search index or backend database is reliant upon what you want to do. Posnick says that using search index is great for those that want to get a return on all videos that match “an arbitrary keyword” or “ordering a feed of videos os that they’re sorted by view count.” The backend should be used to gather fresh results or whenever it’s advantageous to do so.
Developers can also request a specific video from either the backend database or the search index. They use the example of searching for the video ID sOEAD-gfJ_M . Going with the backend, the user is presented with the video straight from the source. Going with the search index searches all metadata containing the video ID and then returns the actual video being searched for.
The moral of the story – if you want the most up-to-date video metadata, stick to the backend database. If you want to know more about the difference between search index and the backend database, check out the documentation on the matter.