本文整理汇总了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
}
示例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
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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"
}
示例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
}
示例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)
}
示例10: NewBleveParams
func NewBleveParams() *BleveParams {
return &BleveParams{
Mapping: *bleve.NewIndexMapping(),
Store: map[string]interface{}{
"kvStoreName": bleve.Config.DefaultKVStore,
},
}
}
示例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)
}
}
}
}
示例12: NewBleveParams
func NewBleveParams() *BleveParams {
rv := &BleveParams{
Mapping: *bleve.NewIndexMapping(),
Store: map[string]interface{}{
"kvStoreName": bleve.Config.DefaultKVStore,
},
}
rv.Mapping.TypeField = "type"
return rv
}
示例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}
}
示例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
}
示例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")
}