forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Actually close IndexAnalyzers contents (elastic#43914)
IndexAnalyzers has a close() method that should iterate through all its wrapped analyzers and close each one in turn. However, instead of delegating to the analyzers' close() methods, it instead wraps them in a Closeable interface, which just returns a list of the analyzers. In addition, whitespace normalizers are ignored entirely.
- Loading branch information
1 parent
09b6c23
commit 20d50c5
Showing
2 changed files
with
80 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
75 changes: 75 additions & 0 deletions
75
server/src/test/java/org/elasticsearch/index/analysis/IndexAnalyzersTests.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.index.analysis; | ||
|
||
import org.apache.lucene.analysis.core.KeywordAnalyzer; | ||
import org.apache.lucene.analysis.core.WhitespaceAnalyzer; | ||
import org.apache.lucene.analysis.standard.StandardAnalyzer; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.index.Index; | ||
import org.elasticsearch.index.IndexSettings; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.test.IndexSettingsModule; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
public class IndexAnalyzersTests extends ESTestCase { | ||
|
||
public void testClose() throws IOException { | ||
|
||
AtomicInteger closes = new AtomicInteger(0); | ||
NamedAnalyzer a = new NamedAnalyzer("default", AnalyzerScope.INDEX, new WhitespaceAnalyzer()){ | ||
@Override | ||
public void close() { | ||
super.close(); | ||
closes.incrementAndGet(); | ||
} | ||
}; | ||
|
||
NamedAnalyzer n = new NamedAnalyzer("keyword_normalizer", AnalyzerScope.INDEX, new KeywordAnalyzer()){ | ||
@Override | ||
public void close() { | ||
super.close(); | ||
closes.incrementAndGet(); | ||
} | ||
}; | ||
|
||
NamedAnalyzer w = new NamedAnalyzer("whitespace_normalizer", AnalyzerScope.INDEX, new WhitespaceAnalyzer()){ | ||
@Override | ||
public void close() { | ||
super.close(); | ||
closes.incrementAndGet(); | ||
} | ||
}; | ||
|
||
Index index = new Index("_index", "testUUID"); | ||
IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, Settings.EMPTY); | ||
NamedAnalyzer namedAnalyzer = new NamedAnalyzer("default", AnalyzerScope.INDEX, new StandardAnalyzer()); | ||
|
||
IndexAnalyzers ia = new IndexAnalyzers(indexSettings, namedAnalyzer, namedAnalyzer, namedAnalyzer, | ||
Collections.singletonMap("default", a), Collections.singletonMap("n", n), Collections.singletonMap("w", w)); | ||
ia.close(); | ||
assertEquals(3, closes.get()); | ||
|
||
} | ||
|
||
} |