Analyze API: Default analyzer accidentally removed stopwords

The analyze API used the standard analyzer from lucene and therefore removed
stopwords instead of using the elasticsearch default analyzer.

Closes #5974
This commit is contained in:
Alexander Reelsen 2014-05-05 11:28:37 +02:00
parent d4fcf23057
commit 799bb2491c
2 changed files with 22 additions and 2 deletions

View File

@ -34,7 +34,6 @@ import org.elasticsearch.cluster.block.ClusterBlockException;
import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.cluster.routing.ShardsIterator; import org.elasticsearch.cluster.routing.ShardsIterator;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.analysis.*; import org.elasticsearch.index.analysis.*;
@ -213,7 +212,7 @@ public class TransportAnalyzeAction extends TransportSingleCustomOperationAction
closeAnalyzer = true; closeAnalyzer = true;
} else if (analyzer == null) { } else if (analyzer == null) {
if (indexService == null) { if (indexService == null) {
analyzer = Lucene.STANDARD_ANALYZER; analyzer = indicesAnalysisService.analyzer("standard");
} else { } else {
analyzer = indexService.analysisService().defaultIndexAnalyzer(); analyzer = indexService.analysisService().defaultIndexAnalyzer();
} }

View File

@ -31,6 +31,8 @@ import java.io.IOException;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder; import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
/** /**
* *
@ -172,4 +174,23 @@ public class AnalyzeActionTests extends ElasticsearchIntegrationTest {
assertThat(token.getEndOffset(), equalTo(14)); assertThat(token.getEndOffset(), equalTo(14));
} }
} }
@Test // issue #5974
public void testThatStandardAndDefaultAnalyzersAreSame() throws Exception {
AnalyzeResponse response = client().admin().indices().prepareAnalyze("this is a test").setAnalyzer("standard").get();
assertTokens(response, "this", "is", "a", "test");
response = client().admin().indices().prepareAnalyze("this is a test").setAnalyzer("default").get();
assertTokens(response, "this", "is", "a", "test");
response = client().admin().indices().prepareAnalyze("this is a test").get();
assertTokens(response, "this", "is", "a", "test");
}
private void assertTokens(AnalyzeResponse response, String ... tokens) {
assertThat(response.getTokens(), hasSize(tokens.length));
for (int i = 0; i < tokens.length; i++) {
assertThat(response.getTokens().get(i).getTerm(), is(tokens[i]));
}
}
} }