安卓搜索:使用FTS表与正常的SQLite数据库表 [英] Android search : Use FTS tables along with normal SQLite DB Tables

查看:404
本文介绍了安卓搜索:使用FTS表与正常的SQLite数据库表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这更多的是一个设计问题 - 不只是一个编码问题

This is more of a design question - not just a coding question.

我已经有一个应用程序,将数据存储在SQLite的数据库表。现在,我想添加搜索功能到这一点。

I already have an app that stores data in SQLite DB tables. Now I want to add Search feature into this.

据我所知,为了让搜索功能,我需要FTS表。

I understand that in order to enable search feature I need FTS tables.

这是我的(不完全一样,但给人非常相似的示例)表:

The tables that I have are (not exactly the same but giving very similar example):

内容表 - 有一个像列:ID,标题,内容,创建人,创建日期,更改者,改变了等...

Content table - has columns like: Id, Title, Content, Created By, Created On, Changed By, Changed on etc ...

意见表 - 有列,如:身份证,评论,创建人,创建时间,在回复等等...

Comments table - has columns like: Id, Comments, Created By, Created On, In Reply to etc ...

喜欢的用户数据,元数据,分类,标签等其他表

Other tables like User Data, Meta Data, Categories, Tags etc.

在这里,我只想搜索标题,内容和注释功能。很显然,我喜欢用等创建不需要在其他列的搜索能力。

Here I only want search capability on Title, Content and Comments. Obviously I don't need search capability on other columns like created by etc.

这是最好的选择吗?

  1. 我应该放弃我的旧表,并只创建FTS表?
  2. 我应该继续使用旧表,并创建只支持搜索功能的新FTS表。

问题,我有选择1看到的是:

Problems that I see with option 1 are:

  • 这是一个颠覆性的改变!
  • 在我有一组具有许多非文本列上,我不打算执行搜索多个表。我如何模拟它们FTS?
  • 右键现在我使用RDBMS的功能,如加入等等,我认为我将无法做,如果我切换充分FTS表!

问题,我与选项2看到的是:

Problems that I see with option 2 are:

  • 这将导致重复表 - !而且会占用更多的内存/空间
  • 在我每次插入/更新/修改我的SQL表的条目,我必须做的FTS表相同的变化。

那么,什么是最好的选择? 有没有任何机构面临着类似的挑战是什么?

So, what is the best option ? Has any body faced similar challenges ?

推荐答案

FTS表不能高效地查询非FTS的搜索,所以选择1超出。

FTS tables cannot be efficiently queried for non-FTS searches, so option 1 is out.

整个FTS表基本上是一个索引。这是一个速度/空间折衷,并做全文搜索的能力,通常是值得的。 为了避免存储原始文本的两倍,使用外部内容表的。

The entire FTS table essentially is an index. This is a speed/space tradeoff, and the ability to do full-text searches usually is worth it. To avoid storing the original text twice, use external content tables.

要保持同步的原件和FTS表,使用触发器。

To keep the original and FTS tables in sync, use triggers.

这篇关于安卓搜索:使用FTS表与正常的SQLite数据库表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