예제 #1
0
func fullTextSpecType(field *Field) *C.lucy_FieldType {
	// Two ways to skin a cat
	//
	// specType := C.LucyFullTextTypeNew(field.IndexOptions.Analyzer.lucyAnalyzer)
	// specType = C.LucyFullTextTypeInitOptions(specType,
	// 	field.IndexOptions.Analyzer.lucyAnalyzer,
	// 	(C.float)(field.IndexOptions.Boost),
	// 	(C.bool)(field.IndexOptions.Indexed),
	// 	(C.bool)(field.IndexOptions.Stored),
	// 	(C.bool)(field.IndexOptions.Sortable),
	// 	(C.bool)(field.IndexOptions.Highlightable),
	// )
	// return specType
	//
	// and another
	return (*C.lucy_FieldType)(C.LucyFullTextTypeInitOptions(
		C.LucyFullTextTypeNew(field.IndexOptions.Analyzer.lucyAnalyzer),
		field.IndexOptions.Analyzer.lucyAnalyzer,
		(C.float)(field.IndexOptions.Boost),
		(C.bool)(field.IndexOptions.Indexed),
		(C.bool)(field.IndexOptions.Stored),
		(C.bool)(field.IndexOptions.Sortable),
		(C.bool)(field.IndexOptions.Highlightable),
	))
}
예제 #2
0
파일: plan.go 프로젝트: rectang/golucy
func (schema *Schema) createLucySchema() {
	lucySchema := C.LucySchemaNew()
	for _, item := range schema.PlanItems {
		var specType *C.CFishObj
		if item.Type == FullTextType {
			var language *C.CFishCharBuf
			if item.Options != nil && item.Options.Language != "" {
				language = cb_newf(item.Options.Language)
			} else {
				language = cb_newf("en")
			}
			analyzer := C.LucyEasyAnalyzerNew(language)
			specType = C.LucyFullTextTypeNew(analyzer)
			// TODO: come up with a better way to handle options.
			// This isn't very friendly.
			if item.Options != nil {
				specType = C.LucyFullTextTypeInitOptions(specType, analyzer,
					(C.float)(item.Options.Boost),
					(C.bool)(item.Options.Indexed),
					(C.bool)(item.Options.Stored),
					(C.bool)(item.Options.Sortable),
					(C.bool)(item.Options.Highlightable),
				)
			}
			C.DECREF(language)
			C.DECREF(analyzer)
		} else if item.Type == StringType {
			specType = C.LucyStringTypeNew()
			if item.Options != nil {
				specType = C.LucyStringTypeInitOptions(specType,
					(C.float)(item.Options.Boost),
					(C.bool)(item.Options.Indexed),
					(C.bool)(item.Options.Stored),
					(C.bool)(item.Options.Sortable),
				)
			}
		} else if item.Type == BlobType {
			isStored := (C.bool)(false)
			if item.Options != nil && item.Options.Stored {
				isStored = (C.bool)(true)
			}
			specType = C.LucyBlobTypeNew(isStored)
			// need to send []cfish_byte castable value
			panic("BlobType not supported yet")
		} else {
			panic("Type not supported yet")
		}
		fieldName := cb_newf(item.Field)
		C.LucySchemaSpecField(lucySchema, fieldName, specType)
		C.DECREF(fieldName)
		C.DECREF(specType)
	}
	schema.lucySchema = lucySchema
}