当前位置: 首页>>代码示例>>Golang>>正文


Golang bleve.NewIndexMapping函数代码示例

本文整理汇总了Golang中github.com/blevesearch/bleve.NewIndexMapping函数的典型用法代码示例。如果您正苦于以下问题:Golang NewIndexMapping函数的具体用法?Golang NewIndexMapping怎么用?Golang NewIndexMapping使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewIndexMapping函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: getIndexMapping

// Returns data model for index
func getIndexMapping() *bv.IndexMapping {
	indexMapping := bv.NewIndexMapping()
	messageMapping := bv.NewDocumentStaticMapping()

	// Will search exact string, e.g.: «hostname.example.org» will search for «hostname.example.org»
	mappingKeyword := getTextFieldMapping()
	mappingKeyword.Analyzer = bvKeywordAnalyzer.Name

	// Tokenized query, e.g.: «hostname example org» will search for «hostname», «example» or «org»
	mappingText := getTextFieldMapping()
	mappingText.Analyzer = bvStandardAnalyzer.Name

	messageMapping.AddFieldMappingsAt("version", mappingKeyword)
	messageMapping.AddFieldMappingsAt("host", mappingKeyword)
	messageMapping.AddFieldMappingsAt("short_message", mappingText)
	messageMapping.AddFieldMappingsAt("full_message", mappingText)
	messageMapping.AddFieldMappingsAt("timestamp", bv.NewDateTimeFieldMapping())
	messageMapping.AddFieldMappingsAt("level", bv.NewNumericFieldMapping())
	messageMapping.AddFieldMappingsAt("facility", mappingKeyword)
	messageMapping.AddSubDocumentMapping("extra", bv.NewDocumentMapping())

	indexMapping.AddDocumentMapping(DOC_TYPE, messageMapping)

	return indexMapping
}
开发者ID:endeveit,项目名称:recause,代码行数:26,代码来源:bleve.go

示例2: BuildArticleMapping

// BuildArticleMapping returns a mapping for indexing wikipedia articles
// in a manner similar to that done by lucene nightly benchmarks
func BuildArticleMapping() *bleve.IndexMapping {

	// a generic reusable mapping for english text
	standardJustIndexed := bleve.NewTextFieldMapping()
	standardJustIndexed.Store = false
	standardJustIndexed.IncludeInAll = false
	standardJustIndexed.IncludeTermVectors = false
	standardJustIndexed.Analyzer = "standard"

	keywordJustIndexed := bleve.NewTextFieldMapping()
	keywordJustIndexed.Store = false
	keywordJustIndexed.IncludeInAll = false
	keywordJustIndexed.IncludeTermVectors = false
	keywordJustIndexed.Analyzer = "keyword"

	articleMapping := bleve.NewDocumentMapping()

	// title
	articleMapping.AddFieldMappingsAt("title",
		keywordJustIndexed)

	// text
	articleMapping.AddFieldMappingsAt("text",
		standardJustIndexed)

	// _all (disabled)
	disabledSection := bleve.NewDocumentDisabledMapping()
	articleMapping.AddSubDocumentMapping("_all", disabledSection)

	indexMapping := bleve.NewIndexMapping()
	indexMapping.DefaultMapping = articleMapping
	indexMapping.DefaultAnalyzer = "standard"

	return indexMapping
}
开发者ID:steveyen,项目名称:bleve-bench,代码行数:37,代码来源:mapping.go

示例3: main

func main() {
	// open a new index
	mapping := bleve.NewIndexMapping()
	index, err := bleve.New("example.bleve", mapping)
	if err != nil {
		fmt.Println(err)
		return
	}

	data := struct {
		Name string
	}{
		Name: "text",
	}

	// index some data
	index.Index("id", data)

	// search for some text
	query := bleve.NewMatchQuery("text")
	search := bleve.NewSearchRequest(query)
	searchResults, err := index.Search(search)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(searchResults)
}
开发者ID:joyrexus,项目名称:go-sandbox,代码行数:28,代码来源:hello.go

