MCPcopy Index your code
hub / github.com/TruthHun/BookStack / RebuildAllIndex

Method RebuildAllIndex

models/elasticsearch.go:269–397  ·  view source on GitHub ↗

重建索引【全量】 采用批量重建索引的方式进行 每次操作100条数据

(bookId ...int)

Source from the content-addressed store, hash-verified

267//采用批量重建索引的方式进行
268//每次操作100条数据
269func (this *ElasticSearchClient) RebuildAllIndex(bookId ...int) {
270 if !this.On {
271 return
272 }
273
274 bid := 0
275 if len(bookId) > 0 {
276 bid = bookId[0]
277 }
278
279 if IsRebuildAllIndex && bid <= 0 {
280 return
281 }
282 if bid <= 0 {
283 defer func() {
284 IsRebuildAllIndex = false
285 }()
286 IsRebuildAllIndex = true
287 }
288
289 pageSize := 1000
290 maxPage := int(1e7)
291
292 privateMap := make(map[int]int) //map[book_id]private
293
294 o := orm.NewOrm()
295 book := NewBook()
296 // 更新书籍
297 for page := 1; page < maxPage; page++ {
298 var books []Book
299 fields := []string{"book_id", "book_name", "label", "description", "privately_owned"}
300 q := o.QueryTable(book).Limit(pageSize).Offset((page - 1) * pageSize)
301 if bid > 0 {
302 q.Filter("book_id", bookId).All(&books, fields...)
303 } else {
304 q.All(&books, fields...)
305 }
306
307 if len(books) > 0 {
308 var data []ElasticSearchData
309 var bookId []int
310 for _, item := range books {
311 data = append(data, ElasticSearchData{
312 Id: item.BookId,
313 Title: item.BookName,
314 Keywords: item.Label,
315 Content: item.Description,
316 BookId: 0, //注意:这里必须设置为0
317 Private: item.PrivatelyOwned,
318 Vcnt: item.Vcnt,
319 })
320 privateMap[item.BookId] = item.PrivatelyOwned
321 bookId = append(bookId, item.BookId)
322 }
323 if err := this.BuildIndexByBuck(data); err != nil {
324 beego.Error(err.Error())
325 beego.Error("书籍索引创建失败,书籍ID:", bookId)
326 } else {

Callers 1

ReleaseContentMethod · 0.95

Calls 6

BuildIndexByBuckMethod · 0.95
html2TextMethod · 0.95
NewBookFunction · 0.85
NewDocumentFunction · 0.85
appendFunction · 0.50
AllMethod · 0.45

Tested by

no test coverage detected