转载自:http://blog.csdn.net/doymm2008/article/details/6796033
核心提示:数据字段一般都是保存原文的,一来方便在数据库修改和维护,而来有一些查询要用到它。但是在有些时候,我们无需保存原文了,比如在论坛,博客等数据里的内容字段,一般使用Clob类型,其很少参与搜索,而且就算要全文检索,我们也不推荐使用数据库的like 等,
而应该用第三方的全文检索工具,比如lucene等实现。
这类数据都是大量的文本数据,有很大的可压缩性。由于一些原因,我的数据库已经超过我能容忍的大小了,所以想到了是否可以把这个数据压缩存储来节省空间,于是有了如下的尝试。
压缩算法就先不过多考虑了,就用Zip进行尝试就可以了。先看看如何把字符串压缩和解压缩的算法。
然后就是如何压缩和解压缩,应该放在哪里的问题。我考虑了一下,发现JavaBean这东西真的有趣,竟然可以实现透明压缩和解压缩。看代码:
增加了一个是否压缩的属性。
在读取时,根据是否压缩的标志进行操作,在设置时,根据数据长度和压缩的效果更新数据,并设置压缩标志。
通过这个,数据将被压缩保存,一般的文本压缩率还是很高的,到底有多高,你自己测试看看就知道了。
-
顶
- 0