Creating fast, realtime dialogue search for television scripts

We have a database of television scripts and we’d like to search it, getting results as we type.

We often remember words or snippets of dialogue but can’t remember exactly what was said or what episode it was said in: “What was the episode where George goes against his instincts and walks up to the girl at the diner and tells her he’s unemployed?”

With this tool you’d type “George unemployed” and the result with context (and possibly other hits) would pop up:

EPISODE: "The Opposite"

George : Excuse me, I couldn't help but notice that you were looking in my direction.
Victoria : Oh, yes I was, you just ordered the same exact lunch as me.
( G takes a deep breath )
George : My name is George. I'm unemployed and I live with my parents.
Victoria : I'm Victoria. Hi.

My question is about the best way to design a data structure to implement this kind of search?
My idea so far is store a lookup table in an in-memory data store such as redis. To create the table, first I’d give each script (episode) an id, and then i’d parse the script into lines based on the person speaking. So a particular piece of dialogue could be located with an episode id paired with a line id.

Next I would process each line, creating a data structure indexed by all words appearing in any script, and storing the episode/line location of every instance the word was used.

apple -> [ 
           { scriptid: 9, lines: [11,99] },
           { scriptid: 21, lines: [103,211,214] }
         ]
orange -> [ 
            { scriptid: 2, lines: [101] }
          ]

We could pair this data structure with a simple scoring algorithm, so that when a user searched for multiple words, we’d only show matches where both words occured in the same script, and give higher rank to locations where the words appear closer to one another.

There are other details that, ideally, would be accounted for, such as matching plurals and mispelled words.

Is this a reasonable approach? How could it be improved? What other details should I consider?

3

I would use a search engine, e.g. ElasticSearch, which already has everything you need. It takes care data structure, storage, etc. so you can focus on what filtering the search and returning the results, i.e. drop some words (propositions, etc.), fix misspelled words, give boost to some results, etc. Each of those problem would need a separate discussion on how to solve it. But the default configuration should be enough to get you started.

What type of database are you using? and what programming language?
I personally, using a PHP and MySQL setup, would contain the scripts as an array by first splitting them and inserting into the table.
I would then split the user’s search into an array too by spaces.
Then, I would use the query
SELECT *
FROM 'table'
WHERE 'column'.contains('array[0], array[1]')

Hopefully this makes sense and provides a viable answer, and if not I hope it gives you a ‘starting point’ as such 🙂

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật