mstein / elasticsearch-grails-plugin

ElasticSearch grails plugin
Based on Graeme Rocher initial stub. Note that it is still in early stage.
Other
62 stars 164 forks source link

Default analyzer #29

Open msmolyak opened 12 years ago

msmolyak commented 12 years ago

How can I set the default analyzer for the entire index?

msmolyak commented 12 years ago

Added this code to the plugin for specifying the default analyzer in the local mode.

In the config.groovy:

elasticSearch { ... /* * Default analyzer to use in local mode / defaultAnalyzer = "snowball" ...

In org.grails.plugins.elasticsearch.ClientNodeFactoryBean:

        case 'local':
            // Determines how the data is store (on disk, in memory, ...)
            def storeType = elasticSearchContextHolder.config.index.store.type
            if (storeType) {
                nb.settings().put('index.store.type', storeType as String)
                LOG.debug "Local ElasticSearch client with store type of ${storeType} configured."
            } else {
                LOG.debug "Local ElasticSearch client with default store type configured."
            }
            def queryParsers = elasticSearchContextHolder.config.index.queryparser
            if (queryParsers) {
                queryParsers.each { type, clz ->
                    nb.settings().put("index.queryparser.types.${type}".toString(), clz)
                }
            }
            // New code starts here
            if (elasticSearchContextHolder.config.defaultAnalyzer) {
                nb.settings().put('index.analysis.analyzer.default.type', elasticSearchContextHolder.config.defaultAnalyzer)
                LOG.debug "Setting default analyzer ${elasticSearchContextHolder.config.defaultAnalyzer}"
            }
            // New code ends here
            nb.local(true)
            break
pengqiuyuan commented 11 years ago

Excuse me, if I want to use Chinese word how to add such Ansj this, also like defaultAnalyzer = "ansj" Thank you so do https://github.com/ansjsun/ansj_seg