Click Here to Request a FREE Quote to Develop an iPhone App or Android App

Fast Text Searching in a Mobile App

Searching large text fields (as in thousands of words) for small key phrases is traditionally a difficult problem, especially when the search has to be performed by a mobile app, using an Android or iPhone handset’s limited computing power.

Linear Text Search

Your mobile app could search for your key phrase by checking every letter in your text, as the possible starting point for the phrase you want to find. This works when the text you are searching is short – but if you are attempting to search many thousands of words of text, a linear search is slow, even at modern computing speeds.


Search: The quick brown fox jumps over the lazy dog
Key Phrase: lazy dog
Algorithm: check each letter
The quick brown fox jumps over the lazy dog

Text Map Search

The alternative is to partially pre-run the search when developing the mobile app. You can’t predict the keywords a user will enter, but you can create a searchable text map of the relationships between words and phrases in the text to be searched, to allow code to rapidly search the map, rather than having to check every letter of every word of the text to be searched.


Search: The quick brown fox jumps over the lazy dog
Key Phrase: lazy dog
Algorithm: pre-run search
L -> La -> Lazy -> Lazy Dog

How do you pre-run a search? You could research efficient word search structures – suffix trees, and other exotic data representations. After a significant amount of effort you would be able to create a search engine, which was much faster than a linear search of every letter in your text.

Or you could use the full text index feature of the SQLite database engine, which is fully supported in both the Android App and iPhone App environments.

SQLite Full Text Index

The SQLite full text index engine is very fast – correctly configured, it can search 10s of megabytes of text stored in your mobile app, fast enough so your code can update a list of hits in realtime, as the user types into the search box (obviously its a bit smoother if the database search is running in a different thread). In my experience the limitation on search speed is usually how quickly your code can create tables of data to represent the search results, rather than executing the search itself – so during performance tuning, it is worth considering minimum phrase lengths (e.g. don’t start the search until the user has entered at least 3-4 characters), to limit the number of results which are likely to be generated by a given search.

Creating a SQLite Full Text Index table is very similar to creating a normal database table. If the text to be searched is fixed (i.e. doesn’t change when the mobile app is used), the text search SQLite database can be created when the app is built, and accessed immediately, as soon as the user starts the mobile app.

Other Full Text Index Options

Full Text Index databases are also well supported by web technology. On most Linux boxes you can choose between a SQLite Full Text Search Database or a MySQL Full Text Search Database.

The Next Step

If you are thinking of developing an iPhone app or Android App, or any other kind of mobile app, which needs to present users with the ability to search a large chunk of text very rapidly, please contact me, for advice on optimal ways of implementing such a search.

Leave a Reply

Your email address will not be published. Required fields are marked *