I'm having a hard time understanding how to use full text search (FTS) with Android. I've read the SQLite documentation on the FTS3 and FTS4 extentions. And I know it's possible to do on Android. However, I'm having a hard time finding any examples that I can comprehend. This one isn't bad, but it seems more complex than it needs to be (I hope).
Let me set up an outline for the kind of basic example that is lacking not just on StackOverflow but across the web. I think a good answer here could help a great number of people who are trying to learn how to use FTS with Android. I will try to make it general enough to apply to a wide audience but specific enough to have a concise answer.
The basic database model
A SQLite database table (named example_table) has 4 columns. However, there is only one column (named text_column) that needs to be indexed for a full text search. Every row of text_column contains text varying in length from 0 to 1000 words. The total number of rows is greater than 10,000.
- How would you set up the table and/or the FTS virtual table?
- How would you perform an FTS query on
text_column?
Additional notes:
- Because only one column needs to be indexed, only using an FTS table (and dropping
example_table) would be inefficient for non-FTS queries. - For such a large table, storing duplicate entries of
text_columnin the FTS table would be undesirable. This post suggests using an external content table. - External content tables use FTS4, but FTS4 is not supported before Android API 11. An answer can assume an API >= 11, but commenting on options for supporting lower versions would be helpful.
- Changing data in the original table does not automatically update the FTS table (and vice versa). Including triggers in your answer is not necessary for this basic example, but would be helpful nonetheless.
Aucun commentaire:
Enregistrer un commentaire