【问题标题】:full text search implementation with Golang and MongoDB using mgo使用 mgo 使用 Golang 和 MongoDB 实现全文搜索
【发布时间】:2017-11-06 05:37:31
【问题描述】:

我正在尝试打印我知道包含我的搜索词的 6 个对象。我能够看到正确长度/大小/容量的查询数组。但是当我迭代数组并打印时,它们不包含任何信息。

我最初的反应是我的结果界面可能有误。

代码sn-p:

var sTerm = "Google"
index := mgo.Index{
    Key: []string{"product.maker", "product.product"},
}

err = col.EnsureIndex(index)
//err = col.EnsureIndexKey("product.maker")
check(err)

//query := col.Find(bson.M{"$text": bson.M{"$search": sTerm}})
query := col.Find(bson.M{"product.maker": sTerm})
//query := col.Find(bson.M{"product.maker": &bson.RegEx{Pattern: sTerm, Options: "i"}})
fmt.Println(query)

var res []struct{ Value int }
err = query.All(&res)
check(err)
fmt.Println(res)
for i := 0; i < len(res); i++ {
    fmt.Println(res[i])
}

输出:

&{{0 0} 0xc042056d00 {{devbase.devices map[product.maker:Google] 0 0 <nil> 0 <nil> 0 {<nil> <nil> <nil> false false [] 0 0 } false []} 0.25 0}}
[{0} {0} {0} {0} {0} {0}]
{0}
{0}
{0}
{0}
{0}
{0}

目前,我正在对搜索词进行硬编码,我已经为响应和 Gorilla mux 设置了一个 http 处理程序函数。

【问题讨论】:

    标签: mongodb go full-text-search mgo full-text-indexing


    【解决方案1】:

    没关系!

    var res = []bson.M{}
    

    我知道我知道...我现在要去开枪了。哈哈!还是谢谢!

    【讨论】:

      猜你喜欢
      • 2012-10-20
      • 2014-08-26
      • 1970-01-01
      • 1970-01-01
      • 2018-07-28
      • 2013-01-05
      • 2023-04-04
      • 2014-09-09
      • 2019-05-09
      相关资源
      最近更新 更多