This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val tokens = analyzer.analyze("A Blog Post on <b>Elasticsearch</b>") | |
| Assert.assertEquals(listOf("blogpost", "elasticsearch"), tokens) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun analyze(text: String): List<String> { | |
| val result = mutableListOf<String>() | |
| val analyzer = createAnalyzer() | |
| var ts = analyzer.tokenStream("", text) | |
| ts.reset() | |
| while (ts.incrementToken()) { | |
| val attr = ts.getAttribute(CharTermAttribute::class.java) | |
| result.add(attr.toString()) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private fun createAnalyzer(): Analyzer { | |
| val tokenizerFactory = createTokenizerFactory() | |
| val charFilterFactories = createCharFilterFactories() | |
| val tokenFilterFactories = createTokenFilterFactories() | |
| return CustomAnalyzer(tokenizerFactory, charFilterFactories, tokenFilterFactories) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private fun createTokenFilterFactories(): Array<TokenFilterFactory> { | |
| val stopwords = CharArraySet(listOf("a", "an", "on"), false) | |
| val stopTokenFilterFactory = object : TokenFilterFactory { | |
| override fun create(tokenStream: TokenStream?) = StopFilter(tokenStream, stopwords) | |
| override fun name() = "stop" | |
| } | |
| val lowercaseFilterFactory = object : TokenFilterFactory { | |
| override fun create(tokenStream: TokenStream?) = LowerCaseFilter(tokenStream) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private fun createCharFilterFactories(): Array<CharFilterFactory> { | |
| val htmlStripFilterFactory = object : CharFilterFactory { | |
| override fun name() = "htmlStrip" | |
| override fun create(reader: Reader?) = HTMLStripCharFilter(reader) | |
| } | |
| return arrayOf(htmlStripFilterFactory) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private fun createTokenizerFactory(): TokenizerFactory { | |
| return TokenizerFactory.newFactory("whitespace", | |
| Supplier { WhitespaceTokenizer() } | |
| ) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.udemy.search.elasticanalyzers | |
| import org.apache.lucene.analysis.* | |
| import org.apache.lucene.analysis.core.LowerCaseFilter | |
| import org.apache.lucene.analysis.core.WhitespaceTokenizer | |
| import org.apache.lucene.analysis.synonym.SolrSynonymParser | |
| import org.apache.lucene.analysis.synonym.SynonymGraphFilter | |
| import org.apache.lucene.analysis.tokenattributes.CharTermAttribute | |
| import org.elasticsearch.index.analysis.CharFilterFactory | |
| import org.elasticsearch.index.analysis.CustomAnalyzer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Component | |
| class PassthruSimpleHostRoutingFilter(@Autowired val helper: ProxyRequestHelper, | |
| @Autowired val zuulProperties: ZuulProperties, | |
| @Autowired val httpClientConnectionManagerFactory: ApacheHttpClientConnectionManagerFactory, | |
| @Autowired val httpClientFactory: ApacheHttpClientFactory) : SimpleHostRoutingFilter(helper, zuulProperties, httpClientConnectionManagerFactory, httpClientFactory) { | |
| override fun buildHttpRequest(verb: String?, uri: String?, entity: InputStreamEntity?, headers: MultiValueMap<String, String>?, params: MultiValueMap<String, String>?, request: HttpServletRequest): HttpRequest { | |
| return if (verb?.toUpperCase() == "GET") { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Component | |
| class PassthruPostFilter : ZuulFilter() { | |
| override fun shouldFilter() = true | |
| override fun filterType() = "post" | |
| override fun filterOrder() = 1 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val bytes = ctx.responseDataStream.readAllBytes() | |
| responseBody = CharStreams.toString(GZIPInputStream(bytes.inputStream()).reader()) | |
| ctx.responseDataStream = bytes.inputStream() |