Example #1
0
func i32ArrayToSlice(a *C.lucy_I32Array) []int32 {
	size := int(C.LUCY_I32Arr_Get_Size(a))
	nums := make([]int32, size)
	for i := 0; i < size; i++ {
		nums[i] = int32(C.LUCY_I32Arr_Get(a, C.size_t(i)))
	}
	return nums
}
Example #2
0
File: lucy.go Project: apache/lucy
func readDocPolyDR(pdr *C.lucy_PolyDocReader, docID int32, doc interface{}) error {
	ivars := C.lucy_PolyDocReader_IVARS(pdr)
	segTick := C.lucy_PolyReader_sub_tick(ivars.offsets, C.int32_t(docID))
	offset := C.LUCY_I32Arr_Get(ivars.offsets, C.size_t(segTick))
	defDocReader := (*C.lucy_DefaultDocReader)(C.CFISH_Vec_Fetch(ivars.readers, C.size_t(segTick)))
	if defDocReader == nil {
		return clownfish.NewErr(fmt.Sprintf("Invalid docID: %d", docID))
	}
	if !C.cfish_Obj_is_a((*C.cfish_Obj)(unsafe.Pointer(defDocReader)), C.LUCY_DEFAULTDOCREADER) {
		panic(clownfish.NewErr("Unexpected type")) // sanity check
	}
	adjustedDocID := docID - int32(offset)
	err := doReadDocData(defDocReader, adjustedDocID, doc)
	if docDoc, ok := doc.(Doc); ok {
		docDoc.SetDocID(docID)
	}
	return err
}