GithubHelp home page GithubHelp logo

Comments (10)

qweawdqq avatar qweawdqq commented on June 25, 2024

刚添加完的索引是能够查询到的,但是重启工程之后,就查询不到之前添加的索引了

from riot.

vcaesar avatar vcaesar commented on June 25, 2024

Please provide the code.

from riot.

qweawdqq avatar qweawdqq commented on June 25, 2024
//标题、作者、标签
func AddContent(title,content,author string,labels[]string)(err error)  {
	//defer searcher.Close()
	//错误
	log.Println("添加了文件标题为: ", title)

	//err = GetError()
	//为文件添加属性
	attri :=types.Attri{title,author,unit.GetTimeNow(),0}
	ct :=types.DocData{Content: content}
	ct.Attri=attri
	//如果类别不为空则添加类别
	if labels != nil || len(labels) >0{
		ct.Labels = labels
	}
	//生成主键
	docid := uint64(time.Now().Unix())
	//插入
	searcher.Index(docid, ct)
	//searcher.Index(22, types.DocData{Content: content})
	//刷新
	searcher.Flush()
	log.Println("创建的索引数量: ", searcher.NumDocsIndexed())

	return err
}

from riot.

qweawdqq avatar qweawdqq commented on June 25, 2024

我是使用了一个web框架(beego),请求过来之后在进行添加搜索文档的

from riot.

qweawdqq avatar qweawdqq commented on June 25, 2024

Take a look at the code I duplicated.Adding is good, but as long as the service is restarted, there is no data added before.

from riot.

qweawdqq avatar qweawdqq commented on June 25, 2024

I used a web framework (beego)
After the request comes in, the search document is added.
The files added before restarting the service disappeared

from riot.

vcaesar avatar vcaesar commented on June 25, 2024

Please restore index first, then try gob registration,

gob.Register(MyAttriStruct{})

from riot.

qweawdqq avatar qweawdqq commented on June 25, 2024

Thank you very much. The problem has been solved.

from riot.

zlykernel avatar zlykernel commented on June 25, 2024

Thank you very much. The problem has been solved.
能提供一下 解决的代码吗

from riot.

zlykernel avatar zlykernel commented on June 25, 2024

我也遇到同样问题,go version go1.12.4 linux/amd64
代码如下:
package main

import (
"log"
"net/http"
"time"

// rhttp "github.com/go-ego/riot/net/http"

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

)

var (
// searcher is coroutine safe
searcher = riot.Engine{}

opts = types.EngineOpts{
	Using: 1,
	IndexerOpts: &types.IndexerOpts{
		IndexType: types.DocIdsIndex,
	},
	UseStore: true,
	StoreFolder: "riot-index-data",
	StoreEngine: "bg", // bg: badger, lbd: leveldb, bolt: bolt
}

)

//标题、作者、标签
func AddContent(title,content,author string,labels[]string)(err error) {
//defer searcher.Close()
//错误
log.Println("添加了文件标题为: ", title)

//err = GetError()
//为文件添加属性
attri :=types.Attri{title,author,time.Now().Format("2006-01-02 15:04:05"),0}
ct :=types.DocData{Content: content}
ct.Attri=attri
//如果类别不为空则添加类别
if labels != nil || len(labels) >0{
	ct.Labels = labels
}
//生成主键
docid := time.Now().Format("2006-01-02 15:04:05")
//插入
searcher.Index(docid, ct)
//刷新
searcher.Flush()
log.Println("创建的索引数量: ", searcher.NumDocsIndexed())
return err

}

func Add(w http.ResponseWriter, req *http.Request){
AddContent("title1","content1","author1",[]string{"false"})
log.Println("after Add 创建的索引数量: ", searcher.NumDocsIndexed())
// restoreIndex()
}

func restoreIndex() {
searcher.Init(opts)
defer searcher.Close()
searcher.Flush()
log.Println("recover index number: ", searcher.NumDocsIndexed())
}

func main() {

searcher.Init(opts)
// restoreIndex()
log.Println("创建的索引数量: ", searcher.NumDocsIndexed())
// http.HandleFunc("/search", rhttp.Search)
// http.HandleFunc("/dist", rhttp.WgDist)
// http.HandleFunc("/Add", Add)
// log.Println("listen and serve on 8080...")
// log.Fatal(http.ListenAndServe(":8088", nil))

// Add(nil,nil)
// searcher.Flush()

sea := searcher.Search(types.SearchReq{
	Text: "content1",
	RankOpts: &types.RankOpts{
		OutputOffset: 0,
		MaxOutputs:   100,
	}})
log.Println("查询: ", sea)

defer searcher.Close()

}

from riot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.