示例4: openIndex

func openIndex(path string) (bleve.Index, error) {
	if _, err := os.Stat(path); os.IsNotExist(err) {
		mapping := bleve.NewIndexMapping()
		return bleve.New(path, mapping)
	}
	return bleve.Open(path)
}
开发者ID:marsmensch,项目名称:blobstash,代码行数:7,代码来源:docstore.go

示例5: ValidateMapping

func ValidateMapping(w http.ResponseWriter, req *http.Request) {
	indexMapping := bleve.NewIndexMapping()

	// read the request body
	requestBody, err := ioutil.ReadAll(req.Body)
	if err != nil {
		showError(w, req, fmt.Sprintf("error reading request body: %v", err), 400)
		return
	}

	// interpret request body as index mapping
	if len(requestBody) > 0 {
		requestBody, err = CleanseJSON(requestBody)
		if err != nil {
			showError(w, req, fmt.Sprintf("error preparing index mapping: %v", err), 400)
			return
		}
		err = json.Unmarshal(requestBody, &indexMapping)
		if err != nil {
			showError(w, req, fmt.Sprintf("error parsing index mapping: %v", err), 400)
			return
		}
	}

	rv := struct {
		Status string `json:"status"`
	}{
		Status: "ok",
	}
	mustEncode(w, rv)
}
开发者ID:steveyen,项目名称:bleve-mapping-ui,代码行数:31,代码来源:mapping.go

示例6: main

func main() {
	// Open an index if it already exists.
	index, err := bleve.Open("example.bleve")
	if err != nil {
		mapping := bleve.NewIndexMapping()
		index, err = bleve.New("example.bleve", mapping)
		if err != nil {
			fmt.Println(err)
			return
		}
	}

	data := struct {
		Name string
	}{
		Name: "text",
	}

	// Index some data.
	index.Index("id", data)

	// Search for some text
	query := bleve.NewMatchQuery("text")
	search := bleve.NewSearchRequest(query)
	searchResults, err := index.Search(search)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(searchResults)
}
开发者ID:DexterB,项目名称:Go,代码行数:32,代码来源:easysearch.go

示例7: init

func init() {
	// 定义bleve分词 -> gojieba(中文分词)
	indexMapping = bleve.NewIndexMapping()
	err := indexMapping.AddCustomTokenizer("gojieba",
		map[string]interface{}{
			"dictpath":     gojieba.DICT_PATH,
			"hmmpath":      gojieba.HMM_PATH,
			"userdictpath": gojieba.USER_DICT_PATH,
			"type":         "gojieba",
		},
	)
	if err != nil {
		fmt.Println(err)
		panic(err)
	}
	err = indexMapping.AddCustomAnalyzer("gojieba",
		map[string]interface{}{
			"type":      "gojieba",
			"tokenizer": "gojieba",
		},
	)
	if err != nil {
		fmt.Println(err)

		panic(err)
	}
	indexMapping.DefaultAnalyzer = "gojieba"
}
开发者ID:yourhe,项目名称:gojieba,代码行数:28,代码来源:wfzl.go

示例8: buildIndexMapping

