粗糙的MONGOID TAG

设计目的:

  1. 不用动脑子想tag的设计
  2. 单向对基于tag查询实体的优化

基于以下假设

  1. 根据标签名称,查找实体的情况频繁于根据实体查找tags
  2. 实体间不共享一类 tag

用法

class Model include Mongoid::Document include EasyMongoidTag

field :bname, as: :book_name, type: String easy_tags :tests end book1 = Model.create(bname: ‘红楼梦’, :tests => [’曹雪芹 ’, ’ 高 鹗 ’]) book2 = Model.create(bname: ‘石头记’, :tests => [‘曹沾’, ‘高 鹗’]) book1.test_tags TestTag.find_by(title: ‘曹雪芹’) TestTag.search(‘曹’)