当前位置: 首页>>代码示例>>Java>>正文


Java EnglishAnalyzer类代码示例

本文整理汇总了Java中org.apache.lucene.analysis.en.EnglishAnalyzer的典型用法代码示例。如果您正苦于以下问题:Java EnglishAnalyzer类的具体用法?Java EnglishAnalyzer怎么用?Java EnglishAnalyzer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


EnglishAnalyzer类属于org.apache.lucene.analysis.en包,在下文中一共展示了EnglishAnalyzer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testAnalyzerAlias

import org.apache.lucene.analysis.en.EnglishAnalyzer; //导入依赖的package包/类
public void testAnalyzerAlias() throws IOException {
    Settings settings = Settings.builder()
        .put("index.analysis.analyzer.foobar.alias","default")
        .put("index.analysis.analyzer.foobar.type", "keyword")
        .put("index.analysis.analyzer.foobar_search.alias","default_search")
        .put("index.analysis.analyzer.foobar_search.type","english")
        .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
        // analyzer aliases are only allowed in 2.x indices
        .put(IndexMetaData.SETTING_VERSION_CREATED, VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.V_2_3_5))
        .build();
    AnalysisRegistry newRegistry = getNewRegistry(settings);
    IndexAnalyzers indexAnalyzers = getIndexAnalyzers(newRegistry, settings);
    assertThat(indexAnalyzers.get("default").analyzer(), is(instanceOf(KeywordAnalyzer.class)));
    assertThat(indexAnalyzers.get("default_search").analyzer(), is(instanceOf(EnglishAnalyzer.class)));
    assertWarnings("setting [index.analysis.analyzer.foobar.alias] is only allowed on index [test] because it was created before " +
                    "5.x; analyzer aliases can no longer be created on new indices.",
            "setting [index.analysis.analyzer.foobar_search.alias] is only allowed on index [test] because it was created before " +
                    "5.x; analyzer aliases can no longer be created on new indices.");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:AnalysisModuleTests.java

示例2: InMemoryIndex

import org.apache.lucene.analysis.en.EnglishAnalyzer; //导入依赖的package包/类
public InMemoryIndex(Map<String,String> id2Text){
    Analyzer analyzer = new EnglishAnalyzer();
    IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
    iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
    try {
        IndexWriter writer = new IndexWriter(directory, iwc);
        for (String id:id2Text.keySet()) {
            Document doc=new Document();
            doc.add(new StringField("id", id, Field.Store.YES));
            doc.add(new TextField("content", id2Text.get(id), Field.Store.YES));
            writer.addDocument(doc);
        }
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:linzeqipku,项目名称:SnowGraph,代码行数:18,代码来源:InMemoryIndex.java

示例3: search

import org.apache.lucene.analysis.en.EnglishAnalyzer; //导入依赖的package包/类
private static List<String> search(List<String> contents, String query, int n) throws IOException, ParseException {
    List<String> r=new ArrayList<>();
    Directory dir=new RAMDirectory();
    IndexWriter indexWriter=new IndexWriter(dir, new IndexWriterConfig(new EnglishAnalyzer()));
    for (String method:contents){
        Document document=new Document();
        document.add(new TextField("content",method, Field.Store.YES));
        indexWriter.addDocument(document);
    }
    indexWriter.close();
    QueryParser qp = new QueryParser("content", new EnglishAnalyzer());
    IndexSearcher indexSearcher = new IndexSearcher(DirectoryReader.open(dir));
    TopDocs topDocs = indexSearcher.search(qp.parse(query), n);
    for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
        r.add(indexSearcher.doc(scoreDoc.doc).get("content"));
    }
    return r;
}
 
开发者ID:linzeqipku,项目名称:SnowGraph,代码行数:19,代码来源:CodePatternSearcher.java

示例4: annotate

import org.apache.lucene.analysis.en.EnglishAnalyzer; //导入依赖的package包/类
@Override
public List<Annotation> annotate(String text) throws Exception {
	text = SimpleTokenizer.format(text);
	Analyzer analyser = new EnglishAnalyzer(Version.LUCENE_47, CharArraySet.EMPTY_SET);
	TokenFilter filter = new EnglishMinimalStemFilter(analyser.tokenStream("text", new StringReader(text)));
	List<Annotation> out = Lists.newArrayList();
	while (filter.incrementToken()) {
		CharTermAttribute az = filter.getAttribute(CharTermAttribute.class);
		OffsetAttribute o = filter.getAttribute(OffsetAttribute.class);
		String token = text.substring(o.startOffset(), o.endOffset());
		String lemma = az.toString();
		Annotation t = new Annotation();
		t.setForm(token);
		t.setLemma(lemma);
		out.add(t);
	}
	if (out.size() == 0) {
		log.debug("Input string is empty");
	}
	filter.close();
	analyser.close();
	return out;
}
 
开发者ID:kouylekov,项目名称:edits,代码行数:24,代码来源:LuceneTokenizer.java

示例5: testFuzzyQuery

import org.apache.lucene.analysis.en.EnglishAnalyzer; //导入依赖的package包/类
@Test
public void testFuzzyQuery() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperBoolean());
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    FuzzyCondition fuzzyCondition = new FuzzyCondition(0.5f, "name", "tr", 1, 2, 49, true);
    Query query = fuzzyCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(org.apache.lucene.search.FuzzyQuery.class, query.getClass());
    org.apache.lucene.search.FuzzyQuery luceneQuery = (org.apache.lucene.search.FuzzyQuery) query;
    Assert.assertEquals("name", luceneQuery.getField());
    Assert.assertEquals("tr", luceneQuery.getTerm().text());
    Assert.assertEquals(1, luceneQuery.getMaxEdits());
    Assert.assertEquals(2, luceneQuery.getPrefixLength());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
