V2EX
Full Text Search
Posted in iPhone on November 22nd, 2008 by Xin

These days I’ve been working on an easy solution for implementing full text search on iPhone, and finally I got it working.

There is UISearchBar in UIKit, but there isn’t anything easy in iPhone SDK to help you implementing a high performance data structure for indexing and searching. After some Google search, I found that SQLite has a very promising full text search component called FTS3, however, this component exists in SQLite code tree as a plug-in, so it’s not to be found in iPhone’s built-in SQLite support.

To integrate FTS3 plug-in into your iPhone app, you need to build your own SQLite. Fortunately there is a project named The SQLite Amalgamation, it makes the whole SQLite source tree into three files: two .h headers and one .c source file. So you can create a group in your project in Xcode named SQLite, and drag-n-copy these 3 files into this group. So you’re ready to compile your own SQLite for your iPhone app.

Next step is to turn on FTS3 in sqlite3.c, you need to add this line:

#define SQLITE_ENABLE_FTS3 1

Below this line:

#define SQLITE_AMALGAMATION 1

Be aware that sqlite3.c is a very huge file weighing 340K+, it may crash your Xcode. You may want to open it in vim.

Now you can click build and play with your own SQLite 3 with FTS3. For more information on how to use FTS3, please read the official documentation, it’s quite easy:

http://www.sqlite.org/cvstrac/wiki?p=FtsOne

Bob Aman

Has anyone done this and gotten their app accepted into the App Store?

Shawn Chain

FTS3 needs to be hacked to support splitting chinese texts.

Dirk

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.

Leave a Reply