In the early years of The Daily Show this was a manual process:
The story of an early segment called “Bush v. Bush” is described by writer Steve Bodow as a “Rosetta stone” and with good reason. The Daily Show realized that the strongest commentary on a politician lying was just juxtaposed footage of the politician saying two contradictory things on different occasions. This became a trademark of the show and drove the technology that would make this kind of work easier in years to come. For that 2003 segment, the staff had to pore through hours of VHS footage to get the clips they needed – it took weeks to put together. Beyond the VHS tapes the staff kept, they could request footage from companies that recorded news and politics clips.
But then technology advanced, and they used a bank of TiVOs to record cable news constantly, and then built a clip library out of that:
Soon, they began using TiVO, recording cable news constantly. Different writers and producers watched different news shows so they could bring in suggestions. They started growing a clip library they could refer to to point out hypocrisy, with interns and assistants transcribing footage to make it searchable.
Then commercial companies saw a market for such a service, and TDS started using their services:
In 2010, the show began using SnapStream, which made searching for specific quotes in hundreds of hours of footage even easier. This technology has allowed the show remain a go-to for audiences who felt like they were getting context-free stories from mainstream news outlets.
This article on NJ.com has some more details from the book about this:
Steve Bodow, Stewart's former head writer and currently an executive producer for Stewart's replacement, Trevor Noah, recalls a segment that aired in the midst of the 2003 invasion of Iraq (part of the sadly immortal "Mess O'Potomia") in which President Bush debated his pre-9/11 more isolationist self. "Bush vs. Bush" took two weeks and mountains of VHS tapes to assemble.
It was the first time, Bodow says, "we put together pieces of tape to show that kind of hypocrisy. And it was the beginning of using our institutional memory as a major asset to the show. You could get people in a room and someone notices this thing, and somebody else is going to remember, 'Wait, didn't he say ...' We began to understand that collaboration and finding contradictions in a big part of what we can do."
Soon they had 16 Tivos running all the time.
You can read more about TDS's processes in The Daily Show (The Book): An Oral History as Told by Jon Stewart, the Correspondents, Staff and Guests, which has a long entry that is summarized in the articles linked above.
This 2008 New York Times article also describes their TiVO-era process:
Mr. Remnick asked the writers and producers what a typical day at “The Daily Show” is like. Based on their responses, here is a summary:
7 a.m.: About seven or eight producers start work, culling through video footage and material from the previous day, much of which is stored on a set of 15 to 20 TiVo digital-video recorders. Adam Lowitt, a producer who manages the studio production department, which keeps track of the footage, said that time is spent “gathering and finding these great gems that hopefully we can get on the show.”
Staff members will have e-mailed one another other the previous day about tidbits they saw on television and their approximate timestamps, as well as other ideas. Many of the most biting pairings footage were said to be the work of Adam Chodikoff, a researcher and “unsung hero” of the show, who was sitting in the audience. When asked if he watched a lot of television when he was a child, he replied, “The Brady Bunch.”
Vulture has done an in-depth article on SnapStream:
Have you ever wondered where these clips come from? Does one Last Week Tonight employee watch hours of TV in the hopes that someone will drop a reference to the annual March Madness ad revenue to fit in with what they’re writing? What about the recent Daily Show Vine featuring “50 Fox News Lies in 60 seconds:” did somebody watch Fox News for days to get all of these clips?