开发者ID:Stratio,项目名称:stratio-cassandra,代码行数:20,代码来源:FuzzyConditionTest.java

示例6: testInteger

import org.apache.lucene.analysis.en.EnglishAnalyzer; //导入依赖的package包/类
@Test
public void testInteger() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperInteger(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    MatchCondition matchCondition = new MatchCondition(0.5f, "name", 42);
    Query query = matchCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals(42, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(42, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
开发者ID:Stratio,项目名称:stratio-cassandra,代码行数:19,代码来源:MatchConditionTest.java

示例7: testLong

import org.apache.lucene.analysis.en.EnglishAnalyzer; //导入依赖的package包/类
@Test
public void testLong() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperLong(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    MatchCondition matchCondition = new MatchCondition(0.5f, "name", 42L);
    Query query = matchCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals(42L, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(42L, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
开发者ID:Stratio,项目名称:stratio-cassandra,代码行数:19,代码来源:MatchConditionTest.java

示例8: testFloat

import org.apache.lucene.analysis.en.EnglishAnalyzer; //导入依赖的package包/类
@Test
public void testFloat() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperFloat(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    MatchCondition matchCondition = new MatchCondition(0.5f, "name", 42.42F);
    Query query = matchCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals(42.42F, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(42.42F, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
开发者ID:Stratio,项目名称:stratio-cassandra,代码行数:19,代码来源:MatchConditionTest.java

示例9: testDouble

import org.apache.lucene.analysis.en.EnglishAnalyzer; //导入依赖的package包/类
@Test
public void testDouble() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperDouble(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    MatchCondition matchCondition = new MatchCondition(0.5f, "name", 42.42D);
    Query query = matchCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals(42.42D, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(42.42D, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
开发者ID:Stratio,项目名称:stratio-cassandra,代码行数:19,代码来源:MatchConditionTest.java

示例10: testStringClose

import org.apache.lucene.analysis.en.EnglishAnalyzer; //导入依赖的package包/类
@Test
public void testStringClose() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperBoolean());
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    RangeCondition rangeCondition = new RangeCondition(0.5f, "name", "alpha", "beta", true, true);
    Query query = rangeCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(TermRangeQuery.class, query.getClass());
    Assert.assertEquals("name", ((TermRangeQuery) query).getField());
    Assert.assertEquals("alpha", ((TermRangeQuery) query).getLowerTerm().utf8ToString());
    Assert.assertEquals("beta", ((TermRangeQuery) query).getUpperTerm().utf8ToString());
    Assert.assertEquals(true, ((TermRangeQuery) query).includesLower());
    Assert.assertEquals(true, ((TermRangeQuery) query).includesUpper());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
开发者ID:Stratio,项目名称:stratio-cassandra,代码行数:20,代码来源:RangeConditionTest.java

示例11: testStringOpen

import org.apache.lucene.analysis.en.EnglishAnalyzer; //导入依赖的package包/类
@Test
public void testStringOpen() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperBoolean());
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    RangeCondition rangeCondition = new RangeCondition(0.5f, "name", "alpha", null, true, false);
    Query query = rangeCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(TermRangeQuery.class, query.getClass());
    Assert.assertEquals("name", ((TermRangeQuery) query).getField());
    Assert.assertEquals("alpha", ((TermRangeQuery) query).getLowerTerm().utf8ToString());
    Assert.assertEquals(null, ((TermRangeQuery) query).getUpperTerm());
    Assert.assertNull(((TermRangeQuery) query).getUpperTerm());
    Assert.assertEquals(true, ((TermRangeQuery) query).includesLower());
    Assert.assertEquals(false, ((TermRangeQuery) query).includesUpper());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
开发者ID:Stratio,项目名称:stratio-cassandra,代码行数:21,代码来源:RangeConditionTest.java

示例12: testIntegerClose

import org.apache.lucene.analysis.en.EnglishAnalyzer; //导入依赖的package包/类
@Test
public void testIntegerClose() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperInteger(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    RangeCondition rangeCondition = new RangeCondition(0.5f, "name", 42, 43, false, false);
    Query query = rangeCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals("name", ((NumericRangeQuery<?>) query).getField());
    Assert.assertEquals(42, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(43, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
开发者ID:Stratio,项目名称:stratio-cassandra,代码行数:20,代码来源:RangeConditionTest.java

示例13: testIntegerOpen

import org.apache.lucene.analysis.en.EnglishAnalyzer; //导入依赖的package包/类
@Test
public void testIntegerOpen() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperInteger(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    RangeCondition rangeCondition = new RangeCondition(0.5f, "name", 42, null, true, false);
    Query query = rangeCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals("name", ((NumericRangeQuery<?>) query).getField());
    Assert.assertEquals(42, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(null, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
开发者ID:Stratio,项目名称:stratio-cassandra,代码行数:20,代码来源:RangeConditionTest.java

示例14: testLongClose

import org.apache.lucene.analysis.en.EnglishAnalyzer; //导入依赖的package包/类
@Test
public void testLongClose() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperLong(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    RangeCondition rangeCondition = new RangeCondition(0.5f, "name", 42L, 43, false, false);
    Query query = rangeCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals("name", ((NumericRangeQuery<?>) query).getField());
    Assert.assertEquals(42L, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(43L, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
开发者ID:Stratio,项目名称:stratio-cassandra,代码行数:20,代码来源:RangeConditionTest.java

示例15: testLongOpen

import org.apache.lucene.analysis.en.EnglishAnalyzer; //导入依赖的package包/类
@Test
public void testLongOpen() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperLong(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    RangeCondition rangeCondition = new RangeCondition(0.5f, "name", 42f, null, true, false);
    Query query = rangeCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals("name", ((NumericRangeQuery<?>) query).getField());
    Assert.assertEquals(42L, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(null, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
开发者ID:Stratio,项目名称:stratio-cassandra,代码行数:20,代码来源:RangeConditionTest.java


注:本文中的org.apache.lucene.analysis.en.EnglishAnalyzer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。