5

我在一个 android 应用程序中实现标签,需要一些关于以下内容的指针:

  • 用户可配置的多标签设置的模式设计
  • 如何优化搜索、过滤和简单性的模式。

请注意,我已经查看了一些专注于更大的类似服务器的部署的设计,我正在寻找简单且适用于移动 (SQLITE) 环境中的单个表的东西。

乍一看,我正在考虑使用字符分隔的 varchar 来表示关联的标签,例如#work#meeting#monthly。有更好的设计方法吗?

4

2 回答 2

1

If you use that approach you will have a problem searching and filtering, use a table for your data and another for your tags.

You can use a third table that gives the relation between data and tags, but it is slow and inefficient.

Now, for optimal performance for search and filter, use a list of pointers in the tags table to the data table, this way, if you filter by a tag you will get O(1) complexity. The problem is that you will get the tags related to a data slowly. You can do the same thing in reverse, and have the list of tags tied to your data, but you will have a lot of work to do to keep it valid, since you have to update both tag and data on update.

In the end, keeping in mind that nr_of_tags << nr_of_data you should use just the data pointer tied to the tag, and if you want to show the tags related to a data, then you parse that tags table and search.

Edit: just now I see you want to use just one table.

于 2013-09-18T07:36:57.610 回答
1

我想您必须在将处理卸载到数据库或在您的代码中进行处理之间做出权衡。

我建议在您的代码中执行此操作,因为一旦您在内存中获取数据,您将避免磁盘读取,并且您可以使用线程等高效地处理应用程序层的处理。

这样您就可以避免在多线程模式下运行 SQLite 本身(因此必须在 db 层处理同步)。

一个非常简单的模式可能是:

ID | TAGS
_________
1  | work,meeting,monthly
2  | home,leisure,yearly

您可以将字符串数组存储为逗号分隔值,并使用一个简单的技巧轻松检索它们。

然后你可以使用标准的java集合来映射、排序等

于 2013-09-18T07:57:06.183 回答