コード例 #1
0
ファイル: clownfish.go プロジェクト: rectang/lucy-clownfish
func goToBoolean(value interface{}, nullable bool) unsafe.Pointer {
	switch v := value.(type) {
	case bool:
		if v {
			return unsafe.Pointer(C.cfish_incref(unsafe.Pointer(C.CFISH_TRUE)))
		} else {
			return unsafe.Pointer(C.cfish_incref(unsafe.Pointer(C.CFISH_FALSE)))
		}
	case Obj:
		certifyCF(v, C.CFISH_BOOLEAN, nullable)
		return unsafe.Pointer(C.cfish_incref(unsafe.Pointer(v.TOPTR())))
	}
	mess := fmt.Sprintf("Can't convert %T to clownfish.Boolean", value)
	panic(NewErr(mess))
}
コード例 #2
0
ファイル: search.go プロジェクト: rlugojr/lucy
func (h *HitsIMP) Next(hit interface{}) bool {
	self := (*C.lucy_Hits)(clownfish.Unwrap(h, "h"))
	ivars := C.lucy_Hits_IVARS(self)
	matchDoc := (*C.lucy_MatchDoc)(unsafe.Pointer(
		C.CFISH_Vec_Fetch(ivars.match_docs, C.size_t(ivars.offset))))
	ivars.offset += 1

	if matchDoc == nil {
		// Bail if there aren't any more *captured* hits.  (There may be
		// more total hits.)
		return false
	} else {
		// Lazily fetch HitDoc, set score.
		searcher := clownfish.WRAPAny(unsafe.Pointer(C.cfish_incref(
			unsafe.Pointer(ivars.searcher)))).(Searcher)
		docID := int32(C.LUCY_MatchDoc_Get_Doc_ID(matchDoc))
		err := searcher.ReadDoc(docID, hit)
		if err != nil {
			h.err = err
			return false
		}
		if ss, ok := hit.(setScorer); ok {
			ss.SetScore(float32(C.LUCY_MatchDoc_Get_Score(matchDoc)))
		}
		return true
	}
}
コード例 #3
0
ファイル: clownfish.go プロジェクト: rectang/lucy-clownfish
func goToHash(value interface{}, nullable bool) unsafe.Pointer {
	switch v := value.(type) {
	case map[string]interface{}:
		if v == nil {
			if nullable {
				return nil
			}
		} else {
			size := len(v)
			hash := C.cfish_Hash_new(C.size_t(size))
			for key, val := range v {
				newVal := GoToClownfish(val, nil, true)
				keySize := len(key)
				keyStr := C.CString(key)
				cfKey := C.cfish_Str_new_steal_utf8(keyStr, C.size_t(keySize))
				defer C.cfish_dec_refcount(unsafe.Pointer(cfKey))
				C.CFISH_Hash_Store(hash, cfKey, (*C.cfish_Obj)(newVal))
			}
			return unsafe.Pointer(hash)
		}
	case Obj:
		certifyCF(v, C.CFISH_HASH, nullable)
		return unsafe.Pointer(C.cfish_incref(unsafe.Pointer(v.TOPTR())))
	}
	mess := fmt.Sprintf("Can't convert %T to clownfish.Hash", value)
	panic(NewErr(mess))
}
コード例 #4
0
ファイル: clownfish.go プロジェクト: rectang/lucy-clownfish
func ToGo(ptr unsafe.Pointer) interface{} {
	if ptr == nil {
		return nil
	}
	class := C.cfish_Obj_get_class((*C.cfish_Obj)(ptr))
	if class == C.CFISH_STRING {
		return CFStringToGo(ptr)
	} else if class == C.CFISH_BLOB {
		return BlobToGo(ptr)
	} else if class == C.CFISH_VECTOR {
		return VectorToGo(ptr)
	} else if class == C.CFISH_HASH {
		return HashToGo(ptr)
	} else if class == C.CFISH_BOOLEAN {
		if ptr == unsafe.Pointer(C.CFISH_TRUE) {
			return true
		} else {
			return false
		}
	} else if class == C.CFISH_INTEGER {
		val := C.CFISH_Int_Get_Value((*C.cfish_Integer)(ptr))
		return int64(val)
	} else if class == C.CFISH_FLOAT {
		val := C.CFISH_Float_Get_Value((*C.cfish_Float)(ptr))
		return float64(val)
	} else {
		// Don't convert to a native Go type, but wrap in a Go struct.
		return WRAPAny(unsafe.Pointer(C.cfish_incref(unsafe.Pointer(ptr))))
	}
}
コード例 #5
0
ファイル: lucy.go プロジェクト: lazycrazyowl/lucy
//export GOLUCY_Doc_Field_Names
func GOLUCY_Doc_Field_Names(d *C.lucy_Doc) *C.cfish_Vector {
	fields := fetchDocFields(d)
	vec := clownfish.NewVector(len(fields))
	for key, _ := range fields {
		vec.Push(key)
	}
	return (*C.cfish_Vector)(C.cfish_incref(clownfish.Unwrap(vec, "vec")))
}
コード例 #6
0
ファイル: clownfish.go プロジェクト: rectang/lucy-clownfish
//export GoCfish_TrapErr_internal
func GoCfish_TrapErr_internal(routine C.CFISH_Err_Attempt_t,
	context unsafe.Pointer) *C.cfish_Err {
	err := TrapErr(func() { C.GoCfish_RunRoutine(routine, context) })
	if err != nil {
		ptr := (err.(Err)).TOPTR()
		return ((*C.cfish_Err)(unsafe.Pointer(C.cfish_incref(unsafe.Pointer(ptr)))))
	}
	return nil
}
コード例 #7
0
ファイル: store.go プロジェクト: rlugojr/lucy
func (lock *LockIMP) Obtain() error {
	self := (*C.lucy_Lock)(clownfish.Unwrap(lock, "lock"))
	success := C.LUCY_Lock_Obtain(self)
	if !success {
		cfErr := C.cfish_Err_get_error()
		return clownfish.WRAPAny(unsafe.Pointer(C.cfish_incref(unsafe.Pointer(cfErr)))).(error)
	}
	return nil
}
コード例 #8
0
ファイル: store.go プロジェクト: rlugojr/lucy
func (fh *FileHandleIMP) ReleaseWindow(window FileWindow) error {
	self := (*C.lucy_FileHandle)(clownfish.Unwrap(fh, "fh"))
	windowC := (*C.lucy_FileWindow)(clownfish.Unwrap(window, "window"))
	success := C.LUCY_FH_Release_Window(self, windowC)
	if !success {
		cfErr := C.cfish_Err_get_error()
		return clownfish.WRAPAny(unsafe.Pointer(C.cfish_incref(unsafe.Pointer(cfErr)))).(error)
	}
	return nil
}
コード例 #9
0
ファイル: store.go プロジェクト: rlugojr/lucy
func (fh *FileHandleIMP) Window(window FileWindow, offset, length int64) error {
	self := (*C.lucy_FileHandle)(clownfish.Unwrap(fh, "fh"))
	windowC := (*C.lucy_FileWindow)(clownfish.Unwrap(window, "window"))
	success := C.LUCY_FH_Window(self, windowC, C.int64_t(offset), C.int64_t(length))
	if !success {
		cfErr := C.cfish_Err_get_error()
		return clownfish.WRAPAny(unsafe.Pointer(C.cfish_incref(unsafe.Pointer(cfErr)))).(error)
	}
	return nil
}
コード例 #10
0
ファイル: index.go プロジェクト: rlugojr/lucy
func (r *IndexReaderIMP) Obtain(api string) (retval DataReader, err error) {
	err = clownfish.TrapErr(func() {
		self := (*C.lucy_IndexReader)(clownfish.Unwrap(r, "r"))
		apiC := (*C.cfish_String)(clownfish.GoToClownfish(api, unsafe.Pointer(C.CFISH_STRING), false))
		defer C.cfish_decref(unsafe.Pointer(apiC))
		retvalCF := C.LUCY_IxReader_Obtain(self, apiC)
		retval = clownfish.WRAPAny(unsafe.Pointer(C.cfish_incref(unsafe.Pointer(retvalCF)))).(DataReader)
	})
	return retval, err
}
コード例 #11
0
ファイル: store.go プロジェクト: rlugojr/lucy
func (f *FolderIMP) LocalMkDir(name string) error {
	self := (*C.lucy_Folder)(clownfish.Unwrap(f, "f"))
	nameC := (*C.cfish_String)(clownfish.GoToClownfish(name, unsafe.Pointer(C.CFISH_STRING), false))
	defer C.cfish_decref(unsafe.Pointer(nameC))
	success := C.LUCY_Folder_Local_MkDir(self, nameC)
	if !success {
		cfErr := C.cfish_Err_get_error()
		return clownfish.WRAPAny(unsafe.Pointer(C.cfish_incref(unsafe.Pointer(cfErr)))).(error)
	}
	return nil
}
コード例 #12
0
ファイル: search.go プロジェクト: rlugojr/lucy
func (spec *SortSpecIMP) GetRules() []SortRule {
	self := (*C.lucy_SortSpec)(clownfish.Unwrap(spec, "spec"))
	vec := C.LUCY_SortSpec_Get_Rules(self)
	length := int(C.CFISH_Vec_Get_Size(vec))
	slice := make([]SortRule, length)
	for i := 0; i < length; i++ {
		elem := C.cfish_incref(unsafe.Pointer(C.CFISH_Vec_Fetch(vec, C.size_t(i))))
		slice[i] = WRAPSortRule(unsafe.Pointer(elem))
	}
	return slice
}
コード例 #13
0
ファイル: search.go プロジェクト: rlugojr/lucy
func (td *TopDocsIMP) GetMatchDocs() []MatchDoc {
	self := (*C.lucy_TopDocs)(clownfish.Unwrap(td, "td"))
	vec := C.LUCY_TopDocs_Get_Match_Docs(self)
	length := int(C.CFISH_Vec_Get_Size(vec))
	slice := make([]MatchDoc, length)
	for i := 0; i < length; i++ {
		elem := C.cfish_incref(unsafe.Pointer(C.CFISH_Vec_Fetch(vec, C.size_t(i))))
		slice[i] = WRAPMatchDoc(unsafe.Pointer(elem))
	}
	return slice
}
コード例 #14
0
ファイル: analysis.go プロジェクト: rlugojr/lucy
func (p *PolyAnalyzerIMP) GetAnalyzers() []Analyzer {
	self := (*C.lucy_PolyAnalyzer)(clownfish.Unwrap(p, "p"))
	retvalCF := C.LUCY_PolyAnalyzer_Get_Analyzers(self)
	size := C.CFISH_Vec_Get_Size(retvalCF)
	retval := make([]Analyzer, int(size))
	for i := 0; i < int(size); i++ {
		child := unsafe.Pointer(C.CFISH_Vec_Fetch(retvalCF, C.size_t(i)))
		retval[i] = clownfish.WRAPAny(unsafe.Pointer(C.cfish_incref(child))).(Analyzer)
	}
	return retval
}
コード例 #15
0
ファイル: highlight.go プロジェクト: rlugojr/lucy
func spanSliceToVec(slice []Span) *C.cfish_Vector {
	if slice == nil {
		return nil
	}
	length := len(slice)
	vec := C.cfish_Vec_new(C.size_t(length))
	for i := 0; i < length; i++ {
		elem := clownfish.Unwrap(slice[i], "slice[i]")
		C.CFISH_Vec_Push(vec, C.cfish_incref(elem))
	}
	return vec
}
コード例 #16
0
ファイル: store.go プロジェクト: rlugojr/lucy
func (f *FolderIMP) LocalOpenDir() (retval DirHandle, err error) {
	err = clownfish.TrapErr(func() {
		self := (*C.lucy_Folder)(clownfish.Unwrap(f, "f"))
		retvalC := C.LUCY_Folder_Local_Open_Dir(self)
		if retvalC == nil {
			cfErr := C.cfish_Err_get_error()
			panic(clownfish.WRAPAny(unsafe.Pointer(C.cfish_incref(unsafe.Pointer(cfErr)))).(error))
		}
		retval = WRAPDirHandle(unsafe.Pointer(retvalC))
	})
	return retval, err
}
コード例 #17
0
ファイル: store.go プロジェクト: rlugojr/lucy
func OpenCompoundFileReader(folder Folder) (reader CompoundFileReader, err error) {
	err = clownfish.TrapErr(func() {
		folderC := (*C.lucy_Folder)(clownfish.Unwrap(folder, "Folder"))
		cfObj := C.lucy_CFReader_open(folderC)
		if cfObj == nil {
			cfErr := C.cfish_Err_get_error()
			panic(clownfish.WRAPAny(unsafe.Pointer(C.cfish_incref(unsafe.Pointer(cfErr)))).(error))
		}
		reader = WRAPCompoundFileReader(unsafe.Pointer(cfObj))
	})
	return reader, err
}
コード例 #18
0
ファイル: index.go プロジェクト: rlugojr/lucy
func (s *SortReaderIMP) fetchSortCache(field string) (retval SortCache, err error) {
	err = clownfish.TrapErr(func() {
		self := (*C.lucy_SortReader)(clownfish.Unwrap(s, "s"))
		fieldC := (*C.cfish_String)(clownfish.GoToClownfish(field, unsafe.Pointer(C.CFISH_STRING), false))
		defer C.cfish_decref(unsafe.Pointer(fieldC))
		retvalCF := C.LUCY_SortReader_Fetch_Sort_Cache(self, fieldC)
		if retvalCF != nil {
			retval = clownfish.ToGo(unsafe.Pointer(C.cfish_incref(unsafe.Pointer(retvalCF)))).(SortCache)
		}
	})
	return retval, err
}
コード例 #19
0
ファイル: search.go プロジェクト: rlugojr/lucy
func (sc *SortCollectorIMP) PopMatchDocs() []MatchDoc {
	self := (*C.lucy_SortCollector)(clownfish.Unwrap(sc, "sc"))
	matchDocsC := C.LUCY_SortColl_Pop_Match_Docs(self)
	defer C.cfish_decref(unsafe.Pointer(matchDocsC))
	length := int(C.CFISH_Vec_Get_Size(matchDocsC))
	slice := make([]MatchDoc, length)
	for i := 0; i < length; i++ {
		elem := C.cfish_incref(unsafe.Pointer(C.CFISH_Vec_Fetch(matchDocsC, C.size_t(i))))
		slice[i] = WRAPMatchDoc(unsafe.Pointer(elem))
	}
	return slice
}
コード例 #20
0
ファイル: store.go プロジェクト: rlugojr/lucy
func OpenFSDirHandle(path string) (dh FSDirHandle, err error) {
	err = clownfish.TrapErr(func() {
		pathC := (*C.cfish_String)(clownfish.GoToClownfish(path, unsafe.Pointer(C.CFISH_STRING), false))
		defer C.cfish_decref(unsafe.Pointer(pathC))
		cfObj := C.lucy_FSDH_open(pathC)
		if cfObj == nil {
			cfErr := C.cfish_Err_get_error()
			panic(clownfish.WRAPAny(unsafe.Pointer(C.cfish_incref(unsafe.Pointer(cfErr)))).(error))
		}
		dh = WRAPFSDirHandle(unsafe.Pointer(cfObj))
	})
	return dh, err
}
コード例 #21
0
ファイル: store.go プロジェクト: rlugojr/lucy
func OpenOutStream(file interface{}) (out OutStream, err error) {
	err = clownfish.TrapErr(func() {
		fileC := (*C.cfish_Obj)(clownfish.GoToClownfish(file, unsafe.Pointer(C.CFISH_OBJ), false))
		defer C.cfish_decref(unsafe.Pointer(fileC))
		cfObj := C.lucy_OutStream_open(fileC)
		if cfObj == nil {
			cfErr := C.cfish_Err_get_error()
			panic(clownfish.WRAPAny(unsafe.Pointer(C.cfish_incref(unsafe.Pointer(cfErr)))).(error))
		}
		out = WRAPOutStream(unsafe.Pointer(cfObj))
	})
	return out, err
}
コード例 #22
0
ファイル: store.go プロジェクト: rlugojr/lucy
func (f *FolderIMP) HardLink(from, to string) error {
	self := (*C.lucy_Folder)(clownfish.Unwrap(f, "f"))
	fromC := (*C.cfish_String)(clownfish.GoToClownfish(from, unsafe.Pointer(C.CFISH_STRING), false))
	toC := (*C.cfish_String)(clownfish.GoToClownfish(to, unsafe.Pointer(C.CFISH_STRING), false))
	defer C.cfish_decref(unsafe.Pointer(fromC))
	defer C.cfish_decref(unsafe.Pointer(toC))
	success := C.LUCY_Folder_Hard_Link(self, fromC, toC)
	if !success {
		cfErr := C.cfish_Err_get_error()
		return clownfish.WRAPAny(unsafe.Pointer(C.cfish_incref(unsafe.Pointer(cfErr)))).(error)
	}
	return nil
}
コード例 #23
0
ファイル: clownfish.go プロジェクト: rectang/lucy-clownfish
func goToFloat(value interface{}, nullable bool) unsafe.Pointer {
	switch v := value.(type) {
	case float32:
		return unsafe.Pointer(C.cfish_Float_new(C.double(v)))
	case float64:
		return unsafe.Pointer(C.cfish_Float_new(C.double(v)))
	case Obj:
		certifyCF(v, C.CFISH_FLOAT, nullable)
		return unsafe.Pointer(C.cfish_incref(unsafe.Pointer(v.TOPTR())))
	}
	mess := fmt.Sprintf("Can't convert %T to clownfish.Float", value)
	panic(NewErr(mess))
}
コード例 #24
0
ファイル: clownfish.go プロジェクト: rectang/lucy-clownfish
func goToString(value interface{}, nullable bool) unsafe.Pointer {
	switch v := value.(type) {
	case string:
		size := len(v)
		str := C.CString(v)
		return unsafe.Pointer(C.cfish_Str_new_steal_utf8(str, C.size_t(size)))
	case Obj:
		certifyCF(v, C.CFISH_STRING, nullable)
		return unsafe.Pointer(C.cfish_incref(unsafe.Pointer(v.TOPTR())))
	}
	mess := fmt.Sprintf("Can't convert %T to clownfish.String", value)
	panic(NewErr(mess))
}
コード例 #25
0
ファイル: clownfish.go プロジェクト: rectang/lucy-clownfish
// Convert a Go type into an incremented Clownfish object.  If the supplied
// object is a Clownfish object wrapped in a Go struct, extract the Clownfish
// object and incref it before returning its address.
func GoToClownfish(value interface{}, class unsafe.Pointer, nullable bool) unsafe.Pointer {
	klass := (*C.cfish_Class)(class)

	// Default to accepting any type.
	if klass == nil {
		klass = C.CFISH_OBJ
	}

	// Convert the value according to its type if possible.
	switch v := value.(type) {
	case string:
		if klass == C.CFISH_STRING || klass == C.CFISH_OBJ {
			return goToString(value, nullable)
		}
	case []byte:
		if klass == C.CFISH_BLOB || klass == C.CFISH_OBJ {
			return goToBlob(value, nullable)
		}
	case int, uint, uintptr, int64, int32, int16, int8, uint64, uint32, uint16, uint8:
		if klass == C.CFISH_INTEGER || klass == C.CFISH_OBJ {
			return goToInteger(value, nullable)
		}
	case float32, float64:
		if klass == C.CFISH_FLOAT || klass == C.CFISH_OBJ {
			return goToFloat(value, nullable)
		}
	case bool:
		if klass == C.CFISH_BOOLEAN || klass == C.CFISH_OBJ {
			return goToBoolean(value, nullable)
		}
	case []interface{}:
		if klass == C.CFISH_VECTOR || klass == C.CFISH_OBJ {
			return goToVector(value, nullable)
		}
	case map[string]interface{}:
		if klass == C.CFISH_HASH || klass == C.CFISH_OBJ {
			return goToHash(value, nullable)
		}
	case Obj:
		certifyCF(value, klass, nullable)
		return unsafe.Pointer(C.cfish_incref(unsafe.Pointer(v.TOPTR())))
	case nil:
		if nullable {
			return nil
		}
	}

	// Report a conversion error.
	className := StringToGo(unsafe.Pointer(C.CFISH_Class_Get_Name(klass)))
	panic(NewErr(fmt.Sprintf("Can't convert a %T to %s", value, className)))
}
コード例 #26
0
ファイル: index.go プロジェクト: rlugojr/lucy
func (d *DataReaderIMP) GetSegments() []Segment {
	self := (*C.lucy_DataReader)(clownfish.Unwrap(d, "d"))
	retvalCF := C.LUCY_DataReader_Get_Segments(self)
	if retvalCF == nil {
		return nil
	}
	size := C.CFISH_Vec_Get_Size(retvalCF)
	retval := make([]Segment, int(size))
	for i := 0; i < int(size); i++ {
		elem := unsafe.Pointer(C.CFISH_Vec_Fetch(retvalCF, C.size_t(i)))
		retval[i] = clownfish.ToGo(unsafe.Pointer(C.cfish_incref(elem))).(Segment)
	}
	return retval
}
コード例 #27
0
ファイル: store.go プロジェクト: rlugojr/lucy
func (f *FolderIMP) OpenDir(path string) (retval DirHandle, err error) {
	err = clownfish.TrapErr(func() {
		self := (*C.lucy_Folder)(clownfish.Unwrap(f, "f"))
		pathC := (*C.cfish_String)(clownfish.GoToClownfish(path, unsafe.Pointer(C.CFISH_STRING), false))
		defer C.cfish_decref(unsafe.Pointer(pathC))
		retvalC := C.LUCY_Folder_Open_Dir(self, pathC)
		if retvalC == nil {
			cfErr := C.cfish_Err_get_error()
			panic(clownfish.WRAPAny(unsafe.Pointer(C.cfish_incref(unsafe.Pointer(cfErr)))).(error))
		}
		retval = WRAPDirHandle(unsafe.Pointer(retvalC))
	})
	return retval, err
}
コード例 #28
0
ファイル: store.go プロジェクト: rlugojr/lucy
func (f *FolderIMP) LocalOpenFileHandle(name string, flags uint32) (retval FileHandle, err error) {
	err = clownfish.TrapErr(func() {
		self := (*C.lucy_Folder)(clownfish.Unwrap(f, "f"))
		nameC := (*C.cfish_String)(clownfish.GoToClownfish(name, unsafe.Pointer(C.CFISH_STRING), false))
		defer C.cfish_decref(unsafe.Pointer(nameC))
		retvalC := C.LUCY_Folder_Local_Open_FileHandle(self, nameC, C.uint32_t(flags))
		if retvalC == nil {
			cfErr := C.cfish_Err_get_error()
			panic(clownfish.WRAPAny(unsafe.Pointer(C.cfish_incref(unsafe.Pointer(cfErr)))).(error))
		}
		retval = WRAPFileHandle(unsafe.Pointer(retvalC))
	})
	return retval, err
}
コード例 #29
0
ファイル: store.go プロジェクト: rlugojr/lucy
func OpenRAMFileHandle(path string, flags uint32, ramFile RAMFile) (fh RAMFileHandle, err error) {
	err = clownfish.TrapErr(func() {
		pathC := (*C.cfish_String)(clownfish.GoToClownfish(path, unsafe.Pointer(C.CFISH_STRING), false))
		ramFileC := (*C.lucy_RAMFile)(clownfish.GoToClownfish(ramFile, unsafe.Pointer(C.LUCY_RAMFILE), true))
		defer C.cfish_decref(unsafe.Pointer(pathC))
		cfObj := C.lucy_RAMFH_open(pathC, C.uint32_t(flags), ramFileC)
		if cfObj == nil {
			cfErr := C.cfish_Err_get_error()
			panic(clownfish.WRAPAny(unsafe.Pointer(C.cfish_incref(unsafe.Pointer(cfErr)))).(error))
		}
		fh = WRAPRAMFileHandle(unsafe.Pointer(cfObj))
	})
	return fh, err
}
コード例 #30
0
ファイル: index.go プロジェクト: rlugojr/lucy
func (r *IndexReaderIMP) SegReaders() []SegReader {
	self := (*C.lucy_IndexReader)(clownfish.Unwrap(r, "r"))
	retvalCF := C.LUCY_IxReader_Seg_Readers(self)
	defer C.cfish_decref(unsafe.Pointer(retvalCF))
	if retvalCF == nil {
		return nil
	}
	size := C.CFISH_Vec_Get_Size(retvalCF)
	retval := make([]SegReader, int(size))
	for i := 0; i < int(size); i++ {
		elem := unsafe.Pointer(C.CFISH_Vec_Fetch(retvalCF, C.size_t(i)))
		retval[i] = clownfish.ToGo(unsafe.Pointer(C.cfish_incref(elem))).(SegReader)
	}
	return retval
}