go-ego / riot

Go Open Source, Distributed, Simple and efficient Search Engine; Warning: This is V1 and beta version, because of big memory consume, and the V2 will be rewrite all code.
Apache License 2.0
6.11k stars 473 forks source link

Compiling error when use SearchID() #85

Closed xiaomi-tc closed 5 years ago

xiaomi-tc commented 5 years ago
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'

xiaomi-tc commented 5 years ago

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

vcaesar commented 5 years ago

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