blevesearch / bleve

A modern text/numeric/geo-spatial/vector indexing library for go
Apache License 2.0
10.06k stars 683 forks source link

Unable to add custom token map #1477

Closed amanpatel6991 closed 4 years ago

amanpatel6991 commented 4 years ago

Issue: Getting error while trying to create a custom token map (for stop words filter)

I just went on to - http://bleveanalysis.couchbase.com/analysis and created a custom stop words filter and got the generated code in Golang which ain't working

`func buildIndexMapping() (*bleve.IndexMapping, error) { indexMapping := bleve.NewIndexMapping()

var err error
err = indexMapping.AddCustomTokenMap("customStop_wordmap",
    map[string]interface{}{
        "type": `custom`,
        "tokens": []interface{}{
            `the`,
        },
    })
if err != nil {
    return nil, err  // Getting error here
}

err = indexMapping.AddCustomTokenFilter("customStopFilter",
    map[string]interface{}{
        "type": `stop_tokens`,
        "stop_token_map": `customStop_wordmap`,
    })
if err != nil {
    return nil, err
}

err = indexMapping.AddCustomAnalyzer("customStopAnalyze",
    map[string]interface{}{
        "type": `custom`,
        "char_filters": []interface{}{},
        "tokenizer": `unicode`,
        "token_filters": []interface{}{
            `customStopFilter`,
        },
    })
if err != nil {
    return nil, err
}

return indexMapping, nil

}`

Error: no token map with name or type 'custom' registered (inside the package from line 47, in registry/token_maps.go)

Also i am not sure if i have to do something else to make it work So please help

amanpatel6991 commented 4 years ago

Able to figure out So i had to give the type = (github.com/blevesearch/bleve/analysis/tokenmap).Name for AddCustomTokenMap()