func buildIndexMapping() *bleve.IndexMapping {

	enTextFieldMapping := bleve.NewTextFieldMapping()
	enTextFieldMapping.Analyzer = textFieldAnalyzer

	storeFieldOnlyMapping := bleve.NewTextFieldMapping()
	storeFieldOnlyMapping.Index = false
	storeFieldOnlyMapping.IncludeTermVectors = false
	storeFieldOnlyMapping.IncludeInAll = false

	dateTimeMapping := bleve.NewDateTimeFieldMapping()

	wikiMapping := bleve.NewDocumentMapping()
	wikiMapping.AddFieldMappingsAt("name", enTextFieldMapping)
	wikiMapping.AddFieldMappingsAt("body", enTextFieldMapping)
	wikiMapping.AddFieldMappingsAt("modified_by", enTextFieldMapping)
	wikiMapping.AddFieldMappingsAt("modified_by_name", enTextFieldMapping)
	wikiMapping.AddFieldMappingsAt("modified_by_email", enTextFieldMapping)
	wikiMapping.AddFieldMappingsAt("modified_by_avatar", storeFieldOnlyMapping)
	wikiMapping.AddFieldMappingsAt("modified", dateTimeMapping)

	indexMapping := bleve.NewIndexMapping()
	indexMapping.AddDocumentMapping("wiki", wikiMapping)

	indexMapping.DefaultAnalyzer = textFieldAnalyzer

	return indexMapping
}
开发者ID:pedronasser,项目名称:bleve-wiki-indexer,代码行数:28,代码来源:mapping.go

示例9: main

func main() {

	flag.Parse()

	if *indexPath == "" {
		log.Fatal("must specify index path")
	}

	// create a new default mapping
	mapping := bleve.NewIndexMapping()
	if *mappingFile != "" {
		mappingBytes, err := ioutil.ReadFile(*mappingFile)
		if err != nil {
			log.Fatal(err)
		}
		err = json.Unmarshal(mappingBytes, &mapping)
		if err != nil {
			log.Fatal(err)
		}
	}

	// create the index
	index, err := bleve.New(*indexPath, mapping)
	if err != nil {
		log.Fatal(err)
	}
	defer index.Close()

	log.Printf("Created bleve index at: %s", *indexPath)
}
开发者ID:bozzcq,项目名称:bleve,代码行数:30,代码来源:main.go

示例10: NewBleveParams

func NewBleveParams() *BleveParams {
	return &BleveParams{
		Mapping: *bleve.NewIndexMapping(),
		Store: map[string]interface{}{
			"kvStoreName": bleve.Config.DefaultKVStore,
		},
	}
}
开发者ID:trebogeer,项目名称:cbft,代码行数:8,代码来源:pindex_bleve.go

示例11: init

func init() {

	bleve.Config.DefaultKVStore = gtreap.Name

	bleveHttp.SetLog(log.New(os.Stderr, "bleve.http ", log.LstdFlags))

	router := mux.NewRouter()
	router.StrictSlash(true)

	listIndexesHandler := bleveHttp.NewListIndexesHandler()
	router.Handle("/api", listIndexesHandler).Methods("GET")

	docCountHandler := bleveHttp.NewDocCountHandler("")
	docCountHandler.IndexNameLookup = indexNameLookup
	router.Handle("/api/{indexName}/_count", docCountHandler).Methods("GET")

	searchHandler := bleveHttp.NewSearchHandler("")
	searchHandler.IndexNameLookup = indexNameLookup
	router.Handle("/api/{indexName}/_search", searchHandler).Methods("POST")

	http.Handle("/", &CORSWrapper{router})

	log.Printf("opening indexes")
	// walk the data dir and register index names
	dirEntries, err := ioutil.ReadDir(indexDir)
	if err != nil {
		log.Printf("error reading data dir: %v", err)
		return
	}

	for _, dirInfo := range dirEntries {
		indexPath := indexDir + string(os.PathSeparator) + dirInfo.Name()

		if dirInfo.IsDir() {
			log.Printf("see directory %s, this is not supported in the appengine environment", dirInfo.Name())
		} else {
			log.Printf("preloading index export %s", dirInfo.Name())
			// assume file in this dir is actually a bleve export
			i, err := bleve.NewUsing(
				"",
				bleve.NewIndexMapping(),
				bleve.Config.DefaultIndexType,
				preload.Name,
				map[string]interface{}{
					"kvStoreName_actual": gtreap.Name,
					"preloadpath":        indexPath,
				})
			if err != nil {
				log.Printf("error preloading index %s: %v", indexPath, err)
			} else {
				i.SetName(dirInfo.Name())
				log.Printf("registered index: %s", dirInfo.Name())
				bleveHttp.RegisterIndexName(dirInfo.Name(), i)
			}
		}
	}
}
开发者ID:blevesearch,项目名称:bleve-hosted,代码行数:57,代码来源:appengine.go

