本文整理匯總了Golang中git-wip-us/apache/org/repos/asf/lucy-clownfish/git/runtime/go/clownfish.NewErr函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewErr函數的具體用法?Golang NewErr怎麽用?Golang NewErr使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewErr函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GOLUCY_Inverter_Invert_Doc
//export GOLUCY_Inverter_Invert_Doc
func GOLUCY_Inverter_Invert_Doc(inverter *C.lucy_Inverter, doc *C.lucy_Doc) {
ivars := C.lucy_Inverter_IVARS(inverter)
fields := (*C.cfish_Hash)(C.LUCY_Doc_Get_Fields(doc))
// Prepare for the new doc.
C.LUCY_Inverter_Set_Doc(inverter, doc)
// Extract and invert the doc's fields.
iter := C.cfish_HashIter_new(fields)
for C.CFISH_HashIter_Next(iter) {
field := C.CFISH_HashIter_Get_Key(iter)
obj := C.CFISH_HashIter_Get_Value(iter)
if obj == nil {
mess := "Invalid nil value for field" + clownfish.CFStringToGo(unsafe.Pointer(field))
panic(clownfish.NewErr(mess))
}
inventry := fetchEntry(ivars, field)
inventryIvars := C.lucy_InvEntry_IVARS(inventry)
fieldType := inventryIvars._type
// Get the field value.
var expectedType *C.cfish_Class
switch C.LUCY_FType_Primitive_ID(fieldType) & C.lucy_FType_PRIMITIVE_ID_MASK {
case C.lucy_FType_TEXT:
expectedType = C.CFISH_STRING
case C.lucy_FType_BLOB:
expectedType = C.CFISH_BLOB
case C.lucy_FType_INT32:
expectedType = C.CFISH_INTEGER
case C.lucy_FType_INT64:
expectedType = C.CFISH_INTEGER
case C.lucy_FType_FLOAT32:
expectedType = C.CFISH_FLOAT
case C.lucy_FType_FLOAT64:
expectedType = C.CFISH_FLOAT
default:
panic(clownfish.NewErr("Internal Lucy error: bad type id for field " +
clownfish.CFStringToGo(unsafe.Pointer(field))))
}
if !C.cfish_Obj_is_a(obj, expectedType) {
className := C.cfish_Obj_get_class_name((*C.cfish_Obj)(unsafe.Pointer(fieldType)))
mess := fmt.Sprintf("Invalid type for field '%s': '%s'",
clownfish.CFStringToGo(unsafe.Pointer(field)),
clownfish.CFStringToGo(unsafe.Pointer(className)))
panic(clownfish.NewErr(mess))
}
if inventryIvars.value != obj {
C.cfish_decref(unsafe.Pointer(inventryIvars.value))
inventryIvars.value = C.cfish_inc_refcount(unsafe.Pointer(obj))
}
C.LUCY_Inverter_Add_Field(inverter, inventry)
}
C.cfish_dec_refcount(unsafe.Pointer(iter))
}
示例2: fetchEntry
func fetchEntry(ivars *C.lucy_InverterIVARS, fieldGo string) *C.lucy_InverterEntry {
field := (*C.cfish_String)(clownfish.GoToClownfish(fieldGo,
unsafe.Pointer(C.CFISH_STRING), false))
defer C.cfish_decref(unsafe.Pointer(field))
schema := ivars.schema
fieldNum := C.LUCY_Seg_Field_Num(ivars.segment, field)
if fieldNum == 0 {
// This field seems not to be in the segment yet. Try to find it in
// the Schema.
if C.LUCY_Schema_Fetch_Type(schema, field) != nil {
// The field is in the Schema. Get a field num from the Segment.
fieldNum = C.LUCY_Seg_Add_Field(ivars.segment, field)
} else {
// We've truly failed to find the field. The user must
// not have spec'd it.
fieldGo := clownfish.CFStringToGo(unsafe.Pointer(field))
err := clownfish.NewErr("Unknown field name: '" + fieldGo + "'")
panic(err)
}
}
entry := C.CFISH_Vec_Fetch(ivars.entry_pool, C.size_t(fieldNum))
if entry == nil {
newEntry := C.lucy_InvEntry_new(schema, field, fieldNum)
C.CFISH_Vec_Store(ivars.entry_pool, C.size_t(fieldNum),
(*C.cfish_Obj)(unsafe.Pointer(entry)))
return newEntry
}
return (*C.lucy_InverterEntry)(unsafe.Pointer(entry))
}
示例3: ReadDoc
// Read data into the supplied doc.
func (s *SearcherIMP) ReadDoc(docID int32, doc interface{}) error {
self := (*C.lucy_Searcher)(clownfish.Unwrap(s, "s"))
class := C.cfish_Obj_get_class((*C.cfish_Obj)(unsafe.Pointer(self)))
if class == C.LUCY_INDEXSEARCHER {
ixReader := C.LUCY_IxSearcher_Get_Reader((*C.lucy_IndexSearcher)(unsafe.Pointer(self)))
cfStr := (*C.cfish_String)(clownfish.GoToClownfish("Lucy::Index::DocReader", unsafe.Pointer(C.CFISH_STRING), false))
defer C.cfish_decref(unsafe.Pointer(cfStr))
docReader := C.LUCY_IxReader_Fetch(ixReader, cfStr)
if docReader == nil {
return clownfish.NewErr("No DocReader available")
}
docReaderGo := clownfish.WRAPAny(unsafe.Pointer(C.cfish_incref(unsafe.Pointer(docReader)))).(DocReader)
return docReaderGo.ReadDoc(docID, doc)
} else {
return clownfish.NewErr("Support for ReadDoc not implemented")
}
}
示例4: fetchDocFields
func fetchDocFields(d *C.lucy_Doc) map[string]interface{} {
ivars := C.lucy_Doc_IVARS(d)
fieldsID := uintptr(ivars.fields)
fieldsGo, ok := registry.fetch(fieldsID).(map[string]interface{})
if !ok {
panic(clownfish.NewErr(fmt.Sprintf("Failed to fetch doc %d from registry ", fieldsID)))
}
return fieldsGo
}
示例5: readDocPolyDR
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
}
示例6: fetchDocFromDocReader
func fetchDocFromDocReader(dr DocReader, docID int32, doc interface{}) error {
switch v := dr.(type) {
case *DefaultDocReaderIMP:
return v.readDoc(docID, doc)
case *PolyDocReaderIMP:
return v.readDoc(docID, doc)
default:
panic(clownfish.NewErr(fmt.Sprintf("Unexpected type: %T", v)))
}
}
示例7: NewI32Array
func NewI32Array(nums []int32) I32Array {
size := len(nums)
if int(C.size_t(size)) != size {
panic(clownfish.NewErr("input too large"))
}
obj := C.lucy_I32Arr_new_blank(C.size_t(size))
for i := 0; i < size; i++ {
C.LUCY_I32Arr_Set(obj, C.size_t(i), C.int32_t(nums[i]))
}
return WRAPI32Array(unsafe.Pointer(obj))
}
示例8: ReadDoc
func (d *DocReaderIMP) ReadDoc(docID int32, doc interface{}) error {
self := (*C.lucy_DocReader)(clownfish.Unwrap(d, "d"))
class := clownfish.GetClass(d)
classC := ((*C.cfish_Class)(clownfish.Unwrap(class, "class")))
if classC == C.LUCY_DEFAULTDOCREADER {
return doReadDocData((*C.lucy_DefaultDocReader)(self), docID, doc)
} else if classC == C.LUCY_POLYDOCREADER {
return readDocPolyDR((*C.lucy_PolyDocReader)(self), docID, doc)
} else {
panic(clownfish.NewErr(fmt.Sprintf("Unexpected type: %s", class.GetName)))
}
}
示例9: Write
func (fh *FileHandleIMP) Write(data []byte, size int) error {
return clownfish.TrapErr(func() {
self := (*C.lucy_FileHandle)(clownfish.Unwrap(fh, "fh"))
if size > len(data) {
panic(clownfish.NewErr(fmt.Sprintf("Buf only %d long, can't write %d bytes",
len(data), size)))
}
octets := C.CString(string(data))
defer C.free(unsafe.Pointer(octets))
C.LUCY_FH_Write(self, unsafe.Pointer(octets), C.size_t(size))
})
}
示例10: WriteBytes
func (out *OutStreamIMP) WriteBytes(content []byte, size int) error {
return clownfish.TrapErr(func() {
self := (*C.lucy_OutStream)(clownfish.Unwrap(out, "out"))
if size > len(content) {
panic(clownfish.NewErr(fmt.Sprintf("Buf only %d long, can't write %d bytes",
len(content), size)))
}
octets := C.CString(string(content))
defer C.free(unsafe.Pointer(octets))
C.LUCY_OutStream_Write_Bytes(self, unsafe.Pointer(octets), C.size_t(size))
})
}
示例11: Next
func (obj *HitsIMP) Next(hit interface{}) bool {
self := ((*C.lucy_Hits)(unsafe.Pointer(obj.TOPTR())))
// TODO: accept a HitDoc object and populate score.
// Get reflection value and type for the supplied struct.
var hitValue reflect.Value
if reflect.ValueOf(hit).Kind() == reflect.Ptr {
temp := reflect.ValueOf(hit).Elem()
if temp.Kind() == reflect.Struct {
if temp.CanSet() {
hitValue = temp
}
}
}
if hitValue == (reflect.Value{}) {
mess := fmt.Sprintf("Arg not writeable struct pointer: %v",
reflect.TypeOf(hit))
obj.err = clownfish.NewErr(mess)
return false
}
var docC *C.lucy_HitDoc
errCallingNext := clownfish.TrapErr(func() {
docC = C.LUCY_Hits_Next(self)
})
if errCallingNext != nil {
obj.err = errCallingNext
return false
}
if docC == nil {
return false
}
defer C.cfish_dec_refcount(unsafe.Pointer(docC))
fields := (*C.cfish_Hash)(unsafe.Pointer(C.LUCY_HitDoc_Get_Fields(docC)))
iterator := C.cfish_HashIter_new(fields)
defer C.cfish_dec_refcount(unsafe.Pointer(iterator))
for C.CFISH_HashIter_Next(iterator) {
keyC := C.CFISH_HashIter_Get_Key(iterator)
valC := C.CFISH_HashIter_Get_Value(iterator)
key := clownfish.CFStringToGo(unsafe.Pointer(keyC))
val := clownfish.CFStringToGo(unsafe.Pointer(valC))
match := func(name string) bool {
return strings.EqualFold(key, name)
}
structField := hitValue.FieldByNameFunc(match)
if structField != (reflect.Value{}) {
structField.SetString(val)
}
}
return true
}
示例12: AddDoc
func (s *SimpleIMP) AddDoc(doc interface{}) error {
self := (*C.lucy_Simple)(clownfish.Unwrap(s, "s"))
indexer := s.getIndexer()
var docToIndex Doc
stockDoc := indexer.getStockDoc()
stockDocC := (*C.lucy_Doc)(clownfish.Unwrap(stockDoc, "stockDoc"))
docFields := fetchDocFields(stockDocC)
for field := range docFields {
delete(docFields, field)
}
switch d := doc.(type) {
case map[string]interface{}:
for k, v := range d {
docFields[k] = v
}
docToIndex = stockDoc
case Doc:
docToIndex = d
default:
docToIndex = stockDoc
// Get reflection value and type for the supplied struct.
var docValue reflect.Value
var success bool
if reflect.ValueOf(doc).Kind() == reflect.Ptr {
temp := reflect.ValueOf(doc).Elem()
if temp.Kind() == reflect.Struct {
docValue = temp
success = true
}
}
if !success {
mess := fmt.Sprintf("Unexpected type for doc: %T", doc)
return clownfish.NewErr(mess)
}
// Copy field values into stockDoc.
docType := docValue.Type()
for i := 0; i < docValue.NumField(); i++ {
field := docType.Field(i).Name
value := docValue.Field(i).String()
docFields[field] = value
}
}
return clownfish.TrapErr(func() {
docC := (*C.lucy_Doc)(clownfish.Unwrap(docToIndex, "docToIndex"))
C.LUCY_Simple_Add_Doc(self, docC)
})
}
示例13: AddDoc
func (obj *IndexerIMP) AddDoc(doc interface{}) error {
self := ((*C.lucy_Indexer)(unsafe.Pointer(obj.TOPTR())))
stockDoc := C.LUCY_Indexer_Get_Stock_Doc(self)
docFields := (*C.cfish_Hash)(C.LUCY_Doc_Get_Fields(stockDoc))
C.CFISH_Hash_Clear(docFields)
// TODO: Support map as doc in addition to struct as doc.
// Get reflection value and type for the supplied struct.
var docValue reflect.Value
if reflect.ValueOf(doc).Kind() == reflect.Ptr {
temp := reflect.ValueOf(doc).Elem()
if temp.Kind() == reflect.Struct {
docValue = temp
}
}
if docValue == (reflect.Value{}) {
mess := fmt.Sprintf("Doc not struct pointer: %v",
reflect.TypeOf(doc))
return clownfish.NewErr(mess)
}
docType := docValue.Type()
for i := 0; i < docValue.NumField(); i++ {
field := docType.Field(i).Name
value := docValue.Field(i).String()
fieldC := obj.findFieldC(field)
valueC := clownfish.NewString(value)
C.CFISH_Hash_Store(docFields,
(*C.cfish_String)(unsafe.Pointer(fieldC)),
C.cfish_inc_refcount(unsafe.Pointer(valueC.TOPTR())))
}
// TODO create an additional method AddDocWithBoost which allows the
// client to supply `boost`.
boost := 1.0
err := clownfish.TrapErr(func() {
C.LUCY_Indexer_Add_Doc(self, stockDoc, C.float(boost))
})
return err
}
示例14: GOLUCY_Inverter_Invert_Doc
//export GOLUCY_Inverter_Invert_Doc
func GOLUCY_Inverter_Invert_Doc(inverter *C.lucy_Inverter, doc *C.lucy_Doc) {
ivars := C.lucy_Inverter_IVARS(inverter)
fields := fetchDocFields(doc)
// Prepare for the new doc.
C.LUCY_Inverter_Set_Doc(inverter, doc)
// Extract and invert the doc's fields.
for field, val := range fields {
inventry := fetchEntry(ivars, field)
inventryIvars := C.lucy_InvEntry_IVARS(inventry)
fieldType := inventryIvars._type
// Get the field value.
var expectedType *C.cfish_Class
switch C.LUCY_FType_Primitive_ID(fieldType) & C.lucy_FType_PRIMITIVE_ID_MASK {
case C.lucy_FType_TEXT:
expectedType = C.CFISH_STRING
case C.lucy_FType_BLOB:
expectedType = C.CFISH_BLOB
case C.lucy_FType_INT32:
expectedType = C.CFISH_INTEGER
case C.lucy_FType_INT64:
expectedType = C.CFISH_INTEGER
case C.lucy_FType_FLOAT32:
expectedType = C.CFISH_FLOAT
case C.lucy_FType_FLOAT64:
expectedType = C.CFISH_FLOAT
default:
panic(clownfish.NewErr("Internal Lucy error: bad type id for field " + field))
}
temp := inventryIvars.value
valCF := clownfish.GoToClownfish(val, unsafe.Pointer(expectedType), false)
inventryIvars.value = C.cfish_inc_refcount(valCF)
C.cfish_decref(unsafe.Pointer(temp))
C.LUCY_Inverter_Add_Field(inverter, inventry)
}
}
示例15: GOLUCY_RegexTokenizer_Tokenize_Utf8
//export GOLUCY_RegexTokenizer_Tokenize_Utf8
func GOLUCY_RegexTokenizer_Tokenize_Utf8(rt *C.lucy_RegexTokenizer, str *C.char,
stringLen C.size_t, inversion *C.lucy_Inversion) {
ivars := C.lucy_RegexTokenizer_IVARS(rt)
rxID := uintptr(ivars.token_re)
rx, ok := registry.fetch(rxID).(*regexp.Regexp)
if !ok {
mess := fmt.Sprintf("Failed to Fetch *RegExp with id %d and pattern %s",
rxID, clownfish.CFStringToGo(unsafe.Pointer(ivars.pattern)))
panic(clownfish.NewErr(mess))
}
buf := C.GoBytes(unsafe.Pointer(str), C.int(stringLen))
found := rx.FindAllIndex(buf, int(stringLen))
lastEnd := 0
cpCount := 0
for _, startEnd := range found {
cpCount = int(C.push_token(str, C.int(startEnd[0]), C.int(startEnd[1]),
C.int(lastEnd), C.int(cpCount), inversion))
lastEnd = startEnd[1]
}
}