Start of blevification
This commit is contained in:
84
db/index.go
84
db/index.go
@@ -1,80 +1,24 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/tardisx/linkwallet/entity"
|
||||
bolthold "github.com/timshannon/bolthold"
|
||||
)
|
||||
|
||||
func (db *DB) InitIndices() {
|
||||
wi := entity.WordIndex{}
|
||||
db.store.DeleteMatching(wi, &bolthold.Query{})
|
||||
panic("unimplemented")
|
||||
// wi := entity.WordIndex{}
|
||||
// db.store.DeleteMatching(wi, &bolthold.Query{})
|
||||
}
|
||||
|
||||
func (db *DB) UpdateIndexForWordsByID(words []string, id uint64) {
|
||||
// delete this id from all indices
|
||||
txn, err := db.store.Bolt().Begin(true)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
db.store.TxForEach(txn, &bolthold.Query{}, func(wi *entity.WordIndex) error {
|
||||
delete(wi.Bitmap, id)
|
||||
// if the index is now completely empty, nuke it entirely
|
||||
empty := true
|
||||
for _, v := range wi.Bitmap {
|
||||
if v {
|
||||
empty = false
|
||||
break
|
||||
}
|
||||
}
|
||||
// func (db *DB) IndexDocument(id uint64, info entity.PageInfo) {
|
||||
// log.Printf("I am indexing!")
|
||||
// err := db.bleve.Index(fmt.Sprint(id), info)
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// }
|
||||
|
||||
if empty {
|
||||
db.store.TxDelete(txn, "word_index_"+wi.Word, wi)
|
||||
} else {
|
||||
db.store.TxUpdate(txn, "word_index_"+wi.Word, wi)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
// adding
|
||||
for i, word := range words {
|
||||
// log.Printf("indexing %s", word)
|
||||
thisWI := entity.WordIndex{Word: word}
|
||||
err := db.store.TxGet(txn, "word_index_"+word, &thisWI)
|
||||
if err == bolthold.ErrNotFound {
|
||||
// create it
|
||||
thisWI.Bitmap = map[uint64]bool{}
|
||||
} else if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
thisWI.Bitmap[id] = true
|
||||
err = db.store.TxUpsert(txn, "word_index_"+word, thisWI)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if i > 0 && i%100 == 0 {
|
||||
txn.Commit()
|
||||
txn, err = db.store.Bolt().Begin(true)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
txn.Commit()
|
||||
}
|
||||
// func (db *DB) UpdateIndexForWordsByID(words []string, id uint64) {
|
||||
// panic("I should not be called")
|
||||
// }
|
||||
|
||||
func (db *DB) DumpIndex() {
|
||||
|
||||
err := db.store.ForEach(&bolthold.Query{}, func(wi *entity.WordIndex) error {
|
||||
log.Printf("%10s: %v", wi.Word, wi.Bitmap)
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
panic("unimplemented")
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user