Java 类org.apache.lucene.analysis.ngram.EdgeNGramTokenFilter 实例源码

项目:elasticsearch_my    文件:NGramTokenizerFactoryTests.java   
public void testBackwardsCompatibilityEdgeNgramTokenFilter() throws Exception {
    int iters = scaledRandomIntBetween(20, 100);
    for (int i = 0; i < iters; i++) {
        final Index index = new Index("test", "_na_");
        final String name = "ngr";
        Version v = randomVersion(random());
        Builder builder = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 3);
        boolean reverse = random().nextBoolean();
        if (reverse) {
            builder.put("side", "back");
        }
        Settings settings = builder.build();
        Settings indexSettings = newAnalysisSettingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, v.id).build();
        Tokenizer tokenizer = new MockTokenizer();
        tokenizer.setReader(new StringReader("foo bar"));
        TokenStream edgeNGramTokenFilter = new EdgeNGramTokenFilterFactory(IndexSettingsModule.newIndexSettings(index, indexSettings), null, name, settings).create(tokenizer);
        if (reverse) {
            assertThat(edgeNGramTokenFilter, instanceOf(ReverseStringFilter.class));
        } else {
            assertThat(edgeNGramTokenFilter, instanceOf(EdgeNGramTokenFilter.class));
        }
    }
}
项目:NYBC    文件:EdgeNGramFilterFactory.java   
@Override
public void init(Map<String, String> args) {
  super.init(args);
  String maxArg = args.get("maxGramSize");
  maxGramSize = (maxArg != null ? Integer.parseInt(maxArg)
      : EdgeNGramTokenFilter.DEFAULT_MAX_GRAM_SIZE);

  String minArg = args.get("minGramSize");
  minGramSize = (minArg != null ? Integer.parseInt(minArg)
      : EdgeNGramTokenFilter.DEFAULT_MIN_GRAM_SIZE);

  side = args.get("side");
  if (side == null) {
    side = EdgeNGramTokenFilter.Side.FRONT.getLabel();
  }
}
项目:opensearchserver    文件:EdgeNGramFilter.java   
@Override
protected void initProperties() throws SearchLibException {
    super.initProperties();
    addProperty(ClassPropertyEnum.MIN_GRAM,
            Integer.toString(EdgeNGramTokenFilter.DEFAULT_MIN_GRAM_SIZE),
            null, 10, 1);
    addProperty(ClassPropertyEnum.MAX_GRAM,
            Integer.toString(EdgeNGramTokenFilter.DEFAULT_MAX_GRAM_SIZE),
            null, 10, 1);
    addProperty(ClassPropertyEnum.SIDE,
            EdgeNGramTokenFilter.DEFAULT_SIDE.getLabel(), SIDE_VALUE_LIST,
            0, 0);
}
项目:search    文件:TestRandomChains.java   
@Override public Object create(Random random) {
  return random.nextBoolean() 
      ? EdgeNGramTokenFilter.Side.FRONT 
      : EdgeNGramTokenFilter.Side.BACK;
}
项目:search    文件:SimpleNaiveBayesClassifierTest.java   
@Override
protected TokenStreamComponents createComponents(String fieldName, Reader reader) {
  final Tokenizer tokenizer = new KeywordTokenizer(reader);
  return new TokenStreamComponents(tokenizer, new ReverseStringFilter(new EdgeNGramTokenFilter(new ReverseStringFilter(tokenizer), 10, 20)));
}
项目:NYBC    文件:EdgeNGramFilterFactory.java   
@Override
public EdgeNGramTokenFilter create(TokenStream input) {
  return new EdgeNGramTokenFilter(input, side, minGramSize, maxGramSize);
}
项目:NYBC    文件:TestRandomChains.java   
@Override public Object create(Random random) {
  return random.nextBoolean() 
      ? EdgeNGramTokenFilter.Side.FRONT 
      : EdgeNGramTokenFilter.Side.BACK;
}
项目:opensearchserver    文件:EdgeNGramFilter.java   
@Override
public TokenStream create(TokenStream input) {
    return new EdgeNGramTokenFilter(input, side, min, max);
}
项目:Maskana-Gestor-de-Conocimiento    文件:TestRandomChains.java   
@Override public Object create(Random random) {
  return random.nextBoolean() 
      ? EdgeNGramTokenFilter.Side.FRONT 
      : EdgeNGramTokenFilter.Side.BACK;
}
项目:Maskana-Gestor-de-Conocimiento    文件:SimpleNaiveBayesClassifierTest.java   
@Override
protected TokenStreamComponents createComponents(String fieldName, Reader reader) {
  final Tokenizer tokenizer = new KeywordTokenizer(reader);
  return new TokenStreamComponents(tokenizer, new ReverseStringFilter(TEST_VERSION_CURRENT, new EdgeNGramTokenFilter(TEST_VERSION_CURRENT, new ReverseStringFilter(TEST_VERSION_CURRENT, tokenizer), 10, 20)));
}
项目:t4f-data    文件:NGramTest.java   
@Override
public TokenStream tokenStream(String fieldName, Reader reader) {
    return new EdgeNGramTokenFilter(new KeywordTokenizer(reader), EdgeNGramTokenFilter.Side.FRONT, 1, 4);
}
项目:t4f-data    文件:NGramTest.java   
@Override
public TokenStream tokenStream(String fieldName, Reader reader) {
    return new EdgeNGramTokenFilter(new KeywordTokenizer(reader), EdgeNGramTokenFilter.Side.BACK, 1, 4);
}