func (s *StepperIMP) readRecord(instream InStream) error { return clownfish.TrapErr(func() { self := (*C.lucy_Stepper)(clownfish.Unwrap(s, "s")) instreamCF := (*C.lucy_InStream)(clownfish.Unwrap(instream, "instream")) C.LUCY_Stepper_Read_Record(self, instreamCF) }) }
func (d *DataWriterIMP) addInvertedDoc(inverter Inverter, docId int32) error { return clownfish.TrapErr(func() { self := (*C.lucy_DataWriter)(clownfish.Unwrap(d, "d")) inverterCF := (*C.lucy_Inverter)(clownfish.Unwrap(inverter, "inverter")) C.LUCY_DataWriter_Add_Inverted_Doc(self, inverterCF, C.int32_t(docId)) }) }
func (d *DeletionsWriterIMP) DeleteByQuery(query Query) error { return clownfish.TrapErr(func() { self := (*C.lucy_DeletionsWriter)(clownfish.Unwrap(d, "d")) queryCF := (*C.lucy_Query)(clownfish.Unwrap(query, "query")) C.LUCY_DelWriter_Delete_By_Query(self, queryCF) }) }
func (s *SegWriterIMP) AddDoc(doc Doc, boost float32) error { return clownfish.TrapErr(func() { self := (*C.lucy_SegWriter)(clownfish.Unwrap(s, "s")) docCF := (*C.lucy_Doc)(clownfish.Unwrap(doc, "doc")) C.LUCY_SegWriter_Add_Doc(self, docCF, C.float(boost)) }) }
func (s *SegmentIMP) ReadFile(folder Folder) error { return clownfish.TrapErr(func() { self := (*C.lucy_Segment)(clownfish.Unwrap(s, "s")) folderC := (*C.lucy_Folder)(clownfish.Unwrap(folder, "folder")) C.LUCY_Seg_Read_File(self, folderC) }) }
func (obj *IndexerIMP) addDocObj(doc Doc, boost float32) error { self := (*C.lucy_Indexer)(clownfish.Unwrap(obj, "obj")) d := (*C.lucy_Doc)(clownfish.Unwrap(doc, "doc")) return clownfish.TrapErr(func() { C.LUCY_Indexer_Add_Doc(self, d, C.float(boost)) }) }
func (out *OutStreamIMP) Absorb(in InStream) error { return clownfish.TrapErr(func() { self := (*C.lucy_OutStream)(clownfish.Unwrap(out, "out")) inStreamC := (*C.lucy_InStream)(clownfish.Unwrap(in, "in")) C.LUCY_OutStream_Absorb(self, inStreamC) }) }
func (obj *IndexerIMP) DeleteByQuery(query Query) error { return clownfish.TrapErr(func() { self := (*C.lucy_Indexer)(clownfish.Unwrap(obj, "obj")) queryC := (*C.lucy_Query)(clownfish.Unwrap(query, "query")) C.LUCY_Indexer_Delete_By_Query(self, queryC) }) }
func (d *DataWriterIMP) DeleteSegment(reader SegReader) error { return clownfish.TrapErr(func() { self := (*C.lucy_DataWriter)(clownfish.Unwrap(d, "d")) readerCF := (*C.lucy_SegReader)(clownfish.Unwrap(reader, "reader")) C.LUCY_DataWriter_Delete_Segment(self, readerCF) }) }
func (td *TopDocsIMP) SetMatchDocs(matchDocs []MatchDoc) { self := (*C.lucy_TopDocs)(clownfish.Unwrap(td, "td")) vec := clownfish.NewVector(len(matchDocs)) for _, matchDoc := range matchDocs { vec.Push(matchDoc) } C.LUCY_TopDocs_Set_Match_Docs(self, (*C.cfish_Vector)(clownfish.Unwrap(vec, "matchDocs"))) }
func (s *StepperIMP) WriteDelta(outstream OutStream, value interface{}) error { return clownfish.TrapErr(func() { self := (*C.lucy_Stepper)(clownfish.Unwrap(s, "s")) outstreamCF := (*C.lucy_OutStream)(clownfish.Unwrap(outstream, "outstream")) valueCF := (*C.cfish_Obj)(clownfish.GoToClownfish(value, unsafe.Pointer(C.CFISH_OBJ), false)) defer C.cfish_decref(unsafe.Pointer(valueCF)) C.LUCY_Stepper_Write_Delta(self, outstreamCF, valueCF) }) }
func (s *SnapshotIMP) WriteFile(folder Folder, path string) error { return clownfish.TrapErr(func() { self := (*C.lucy_Snapshot)(clownfish.Unwrap(s, "s")) folderC := (*C.lucy_Folder)(clownfish.Unwrap(folder, "folder")) pathC := (*C.cfish_String)(clownfish.GoToClownfish(path, unsafe.Pointer(C.CFISH_STRING), false)) defer C.cfish_decref(unsafe.Pointer(pathC)) C.LUCY_Snapshot_Write_File(self, folderC, pathC) }) }
func (d *DataWriterIMP) MergeSegment(reader SegReader, docMap []int32) error { return clownfish.TrapErr(func() { self := (*C.lucy_DataWriter)(clownfish.Unwrap(d, "d")) readerCF := (*C.lucy_SegReader)(clownfish.Unwrap(reader, "reader")) docMapConv := NewI32Array(docMap) docMapCF := (*C.lucy_I32Array)(clownfish.UnwrapNullable(docMapConv)) C.LUCY_DataWriter_Merge_Segment(self, readerCF, docMapCF) }) }
func NewSeriesMatcher(matchers []Matcher, offsets []int32) SeriesMatcher { vec := clownfish.NewVector(len(matchers)) for _, child := range matchers { vec.Push(child) } i32arr := NewI32Array(offsets) cfObj := C.lucy_SeriesMatcher_new(((*C.cfish_Vector)(clownfish.Unwrap(vec, "matchers"))), ((*C.lucy_I32Array)(clownfish.Unwrap(i32arr, "offsets")))) return WRAPSeriesMatcher(unsafe.Pointer(cfObj)) }
func (d *DeletionsWriterIMP) generateDocMap(deletions Matcher, docMax int32, offset int32) (retval []int32, err error) { err = clownfish.TrapErr(func() { self := (*C.lucy_DeletionsWriter)(clownfish.Unwrap(d, "d")) deletionsCF := (*C.lucy_Matcher)(clownfish.Unwrap(deletions, "deletions")) retvalCF := C.LUCY_DelWriter_Generate_Doc_Map(self, deletionsCF, C.int32_t(docMax), C.int32_t(offset)) defer C.cfish_decref(unsafe.Pointer(retvalCF)) retval = i32ArrayToSlice(retvalCF) }) return retval, err }
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 }
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 }
func (d *DeletionsWriterIMP) segDeletions(segReader SegReader) (retval Matcher, err error) { err = clownfish.TrapErr(func() { self := (*C.lucy_DeletionsWriter)(clownfish.Unwrap(d, "d")) segReaderCF := (*C.lucy_SegReader)(clownfish.Unwrap(segReader, "segReader")) retvalCF := C.LUCY_DelWriter_Seg_Deletions(self, segReaderCF) if retvalCF != nil { retval = clownfish.WRAPAny(unsafe.Pointer(retvalCF)).(Matcher) } }) return retval, err }
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))) } }
func (s *SearcherIMP) topDocs(query Query, numWanted uint32, sortSpec SortSpec) (topDocs TopDocs, err error) { err = clownfish.TrapErr(func() { self := (*C.lucy_Searcher)(clownfish.Unwrap(s, "s")) sortSpecC := (*C.lucy_SortSpec)(clownfish.UnwrapNullable(sortSpec)) queryC := (*C.lucy_Query)(clownfish.Unwrap(query, "query")) topDocsC := C.LUCY_Searcher_Top_Docs(self, queryC, C.uint32_t(numWanted), sortSpecC) topDocs = WRAPTopDocs(unsafe.Pointer(topDocsC)) }) return topDocs, err }
func (q *QueryIMP) MakeCompiler(searcher Searcher, boost float32, subordinate bool) (retval Compiler, err error) { err = clownfish.TrapErr(func() { self := (*C.lucy_Query)(clownfish.Unwrap(q, "q")) searcherCF := (*C.lucy_Searcher)(clownfish.Unwrap(searcher, "searcher")) retvalCF := C.LUCY_Query_Make_Compiler(self, searcherCF, C.float(boost), C.bool(subordinate)) if retvalCF != nil { retval = clownfish.WRAPAny(unsafe.Pointer(retvalCF)).(Compiler) } }) return retval, err }
func NewTermVector(field, text string, positions, startOffsets, endOffsets []int32) TermVector { fieldC := (*C.cfish_String)(clownfish.GoToClownfish(field, unsafe.Pointer(C.CFISH_STRING), false)) textC := (*C.cfish_String)(clownfish.GoToClownfish(text, unsafe.Pointer(C.CFISH_STRING), false)) defer C.cfish_decref(unsafe.Pointer(fieldC)) defer C.cfish_decref(unsafe.Pointer(textC)) posits := NewI32Array(positions) starts := NewI32Array(startOffsets) ends := NewI32Array(endOffsets) positsC := (*C.lucy_I32Array)(clownfish.Unwrap(posits, "posits")) startsC := (*C.lucy_I32Array)(clownfish.Unwrap(starts, "starts")) endsC := (*C.lucy_I32Array)(clownfish.Unwrap(ends, "ends")) retvalC := C.lucy_TV_new(fieldC, textC, positsC, startsC, endsC) return WRAPTermVector(unsafe.Pointer(retvalC)) }
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) }) }
func (c *CompilerIMP) MakeMatcher(reader SegReader, needScore bool) (retval Matcher, err error) { err = clownfish.TrapErr(func() { self := (*C.lucy_Compiler)(clownfish.Unwrap(c, "c")) readerCF := (*C.lucy_SegReader)(clownfish.Unwrap(reader, "reader")) retvalCF := C.LUCY_Compiler_Make_Matcher(self, readerCF, C.bool(needScore)) if retvalCF != nil { retval = clownfish.WRAPAny(unsafe.Pointer(retvalCF)).(Matcher) } }) if err != nil || retval == nil { return nil, err } return retval, err }
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 } }
func (t *TokenIMP) SetText(text string) { self := (*C.lucy_Token)(clownfish.Unwrap(t, "t")) chars := C.CString(text) defer C.free(unsafe.Pointer(chars)) size := C.size_t(len(text)) C.LUCY_Token_Set_Text(self, chars, size) }
//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"))) }
func (h *HighlightReaderIMP) FetchDocVec(docID int32) (retval DocVector, err error) { err = clownfish.TrapErr(func() { self := (*C.lucy_HighlightReader)(clownfish.Unwrap(h, "h")) retvalCF := C.LUCY_HLReader_Fetch_Doc_Vec(self, C.int32_t(docID)) retval = WRAPDocVector(unsafe.Pointer(retvalCF)) }) return retval, err }
func (d *DocReaderIMP) FetchDoc(docID int32) (doc HitDoc, err error) { err = clownfish.TrapErr(func() { self := (*C.lucy_DocReader)(clownfish.Unwrap(d, "d")) docC := C.LUCY_DocReader_Fetch_Doc(self, C.int32_t(docID)) doc = WRAPHitDoc(unsafe.Pointer(docC)) }) return doc, err }
func (s *SortCacheIMP) Ordinal(docId int32) (retval int32, err error) { err = clownfish.TrapErr(func() { self := (*C.lucy_SortCache)(clownfish.Unwrap(s, "s")) retvalCF := C.LUCY_SortCache_Ordinal(self, C.int32_t(docId)) retval = int32(retvalCF) }) return retval, err }