复杂的二级索引操作

Complex secondary index operations

我可以为此创建二级索引 table:

{
  contact: [
    'example@example.com'
  ]
}

像这样:indexCreate('contact', {multi: true})

但是我可以为此创建索引吗:

{
  contact: [
    {
      type: 'email',
      main: true
      value: 'andros705@gmail.com'
    }
    {
      type: 'phone'
      value: '0735521632'
    }
  ]
}

辅助索引只会搜索类型为 'email' 且主要设置为 'true'

的对象

创建此类索引的方法如下:

table.indexCreate(
  'email',
  row => row('contact').filter({type: 'email'})('value'),
  {multi: true})

这通过使用多索引来实现。当 multi: true 参数传递给 indexCreate 时,索引函数应 return 一个数组而不是单个值。该数组中的每个元素都可用于在索引中查找文档(使用 getAllbetween)。如果数组为空,文档将不会出现在索引中。