views:

790

answers:

3

I'm looking for suggestions on the best way to implement a full-text search on some static data on the iPhone.

Basically I have an app that contains the offline version of a web site, about 50MB of text, and I'd like for users to be able to search for terms. I figure that I should somehow build an table of ("word", reference_to_file_containing_word) or something, put that into either Core Data or just sqlite, index the "word" column, then have the search facility search the table for search terms and take the intersection of the sets of results for the terms or something.

That wouldn't allow people to search for phrases but it would be pretty easy and probably not too slow.

I'd like to just use existing SDK features for this. Should I use Core Data or sqlite?

Does anyone have any other ideas on how this could be done?

+4  A: 

You want to place every word in the document in its own row in a database? That's going to take up even more space than the document itself.

I would recommend just searching through the text; regex is actually pretty fast. Otherwise, you could implement Boyer-Moore fairly easily.

[Edit] If you insist on creating an index of words, you can't beat a trie. It would be faster than using a database, and most likely take up less space than the documents themselves (unlike the database)

BlueRaja - Danny Pflughoeft
Thanks! I think I'll try just traversing all the files with regexps first then if that's too slow I'll try other things from there. Having done network-related programming I'm somewhat familiar with tries but hadn't thought to apply them to words rather than network prefixes.
Nimrod
A: 

Hi there!

I don’t understand zoop about programming on the iPhone, but I’m desperately searching for some simple app that searches for text strings in a specified directory of about 1000 text files. Does anyone know if such a thing exists, or has anyone ever programmed such an app?

Thanks all, Dirk.

Dirk Rensmann
+1  A: 

The answer is FTS3 for SQLite. Google it, there are many tutorials on how to get it working on iPhone.

And the easy way to use SQLite on iPhone is using FMDB.

baswell