示例12: NewBleveParams

func NewBleveParams() *BleveParams {
	rv := &BleveParams{
		Mapping: *bleve.NewIndexMapping(),
		Store: map[string]interface{}{
			"kvStoreName": bleve.Config.DefaultKVStore,
		},
	}

	rv.Mapping.TypeField = "type"

	return rv
}
开发者ID:thesoftwarefactoryuk,项目名称:cbft,代码行数:12,代码来源:pindex_bleve.go

示例13: NewBleveRecipeStore

func NewBleveRecipeStore(path string) RecipeStore {
	idx, err := bleve.Open(path)
	if err == bleve.ErrorIndexPathDoesNotExist {
		mapping := bleve.NewIndexMapping()
		idx, err = bleve.New(path, mapping)
	}
	if err != nil {
		panic(fmt.Errorf("could not open/create bleve idx at %s: %v", path, err))
	}

	return &BleveRecipeStore{idx: idx}
}
开发者ID:LeoCavaille,项目名称:rcpmgr,代码行数:12,代码来源:recipe.go

示例14: buildIndexMapping

func buildIndexMapping() (*bleve.IndexMapping, error) {
	var err error

	// Create the index mapping, configure the analyzer, and set as default.
	indexMapping := bleve.NewIndexMapping()
	err = indexMapping.AddCustomTokenizer("ekanite_tk",
		map[string]interface{}{
			"regexp": `[^\W_]+`,
			"type":   regexp_tokenizer.Name,
		})
	if err != nil {
		return nil, err
	}

	err = indexMapping.AddCustomAnalyzer("ekanite",
		map[string]interface{}{
			"type":          custom_analyzer.Name,
			"char_filters":  []interface{}{},
			"tokenizer":     `ekanite_tk`,
			"token_filters": []interface{}{`to_lower`},
		})
	if err != nil {
		return nil, err
	}
	indexMapping.DefaultAnalyzer = "ekanite"

	// Create field-specific mappings.

	simpleJustIndexed := bleve.NewTextFieldMapping()
	simpleJustIndexed.Store = false
	simpleJustIndexed.IncludeInAll = true // XXX Move to false when using AST
	simpleJustIndexed.IncludeTermVectors = false

	timeJustIndexed := bleve.NewDateTimeFieldMapping()
	timeJustIndexed.Store = false
	timeJustIndexed.IncludeInAll = false
	timeJustIndexed.IncludeTermVectors = false

	articleMapping := bleve.NewDocumentMapping()

	// Connect field mappings to fields.
	articleMapping.AddFieldMappingsAt("Message", simpleJustIndexed)
	articleMapping.AddFieldMappingsAt("ReferenceTime", timeJustIndexed)
	articleMapping.AddFieldMappingsAt("ReceptionTime", timeJustIndexed)

	// Tell the index about field mappings.
	indexMapping.DefaultMapping = articleMapping

	return indexMapping, nil
}
开发者ID:tjyang,项目名称:ekanite,代码行数:50,代码来源:index.go

示例15: main

func main() {
	mapping := bleve.NewIndexMapping()               // HLMAPPING
	index, err := bleve.New("people.bleve", mapping) // HLNEW
	if err != nil {
		log.Fatal(err)
	}

	person := Person{"Marty Schoch"} // HLINDEX
	err = index.Index("m1", person)  // HLINDEX
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Indexed Document")
}
开发者ID:blevesearch,项目名称:gophercon15,代码行数:14,代码来源:index.go


注:本文中的github.com/blevesearch/bleve.NewIndexMapping函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。