Beispiel #1
0
// This will need to be a bit more generic,
// but for testing this will work fine.
func (search *Search) GetSearcher() IndexReader {
	idxLocation := cb_newf(search.Location)
	search.lucySearcher = C.LucyIxSearcherNew(idxLocation)
	C.DECREF(idxLocation)
	return func(q string, field string, offset, limit uint) (uint, []string) {
		query := cb_new_from_utf8(q)
		getField := cb_newf(field)
		hits := C.LucyIxSearcherHits(search.lucySearcher, query, C.uint32_t(offset), C.uint32_t(limit), nil)
		totalNumHits := uint(C.LucyHitsTotal(hits))
		requestedNumHits := minUInt(limit, totalNumHits)
		results := make([]string, requestedNumHits)
		var hit *C.LucyHitDoc
		for i := uint(0); i < requestedNumHits; i++ {
			hit = C.LucyHitsNext(hits)
			if hit == nil {
				break
			}
			value_cb := C.LucyHitDocExtract(hit, getField, nil) // do i need to free this
			value := cb_ptr2char(value_cb)                      // do i need to free this
			results[i] = C.GoString(value)
			C.DECREF(hit)
		}
		C.DECREF(query)
		C.DECREF(getField)
		C.DECREF(hits)
		return totalNumHits, results
	}
}
Beispiel #2
0
func (index *Index) NewIndexReader() *IndexReader {
	ixLocation := cb_newf(index.Path)
	defer C.DECREF(ixLocation)
	ixReader := &IndexReader{
		Index:        index,
		lucySearcher: C.LucyIxSearcherNew(ixLocation),
	}
	runtime.SetFinalizer(ixReader, freeIndexReader)
	return ixReader
}