diff --git a/README.md b/README.md index 76ca356..4587772 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Note: This is a young project we're just starting to do testing on 8/3/2015. We' # Building and installing the plugin mvn package -./bin/plugin --url file:///....elasticsearch-phone/target/releases/elasticsearch-phone-1.0.0.zip --install elasticsearch-phone; +./bin/elasticsearch-plugin install file:///....elasticsearch-phone/target/releases/elasticsearch-phone-1.2.0.zip; ## Example inputs @@ -77,4 +77,3 @@ TOKENS 81771483 817714835 8177148350 - \ No newline at end of file diff --git a/pom.xml b/pom.xml index 0d07392..831543c 100644 --- a/pom.xml +++ b/pom.xml @@ -1,239 +1,272 @@ - 4.0.0 - - com.inin.analytics - elasticsearch-phone - jar - 1.0.2 - elasticsearch-phone - Elasticsearch Plugin for Phone and SIP Analysis - https://github.com/MyPureCloud/elasticsearch-phone - - UTF-8 - 1.7 - 4.11 - /tmp - - - - - The Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - - - - - https://github.com/MyPureCloud/elasticsearch-phone.git - https://github.com/MyPureCloud/elasticsearch-phone.git - https://github.com/MyPureCloud/elasticsearch-phone.git - - - - - - oss-sonatype - oss-sonatype - https://oss.sonatype.org/content/groups/public - - - central - Maven Repository Switchboard - default - http://repo1.maven.org/maven2 - - false - - - - - - - com.googlecode.libphonenumber - libphonenumber - 7.0.7 - - - - org.apache.lucene - lucene-test-framework - 4.10.4 - test - - - - org.elasticsearch - elasticsearch - 1.6.0 - - - - com.carrotsearch.randomizedtesting - randomizedtesting-runner - 2.1.11 - test - - - org.elasticsearch - elasticsearch - 1.6.0 - test - test-jar - - - - org.hamcrest - hamcrest-all - 1.3 - test - - - - org.apache.commons - commons-lang3 - 3.4 - - - - commons-io - commons-io - 2.4 - - - - - junit - junit - ${junit.version} - test - - - - - - Drew Dahlke - justin.dahlke@gmail.com - Interactive Intelligence - http://www.inin.com - - - Michael Mulligan - Michael.Mulligan@inin.com - Interactive Intelligence - http://www.inin.com - - - - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - - ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - - - - - - src/main/resources - true - - - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.3 - true - - ossrh - https://oss.sonatype.org/ - true - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.9.1 - - - attach-javadocs - - jar - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - - com.carrotsearch.randomizedtesting - junit4-maven-plugin - - - org.apache.maven.plugins - maven-surefire-plugin - - - - org.apache.maven.plugins - maven-source-plugin - - - org.apache.maven.plugins - maven-source-plugin - 2.2.1 - - - attach-sources - - jar-no-fork - - - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.5 - - gpg - - - - sign-artifacts - verify - - sign - - - - - - maven-assembly-plugin - 2.3 - - false - ${project.build.directory}/releases/ - - ${basedir}/src/main/assemblies/plugin.xml - - - - - package - - single - - - - - - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + 4.0.0 + + com.inin.analytics + elasticsearch-phone + jar + 5.1.1 + elasticsearch-phone + Elasticsearch Plugin for Phone and SIP Analysis + https://github.com/MyPureCloud/elasticsearch-phone + + UTF-8 + 1.7 + 5.1.1 + 6.3.0 + 4.12 + ${basedir}/src/main/assemblies/plugin.xml + + + + + The Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + + + + + https://github.com/MyPureCloud/elasticsearch-phone.git + https://github.com/MyPureCloud/elasticsearch-phone.git + https://github.com/MyPureCloud/elasticsearch-phone.git + + + + + + oss-sonatype + oss-sonatype + https://oss.sonatype.org/content/groups/public + + + central + Maven Repository Switchboard + default + http://repo1.maven.org/maven2 + + false + + + + + + + com.googlecode.libphonenumber + libphonenumber + 8.4.0 + + + + org.apache.lucene + lucene-test-framework + ${lucence.version} + test + + + + org.elasticsearch + elasticsearch + ${elasticsearch.version} + + + + + + + + + + org.elasticsearch.test + framework + ${elasticsearch.version} + test + + + + org.hamcrest + hamcrest-core + 1.3 + test + + + org.hamcrest + hamcrest-library + 1.3 + test + + + + org.apache.commons + commons-lang3 + 3.4 + + + + commons-io + commons-io + 2.4 + + + + + junit + junit + ${junit.version} + test + + + + net.java.dev.jna + jna + 4.2.1 + test + + + log4j + log4j + 1.2.17 + test + + + + + + Drew Dahlke + justin.dahlke@gmail.com + Interactive Intelligence + http://www.inin.com + + + Michael Mulligan + Michael.Mulligan@inin.com + Interactive Intelligence + http://www.inin.com + + + + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + + + src/main/resources + true + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.3 + true + + ossrh + https://oss.sonatype.org/ + true + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + 1.8 + 1.8 + + + + com.carrotsearch.randomizedtesting + junit4-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + true + + + + + org.apache.maven.plugins + maven-source-plugin + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + + maven-assembly-plugin + 2.6 + + false + ${project.build.directory}/releases/ + + ${basedir}/src/main/assemblies/plugin.xml + + + + + package + + single + + + + + + diff --git a/src/main/assemblies/plugin.xml b/src/main/assemblies/plugin.xml index 7d02d86..0f28927 100644 --- a/src/main/assemblies/plugin.xml +++ b/src/main/assemblies/plugin.xml @@ -5,9 +5,16 @@ zip false + + + ${basedir}/src/main/resources/plugin-descriptor.properties + elasticsearch + true + + - / + /elasticsearch/ true true @@ -15,13 +22,14 @@ - / + /elasticsearch/ true true com.googlecode.libphonenumber:libphonenumber - org.apache.commons:commons-lang3 + org.apache.commons:commons-lang3 + diff --git a/src/main/java/org/elasticsearch/index/analysis/PhoneAnalyzer.java b/src/main/java/org/elasticsearch/index/analysis/PhoneAnalyzer.java index 88a5ffb..4395dfd 100644 --- a/src/main/java/org/elasticsearch/index/analysis/PhoneAnalyzer.java +++ b/src/main/java/org/elasticsearch/index/analysis/PhoneAnalyzer.java @@ -1,15 +1,14 @@ package org.elasticsearch.index.analysis; -import java.io.Reader; - import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.Tokenizer; public class PhoneAnalyzer extends Analyzer { - + @Override - protected TokenStreamComponents createComponents(String field, Reader reader) { - Tokenizer tokenizer = new PhoneTokenizer(reader); + protected TokenStreamComponents createComponents(String field) { + Tokenizer tokenizer = new PhoneTokenizer(); return new TokenStreamComponents(tokenizer); } + } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/analysis/PhoneTokenizer.java b/src/main/java/org/elasticsearch/index/analysis/PhoneTokenizer.java index 0caf56d..c648446 100644 --- a/src/main/java/org/elasticsearch/index/analysis/PhoneTokenizer.java +++ b/src/main/java/org/elasticsearch/index/analysis/PhoneTokenizer.java @@ -1,163 +1,164 @@ package org.elasticsearch.index.analysis; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; -import org.apache.lucene.analysis.Tokenizer; -import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; -import org.elasticsearch.common.lang3.StringUtils; +import org.apache.lucene.analysis.Tokenizer; +import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; import com.google.i18n.phonenumbers.NumberParseException; import com.google.i18n.phonenumbers.PhoneNumberUtil; import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; -import java.io.IOException; -import java.io.Reader; -import java.util.ArrayList; -import java.util.List; - public class PhoneTokenizer extends Tokenizer { - // The raw input - private String stringToTokenize = null; - - // Position in the tokens array. We build all the tokens and return them one at a time as incrementToken gets called. - private int position = 0; - - /** - * The tokens are determined on the first iteration and then returned one at a time - * thereafter. - */ - - private List tokens = null; - - // The base class grabs the charTermAttribute each time incrementToken returns - protected CharTermAttribute charTermAttribute = addAttribute(CharTermAttribute.class); - - public PhoneTokenizer(Reader reader) { - super(reader); - } - - @Override - public final boolean incrementToken() throws IOException { - // Clear anything that is already saved in this.charTermAttribute - this.charTermAttribute.setEmpty(); - - if(tokens == null) { - // It's the 1st iteration, chop it up into tokens. - generateTokens(); - } - - // Return those tokens - return returnTokensOneAtATime(); - } - - private boolean returnTokensOneAtATime() { - // Token have already been generated. Return them 1 at a time - if(tokens != null) { - if(this.position == tokens.size()) { - // No more tokens - return false; - } - - // return each token, 1 at a time - this.charTermAttribute.append(tokens.get(this.position)); - this.position += 1; - return true; - } - return false; - } - - private void generateTokens() { - String uri = getStringToTokenize(); - - tokens = new ArrayList(); - tokens.add(getStringToTokenize()); - - // Rip off the "tel:" or "sip:" prefix - if (uri.indexOf("tel:") != -1 || uri.indexOf("sip:") != -1) { - uri = uri.substring(4); - } else { - // If it's not formatted at least this correctly then the whole string is 1 token. Sorry, put a tel: or sip: at the beginning so we know how to treat it - tokens.add(getStringToTokenize()); - return; - } - - // Drop anything after @. Most likely there's nothing of interest - String[] parts = StringUtils.split(uri, "@"); - if(parts.length == 0) { - return; - } - - String number = parts[0]; - - // Add a token for the raw unmanipulated address. Note this could be a username (sip) instead of telephone number so take it as is - tokens.add(number); - - // Let google's libphone try to parse it - PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); - PhoneNumber numberProto = null; - String countryCode = null; - try{ - // ZZ is the generic "I don't know the country code" region. Google's libphone library will try to infer it. - numberProto = phoneUtil.parse(number, "ZZ"); - if(numberProto != null) { - // Libphone likes it! - countryCode = String.valueOf(numberProto.getCountryCode()); - number = String.valueOf(numberProto.getNationalNumber()); - - // Add Country code, extension, and the number as tokens - tokens.add(countryCode); - if(!StringUtils.isEmpty(numberProto.getExtension())) { - tokens.add(numberProto.getExtension()); - } - - tokens.add(number); - } - } catch(NumberParseException e) { - // Libphone didn't like it, no biggie. We'll just ngram the number as it is. - } catch(StringIndexOutOfBoundsException e) { - // Libphone didn't like it, no biggie. We'll just ngram the number as it is. - } - - // ngram the phone number EG 19198243333 produces 9, 91, 919, etc - if(NumberUtils.isNumber(number)) { - for(int count = 1; count <= number.length(); count++) { - String token = number.substring(0, count); - tokens.add(token); - if(countryCode != null) { - // If there was a country code, add more ngrams such that 19198243333 produces 19, 191, 1919, etc - tokens.add(countryCode + token); - } - } - } - } - - /** - * Read the input into a local variable - * @return - */ - private String getStringToTokenize() { - if(this.stringToTokenize == null) { - try { - this.stringToTokenize = IOUtils.toString(input); - } - catch (IOException e) { - throw new RuntimeException(e); - } - } - return this.stringToTokenize; - } - - /** - * Nuke all state after each use (lucene will re-use an instance of this tokenizer over and over again) - */ - @Override - public final void reset() throws IOException { - super.reset(); - this.position = 0; - tokens = null; - this.stringToTokenize = null; - clearAttributes(); - } + // The raw input + private String stringToTokenize = null; + + // Position in the tokens array. We build all the tokens and return them one at a time as incrementToken + // gets called. + private int position = 0; + + /** + * The tokens are determined on the first iteration and then returned one at a time thereafter. + */ + + private List tokens = null; + + // The base class grabs the charTermAttribute each time incrementToken returns + protected CharTermAttribute charTermAttribute = addAttribute(CharTermAttribute.class); + + public PhoneTokenizer() { + } + + @Override + public final boolean incrementToken() throws IOException { + // Clear anything that is already saved in this.charTermAttribute + this.charTermAttribute.setEmpty(); + + if (tokens == null) { + // It's the 1st iteration, chop it up into tokens. + generateTokens(); + } + + // Return those tokens + return returnTokensOneAtATime(); + } + + private boolean returnTokensOneAtATime() { + // Token have already been generated. Return them 1 at a time + if (tokens != null) { + if (this.position == tokens.size()) { + // No more tokens + return false; + } + + // return each token, 1 at a time + this.charTermAttribute.append(tokens.get(this.position)); + this.position += 1; + return true; + } + return false; + } + + private void generateTokens() { + String uri = getStringToTokenize(); + + tokens = new ArrayList(); + tokens.add(getStringToTokenize()); + + // Rip off the "tel:" or "sip:" prefix + if (uri.indexOf("tel:") != -1 || uri.indexOf("sip:") != -1) { + uri = uri.substring(4); + } else { + // If it's not formatted at least this correctly then the whole string is 1 token. Sorry, put a + // tel: or sip: at the beginning so we know how to treat it + tokens.add(getStringToTokenize()); + return; + } + + // Drop anything after @. Most likely there's nothing of interest + String[] parts = StringUtils.split(uri, "@"); + if (parts.length == 0) { + return; + } + + String number = parts[0]; + + // Add a token for the raw unmanipulated address. Note this could be a username (sip) instead of + // telephone number so take it as is + tokens.add(number); + + // Let google's libphone try to parse it + PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); + PhoneNumber numberProto = null; + String countryCode = null; + try { + // ZZ is the generic "I don't know the country code" region. Google's libphone library will try to + // infer it. + numberProto = phoneUtil.parse(number, "ZZ"); + if (numberProto != null) { + // Libphone likes it! + countryCode = String.valueOf(numberProto.getCountryCode()); + number = String.valueOf(numberProto.getNationalNumber()); + + // Add Country code, extension, and the number as tokens + tokens.add(countryCode); + if (!StringUtils.isEmpty(numberProto.getExtension())) { + tokens.add(numberProto.getExtension()); + } + + tokens.add(number); + } + } catch (NumberParseException e) { + // Libphone didn't like it, no biggie. We'll just ngram the number as it is. + } catch (Exception e) { + // Ignored if Libphone cannot parse it. + } + + // ngram the phone number EG 19198243333 produces 9, 91, 919, etc + if (NumberUtils.isNumber(number)) { + for (int count = 1; count <= number.length(); count++) { + String token = number.substring(0, count); + tokens.add(token); + if (countryCode != null) { + // If there was a country code, add more ngrams such that 19198243333 produces 19, 191, + // 1919, etc + tokens.add(countryCode + token); + } + } + } + } + + /** + * Read the input into a local variable + * + * @return + */ + private String getStringToTokenize() { + if (this.stringToTokenize == null) { + try { + this.stringToTokenize = IOUtils.toString(input); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + return this.stringToTokenize; + } + + /** + * Nuke all state after each use (lucene will re-use an instance of this tokenizer over and over again) + */ + @Override + public final void reset() throws IOException { + super.reset(); + this.position = 0; + tokens = null; + this.stringToTokenize = null; + clearAttributes(); + } } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/analysis/PhoneTokenizerFactory.java b/src/main/java/org/elasticsearch/index/analysis/PhoneTokenizerFactory.java new file mode 100644 index 0000000..9775d6a --- /dev/null +++ b/src/main/java/org/elasticsearch/index/analysis/PhoneTokenizerFactory.java @@ -0,0 +1,18 @@ +package org.elasticsearch.index.analysis; + +import org.apache.lucene.analysis.Tokenizer; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.env.Environment; +import org.elasticsearch.index.IndexSettings; + +public class PhoneTokenizerFactory extends AbstractTokenizerFactory { + + public PhoneTokenizerFactory(IndexSettings indexSettings, Environment environment, String name, Settings settings) { + super(indexSettings, name, settings); + } + + @Override + public Tokenizer create() { + return new PhoneTokenizer(); + } +} diff --git a/src/main/java/org/elasticsearch/plugins/analysis/phone/PhoneAnalyzerProvider.java b/src/main/java/org/elasticsearch/plugins/analysis/phone/PhoneAnalyzerProvider.java index ff121d1..5348191 100644 --- a/src/main/java/org/elasticsearch/plugins/analysis/phone/PhoneAnalyzerProvider.java +++ b/src/main/java/org/elasticsearch/plugins/analysis/phone/PhoneAnalyzerProvider.java @@ -1,36 +1,26 @@ package org.elasticsearch.plugins.analysis.phone; - import java.io.IOException; import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; -import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.analysis.AbstractIndexAnalyzerProvider; import org.elasticsearch.index.analysis.PhoneAnalyzer; -import org.elasticsearch.index.settings.IndexSettings; public class PhoneAnalyzerProvider extends AbstractIndexAnalyzerProvider { - protected PhoneAnalyzer analyzer = new PhoneAnalyzer(); - public static final String NAME = "phone"; - - @Inject - public PhoneAnalyzerProvider(Index index, @IndexSettings Settings indexSettings, Environment env, @Assisted String name, @Assisted Settings settings) throws IOException { - super(index, indexSettings, name, settings); - } - public PhoneAnalyzer getAnalyzer() { - return analyzer; - } + protected PhoneAnalyzer analyzer = new PhoneAnalyzer(); - public PhoneAnalyzer get() { - return analyzer; - } + @Inject + public PhoneAnalyzerProvider(IndexSettings indexSettings, Environment env, String name, Settings settings) throws IOException { + super(indexSettings, name, settings); + } - public static String getName() { - return NAME; - } + @Override + public PhoneAnalyzer get() { + return analyzer; + } } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/plugins/analysis/phone/PhoneBinderProcessor.java b/src/main/java/org/elasticsearch/plugins/analysis/phone/PhoneBinderProcessor.java deleted file mode 100644 index 57136c1..0000000 --- a/src/main/java/org/elasticsearch/plugins/analysis/phone/PhoneBinderProcessor.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.elasticsearch.plugins.analysis.phone; -import org.elasticsearch.index.analysis.AnalysisModule; - -public class PhoneBinderProcessor extends AnalysisModule.AnalysisBinderProcessor { - - @Override - public void processAnalyzers(AnalyzersBindings analyzersBindings) { - analyzersBindings.processAnalyzer(PhoneAnalyzerProvider.NAME, PhoneAnalyzerProvider.class); - } -} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/plugins/analysis/phone/PhonePlugin.java b/src/main/java/org/elasticsearch/plugins/analysis/phone/PhonePlugin.java index 7a49968..cb9bdb6 100644 --- a/src/main/java/org/elasticsearch/plugins/analysis/phone/PhonePlugin.java +++ b/src/main/java/org/elasticsearch/plugins/analysis/phone/PhonePlugin.java @@ -1,31 +1,37 @@ package org.elasticsearch.plugins.analysis.phone; -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.index.analysis.AnalysisModule; -import org.elasticsearch.plugins.AbstractPlugin; +import static java.util.Collections.singletonMap; + +import java.util.Map; + +import org.apache.lucene.analysis.Analyzer; +import org.elasticsearch.index.analysis.AnalyzerProvider; +import org.elasticsearch.index.analysis.PhoneTokenizerFactory; +import org.elasticsearch.index.analysis.TokenizerFactory; +import org.elasticsearch.indices.analysis.AnalysisModule.AnalysisProvider; +import org.elasticsearch.plugins.AnalysisPlugin; import org.elasticsearch.plugins.Plugin; -public class PhonePlugin extends AbstractPlugin implements Plugin { +public class PhonePlugin extends Plugin implements AnalysisPlugin { + + public static final String NAME = "phone-plugin"; /* Return a description of this plugin. */ public String description() { return "Makes a best attempt at tokenizing a phone number or sip address"; } - /* This is the function that will register our analyzer with Elasticsearch. */ - public void onModule(AnalysisModule analysisModule) { - analysisModule.addProcessor(new PhoneBinderProcessor()); + public String name() { + return NAME; } - - @Override - public void processModule(Module module) { - if (module instanceof AnalysisModule) { - AnalysisModule analysisModule = (AnalysisModule) module; - analysisModule.addProcessor(new PhoneBinderProcessor()); - } + + @Override + public Map> getTokenizers() { + return singletonMap("phone_tokenizer", PhoneTokenizerFactory::new); + } + + @Override + public Map>> getAnalyzers() { + return singletonMap("phone", PhoneAnalyzerProvider::new); } - - public String name() { - return "phone-plugin"; - } } \ No newline at end of file diff --git a/src/main/resources/es-plugin.properties b/src/main/resources/es-plugin.properties deleted file mode 100644 index b061165..0000000 --- a/src/main/resources/es-plugin.properties +++ /dev/null @@ -1,3 +0,0 @@ -plugin=org.elasticsearch.plugins.analysis.phone.PhonePlugin -version=.1 -lucene=4.10.4 diff --git a/src/main/resources/plugin-descriptor.properties b/src/main/resources/plugin-descriptor.properties new file mode 100644 index 0000000..05ff35a --- /dev/null +++ b/src/main/resources/plugin-descriptor.properties @@ -0,0 +1,9 @@ +classname=org.elasticsearch.plugins.analysis.phone.PhonePlugin +description=phone-plugin +name=phone-plugin +version=${project.version} +elasticsearch.version=${elasticsearch.version} +java.version=${project.build.sourceVersion} +site=false +jvm=true +isolated=true diff --git a/src/test/java/tests/PhoneIntegrationTest.java b/src/test/java/tests/PhoneIntegrationTest.java index 338fbb4..9821d06 100644 --- a/src/test/java/tests/PhoneIntegrationTest.java +++ b/src/test/java/tests/PhoneIntegrationTest.java @@ -6,27 +6,34 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Locale; +import java.util.UUID; import java.util.concurrent.ExecutionException; +import org.apache.commons.lang3.StringUtils; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; import org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse; import org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse.AnalyzeToken; import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.common.lang3.StringUtils; -import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.plugins.PluginsService; -import org.elasticsearch.test.ElasticsearchIntegrationTest; +import org.elasticsearch.plugins.Plugin; +import org.elasticsearch.plugins.PluginInfo; +import org.elasticsearch.plugins.analysis.phone.PhonePlugin; +import org.elasticsearch.test.ESIntegTestCase; +import org.elasticsearch.test.ESIntegTestCase.ClusterScope; +import org.elasticsearch.test.ESIntegTestCase.Scope; import org.junit.Before; import org.junit.Test; -@ElasticsearchIntegrationTest.ClusterScope(scope = ElasticsearchIntegrationTest.Scope.SUITE) -public class PhoneIntegrationTest extends ElasticsearchIntegrationTest { +@ClusterScope(scope = Scope.SUITE) +public class PhoneIntegrationTest extends ESIntegTestCase { static { ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true); @@ -57,16 +64,31 @@ public void setUp() throws Exception { @Override protected Settings nodeSettings(int nodeOrdinal) { - org.elasticsearch.common.settings.ImmutableSettings.Builder builder = ImmutableSettings.builder() + return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) - .put("plugins." + PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, true); - return builder.build(); + .put(IndexMetaData.SETTING_VERSION_CREATED, "2010099") // not sure why this is needed, see org.elasticsearch.Version#V_2_1_0_ID + .put(IndexMetaData.SETTING_INDEX_UUID, UUID.randomUUID().toString()) + .build(); } - @Test + @SuppressWarnings("unchecked") + @Override + protected Collection> nodePlugins() { + return Collections.singleton(PhonePlugin.class); + } + + @Test public void testPluginIsLoaded() { - NodesInfoResponse infos = client().admin().cluster().prepareNodesInfo().setPlugins(true).execute().actionGet(); - assertThat(infos.getNodes()[0].getPlugins().getInfos().get(0).getName(), is("phone-plugin")); + + NodesInfoResponse infos = client().admin().cluster().prepareNodesInfo().setPlugins(true).get(); + boolean pluginLoaded = false; + List pluginInfos = infos.getNodes().get(0).getPlugins().getPluginInfos(); + for (PluginInfo pluginInfo : pluginInfos) { + if (PhonePlugin.NAME.equals(pluginInfo.getName())) { + pluginLoaded = true; + } + } + assertTrue("Could not find expected plugin: " + PhonePlugin.NAME, pluginLoaded); } @Test