elasticsearch-grails-plugin icon indicating copy to clipboard operation
elasticsearch-grails-plugin copied to clipboard

Default analyzer

Open msmolyak opened this issue 12 years ago • 2 comments

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

msmolyak avatar Jun 06 '12 21:06 msmolyak

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

msmolyak avatar Jun 19 '12 13:06 msmolyak

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

pengqiuyuan avatar Jul 10 '13 03:07 pengqiuyuan