// Preferred method of creating an `IndexWriter` // Set's up all the necessary C bindings. func (index *Index) NewIndexWriter() *IndexWriter { flags := indexOpen if index.Create { flags |= indexCreate } if index.Truncate { flags |= indexTruncate } ixLocation := cb_newf(index.Path) defer C.DECREF(ixLocation) ixWriter := &IndexWriter{ Index: index, lucyIndexer: C.LucyIndexerNew(index.Schema.lucySchema, ixLocation, nil, C.int32_t(flags)), } runtime.SetFinalizer(ixWriter, freeIndexWriter) return ixWriter }
func (index *Index) GetIndexWriter(flags IndexOpenFlags) IndexWriter { idxLocation := cb_newf(index.Location) index.lucyIndexer = C.LucyIndexerNew(index.Schema.lucySchema, idxLocation, nil, C.int32_t(flags)) C.DECREF(idxLocation) return func(ixValueColumns ...*IndexValueColumn) { doc := C.LucyDocNew(nil, 0) for _, ixColumn := range ixValueColumns { fieldName := cb_newf(ixColumn.Field) fieldValue := cb_new_from_utf8(ixColumn.Value) C.LucyDocStore(doc, fieldName, fieldValue) C.DECREF(fieldName) C.DECREF(fieldValue) } C.LucyIndexerAddDoc(index.lucyIndexer, doc, 1.0) C.DECREF(doc) } }