为数组值创建索引

问题描述

我正在尝试使用 Redisearch 为数组值创建索引。 这是代码

c := redisearch.NewClient("127.0.0.1:6379","redisearchDB")

sc := redisearch.NewSchema(redisearch.DefaultOptions).
  AddField(redisearch.NewTextField("Code"))
// Drop an existing index. If the index does not exist an error is returned
c.Drop()

// Create the index with the given schema
if err := c.CreateIndex(sc); 
       err != nil {
      log.Fatal(err)
}
doc := redisearch.NewDocument("Test",1.0)

for i,record := range data {
    postRecord := &BlogPost{}
    err := json.Unmarshal(record.Value,postRecord)
    log.Info("response:",postRecord)
    if err != nil {
        return err
    }
    rsp.Cache[i] = &tcache.TKCache{
        Code:    postRecord.Code,}
    doc.Set("code",postRecord.Code)
}
// Index the document. The API accepts multiple documents at a time
if err := c.Index([]redisearch.Document{doc}...); err != nil {
    log.Fatal(err)
  }
 }  
return nil
}

需要这样的回复

  1. (整数)2
  2. “测试:1”
    1. 代码
    2. “ADL”
  3. “测试:2”
    1. 代码
    2. “MSL”

如何像上面的响应那样创建索引。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)