go-ego/riot

Compiling error when use SearchID()

xiaomi-tc opened this issue · 2 comments

  • Riot version (or commit ref): v0.10.0.425
  • Go version: 1.12
  • Operating system and bit: linux (centos7.6)
  • Can you reproduce the bug at Examples:
    • Yes (provide example code)
    • No
    • Not relevant
  • Provide example code:
package main

import (
	"log"

	"github.com/go-ego/riot"
	"github.com/go-ego/riot/types"
)

var (
	searcher = riot.New("zh")
)

func main() {
	data := types.DocData{Content: `I wonder how, I wonder why
		, I wonder where they are`}
	data1 := types.DocData{Content: "所以, 你好, 再见"}
	data2 := types.DocData{Content: "没有理由"}

	searcher.Index("1", data)
	searcher.Index("2", data1)
	searcher.Index("3", data2)
	searcher.Flush()

	req := types.SearchReq{Text: "你好"}
	search := searcher.Search(req)
	log.Println("search...", search)

	search1 := searcher.SearchID(req)
	log.Println("search...", search1)

	req = types.SearchReq{Text: "why"}
	search = searcher.Search(req)
	log.Println("search...", search)
}

Description

Compiling error: '...github.com/go-ego/riot/engine.go:756:3: cannot use resp.Docs.(types.ScoredDocs) (type types.ScoredDocs) as type []types.ScoredID in field value'

sorry, compile ok
panic when running

panic: interface conversion: interface {} is types.ScoredDocs, not types.ScoredIDs

goroutine 1 [running]:
github.com/go-ego/riot.(*Engine).SearchID(...)
/home/devuser/Golibs/src/github.com/go-ego/riot/engine.go:755
main.main()
/home/devuser/MyProj/riot_test/default-engine/main.go:29 +0x6b1

Set IdOnly to true with searchID(), otherwise use searchDoc().