how to make a keyword searchable hash function/table

I need to, upon receiving an input file with strings of song names, be able to create a hash table of them that is searchable by keywords.

ie. if my input file is

file 1: artist= "The Beatles", title= "All I Need Is Love (Live)"
file 2: artist= "The Beatles", title= "Help! (Live)"
file 3: artist= "The Beatles", title= "Yellow Submarine"

I would need to hash these three to a table and upon searching for

(Live): return file 1 and file 2
Beatles: return file 1, file 2, and file 3
Help!: return file 2

What would be the best way of going about this? I can think of a way to hash them all so that they are searchable in O(1) time if I search for their full name, but I cant think of a way in which every word contained in each line can be used to find the song also.

Any help would be greatly appreciated.

Thanks,
Psychocowtipper
You're asking about an advanced algorithm. Your question is not really related to C++ per se.
Anyhow, a naive approach of implementing your text search functionality would be to have a multi hash map which has as keys the individual words from song titles and as values a pointer (or some kind of reference) to the full song. Something along those lines. You'd probably want to allow for case-insensitive searches, however, Why don't you break into Google's offices and steal their code to do it?
I think you need to extract each individual word from the title and store the words.
One could do this using a std::multimap with each word and phrase in artist and title as a key.
If you want your searches to be case-insensitive, store the keyword keys in your multimap as all lowercase or all uppercase, and when you do a search for a word, convert that word to that case.
Topic archived. No new replies allowed.