Java 类org.apache.lucene.analysis.en.EnglishAnalyzer 实例源码

项目:elasticsearch_my    文件:AnalysisModuleTests.java   
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.");
}
项目:SnowGraph    文件:InMemoryIndex.java   
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();
    }
}
项目:SnowGraph    文件:CodePatternSearcher.java   
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;
}
项目:edits    文件:LuceneTokenizer.java   
@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;
}
项目:stratio-cassandra    文件:FuzzyConditionTest.java   
@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);
}
项目:stratio-cassandra    文件:MatchConditionTest.java   
@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);
}
项目:stratio-cassandra    文件:MatchConditionTest.java   
@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);
}
项目:stratio-cassandra    文件:MatchConditionTest.java   
@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);
}
项目:stratio-cassandra    文件:MatchConditionTest.java   
@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);
}
项目:stratio-cassandra    文件:RangeConditionTest.java   
@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);
}
项目:stratio-cassandra    文件:RangeConditionTest.java   
@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);
}
项目:stratio-cassandra    文件:RangeConditionTest.java   
@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);
}
项目:stratio-cassandra    文件:RangeConditionTest.java   
@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);
}
项目:stratio-cassandra    文件:RangeConditionTest.java   
@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);
}
项目:stratio-cassandra    文件:RangeConditionTest.java   
@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);
}
项目:stratio-cassandra    文件:RangeConditionTest.java   
@Test
public void testFloatClose() {

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

    RangeCondition rangeCondition = new RangeCondition(0.5f, "name", 42.42D, 43.42F, 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.42F, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(43.42f, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
项目:stratio-cassandra    文件:RangeConditionTest.java   
@Test
public void testFloatOpen() {

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

    RangeCondition rangeCondition = new RangeCondition(0.5f, "name", 42.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(42.42f, ((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);
}
项目:stratio-cassandra    文件:RangeConditionTest.java   
@Test
public void testDoubleClose() {

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

    RangeCondition rangeCondition = new RangeCondition(0.5f, "name", 42.42D, 43.42D, 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.42D, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(43.42D, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
项目:stratio-cassandra    文件:RangeConditionTest.java   
@Test
public void testDoubleOpen() {

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

    RangeCondition rangeCondition = new RangeCondition(0.5f, "name", 42.42D, 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.42D, ((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);
}
项目:stratio-cassandra    文件:RangeConditionTest.java   
@Test
public void testInetV4() {

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

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

    Assert.assertNotNull(query);
    Assert.assertEquals(TermRangeQuery.class, query.getClass());
    Assert.assertEquals("name", ((TermRangeQuery) query).getField());
    Assert.assertEquals("192.168.0.1", ((TermRangeQuery) query).getLowerTerm().utf8ToString());
    Assert.assertEquals("192.168.0.45", ((TermRangeQuery) query).getUpperTerm().utf8ToString());
    Assert.assertEquals(true, ((TermRangeQuery) query).includesLower());
    Assert.assertEquals(true, ((TermRangeQuery) query).includesUpper());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
项目:stratio-cassandra    文件:RangeConditionTest.java   
@Test
public void testInetV6() {

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

    RangeCondition rangeCondition = range("name").boost(0.5f)
                                                 .lower("2001:DB8:2de::e13")
                                                 .upper("2001:DB8:02de::e23")
                                                 .includeLower(true)
                                                 .includeUpper(true)
                                                 .build();
    Query query = rangeCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(TermRangeQuery.class, query.getClass());
    Assert.assertEquals("name", ((TermRangeQuery) query).getField());
    Assert.assertEquals("2001:db8:2de:0:0:0:0:e13", ((TermRangeQuery) query).getLowerTerm().utf8ToString());
    Assert.assertEquals("2001:db8:2de:0:0:0:0:e23", ((TermRangeQuery) query).getUpperTerm().utf8ToString());
    Assert.assertEquals(true, ((TermRangeQuery) query).includesLower());
    Assert.assertEquals(true, ((TermRangeQuery) query).includesUpper());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
项目:stratio-cassandra    文件:WildcardConditionTest.java   
@Test
public void testString() {

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

    WildcardCondition wildcardCondition = new WildcardCondition(0.5f, "name", "tr*");
    Query query = wildcardCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(org.apache.lucene.search.WildcardQuery.class, query.getClass());
    org.apache.lucene.search.WildcardQuery luceneQuery = (org.apache.lucene.search.WildcardQuery) query;
    Assert.assertEquals("name", luceneQuery.getField());
    Assert.assertEquals("tr*", luceneQuery.getTerm().text());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
项目:stratio-cassandra    文件:WildcardConditionTest.java   
@Test
public void testInetV4() {

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

    WildcardCondition wildcardCondition = new WildcardCondition(0.5f, "name", "192.168.*");
    Query query = wildcardCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(org.apache.lucene.search.WildcardQuery.class, query.getClass());
    org.apache.lucene.search.WildcardQuery luceneQuery = (org.apache.lucene.search.WildcardQuery) query;
    Assert.assertEquals("name", luceneQuery.getField());
    Assert.assertEquals("192.168.*", luceneQuery.getTerm().text());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
项目:stratio-cassandra    文件:WildcardConditionTest.java   
@Test
public void testInetV6() {

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

    WildcardCondition wildcardCondition = new WildcardCondition(0.5f, "name", "2001:db8:2de:0:0:0:0:e*");
    Query query = wildcardCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(org.apache.lucene.search.WildcardQuery.class, query.getClass());
    org.apache.lucene.search.WildcardQuery luceneQuery = (org.apache.lucene.search.WildcardQuery) query;
    Assert.assertEquals("name", luceneQuery.getField());
    Assert.assertEquals("2001:db8:2de:0:0:0:0:e*", luceneQuery.getTerm().text());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
项目:stratio-cassandra    文件:PrefixConditionTest.java   
@Test
public void testString() {

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

    PrefixCondition prefixCondition = new PrefixCondition(0.5f, "name", "tr");
    Query query = prefixCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(PrefixQuery.class, query.getClass());
    PrefixQuery luceneQuery = (PrefixQuery) query;
    Assert.assertEquals("name", luceneQuery.getField());
    Assert.assertEquals("tr", luceneQuery.getPrefix().text());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
项目:stratio-cassandra    文件:PrefixConditionTest.java   
@Test
public void testInetV4() {

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

    PrefixCondition wildcardCondition = new PrefixCondition(0.5f, "name", "192.168.");
    Query query = wildcardCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(PrefixQuery.class, query.getClass());
    PrefixQuery luceneQuery = (PrefixQuery) query;
    Assert.assertEquals("name", luceneQuery.getField());
    Assert.assertEquals("192.168.", luceneQuery.getPrefix().text());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
项目:stratio-cassandra    文件:PrefixConditionTest.java   
@Test
public void testInetV6() {

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

    PrefixCondition wildcardCondition = new PrefixCondition(0.5f, "name", "2001:db8:2de:0:0:0:0:e");
    Query query = wildcardCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(PrefixQuery.class, query.getClass());
    PrefixQuery luceneQuery = (PrefixQuery) query;
    Assert.assertEquals("name", luceneQuery.getField());
    Assert.assertEquals("2001:db8:2de:0:0:0:0:e", luceneQuery.getPrefix().text());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
项目:stratio-cassandra    文件:PhraseConditionTest.java   
@Test
public void testPhraseQuery() {

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

    List<String> values = new ArrayList<>();
    values.add("hola");
    values.add("adios");

    PhraseCondition phraseCondition = new PhraseCondition(0.5f, "name", values, 2);
    Query query = phraseCondition.query(mappers);
    Assert.assertNotNull(query);
    Assert.assertEquals(org.apache.lucene.search.PhraseQuery.class, query.getClass());
    org.apache.lucene.search.PhraseQuery luceneQuery = (org.apache.lucene.search.PhraseQuery) query;
    Assert.assertEquals(values.size(), luceneQuery.getTerms().length);
    Assert.assertEquals(2, luceneQuery.getSlop());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
项目:tmfcore    文件:IndexesUtil.java   
/**
 * Initialize the classifiers. This static method initializes the
 * italian and the english classifiers under the hood. You must
 * call this function after you have constructed an instance of the
 * TMFVariables class as described in TMFVariables docs.
 *
 * If you don't call this method, when you use the classifier you
 * will get a NullPointerException in Classifier().
 *
 * @since 2.0.0.0.
 */
public static void init() {
    unchecked(() -> {
        LOG.debug("[initializator] - BEGIN");

        // build italian searcher
        Directory contextIndexDirIT = LuceneManager.pickDirectory(new File(TMFVariables.CORPUS_INDEX_IT));
        LOG.info("Corpus index used for italian: " + contextIndexDirIT);
        LuceneManager contextLuceneManagerIT = new LuceneManager(contextIndexDirIT);
        contextLuceneManagerIT.setLuceneDefaultAnalyzer(new ItalianAnalyzer(Version.LUCENE_36, TMFVariables.STOPWORDS_IT));
        ITALIAN_CORPUS_INDEX_SEARCHER = new SimpleSearcher(contextLuceneManagerIT);

        // build english searcher
        Directory contextIndexDirEN = LuceneManager.pickDirectory(new File(TMFVariables.CORPUS_INDEX_EN));
        LOG.info("Corpus index used for english: " + contextIndexDirEN);
        LuceneManager contextLuceneManagerEN = new LuceneManager(contextIndexDirEN);
        contextLuceneManagerEN.setLuceneDefaultAnalyzer(new EnglishAnalyzer(Version.LUCENE_36, TMFVariables.STOPWORDS_EN));
        ENGLISH_CORPUS_INDEX_SEARCHER = new SimpleSearcher(contextLuceneManagerEN);

        LOG.debug("[initializator] - END");
    });
}
项目:coursera_recommender_systems    文件:LuceneModelBuilder.java   
private void writeMovies(Directory dir) throws IOException {
    Analyzer analyzer = new EnglishAnalyzer(Version.LUCENE_35);
    IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_35, analyzer);
    config.setOpenMode(IndexWriterConfig.OpenMode.CREATE);

    IndexWriter writer = new IndexWriter(dir, config);
    try {
        logger.info("Building Lucene movie model");
        for (long movie: dao.getItemIds()) {
            logger.debug("building model for {}", movie);
            Document doc = makeMovieDocument(movie);
            writer.addDocument(doc);
        }
    } finally {
        writer.close();
    }
}
项目:elasticsearch_my    文件:EnglishAnalyzerProvider.java   
public EnglishAnalyzerProvider(IndexSettings indexSettings, Environment env, String name, Settings settings) {
    super(indexSettings, name, settings);
    analyzer = new EnglishAnalyzer(
        Analysis.parseStopWords(env, indexSettings.getIndexVersionCreated(), settings, EnglishAnalyzer.getDefaultStopSet()),
        Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
    );
    analyzer.setVersion(version);
}
项目:elasticsearch_my    文件:AnalysisRegistryTests.java   
public void testOverrideDefaultAnalyzer() throws IOException {
    Version version = VersionUtils.randomVersion(random());
    Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
    IndexAnalyzers indexAnalyzers = registry.build(IndexSettingsModule.newIndexSettings("index", settings),
        singletonMap("default", analyzerProvider("default"))
            , emptyMap(), emptyMap(), emptyMap(), emptyMap());
    assertThat(indexAnalyzers.getDefaultIndexAnalyzer().analyzer(), instanceOf(EnglishAnalyzer.class));
    assertThat(indexAnalyzers.getDefaultSearchAnalyzer().analyzer(), instanceOf(EnglishAnalyzer.class));
    assertThat(indexAnalyzers.getDefaultSearchQuoteAnalyzer().analyzer(), instanceOf(EnglishAnalyzer.class));
}
项目:elasticsearch_my    文件:AnalysisRegistryTests.java   
public void testOverrideDefaultIndexAnalyzerIsUnsupported() {
    Version version = VersionUtils.randomVersionBetween(random(), Version.V_5_0_0_alpha1, Version.CURRENT);
    Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
    AnalyzerProvider<?> defaultIndex = new PreBuiltAnalyzerProvider("default_index", AnalyzerScope.INDEX, new EnglishAnalyzer());
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
            () -> registry.build(IndexSettingsModule.newIndexSettings("index", settings),
                    singletonMap("default_index", defaultIndex), emptyMap(), emptyMap(), emptyMap(), emptyMap()));
    assertTrue(e.getMessage().contains("[index.analysis.analyzer.default_index] is not supported"));
}
项目:elasticsearch_my    文件:AnalysisRegistryTests.java   
public void testBackCompatOverrideDefaultIndexAnalyzer() {
    Version version = VersionUtils.randomVersionBetween(random(), VersionUtils.getFirstVersion(),
            VersionUtils.getPreviousVersion(Version.V_5_0_0_alpha1));
    Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
    IndexAnalyzers indexAnalyzers = registry.build(IndexSettingsModule.newIndexSettings("index", settings),
            singletonMap("default_index", analyzerProvider("default_index")), emptyMap(), emptyMap(), emptyMap(), emptyMap());
    assertThat(indexAnalyzers.getDefaultIndexAnalyzer().analyzer(), instanceOf(EnglishAnalyzer.class));
    assertThat(indexAnalyzers.getDefaultSearchAnalyzer().analyzer(), instanceOf(StandardAnalyzer.class));
    assertThat(indexAnalyzers.getDefaultSearchQuoteAnalyzer().analyzer(), instanceOf(StandardAnalyzer.class));
    assertWarnings("setting [index.analysis.analyzer.default_index] is deprecated, use [index.analysis.analyzer.default] " +
            "instead for index [index]");
}
项目:elasticsearch_my    文件:AnalysisRegistryTests.java   
public void testOverrideDefaultSearchAnalyzer() {
    Version version = VersionUtils.randomVersion(random());
    Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
    IndexAnalyzers indexAnalyzers = registry.build(IndexSettingsModule.newIndexSettings("index", settings),
            singletonMap("default_search", analyzerProvider("default_search")), emptyMap(), emptyMap(), emptyMap(), emptyMap());
    assertThat(indexAnalyzers.getDefaultIndexAnalyzer().analyzer(), instanceOf(StandardAnalyzer.class));
    assertThat(indexAnalyzers.getDefaultSearchAnalyzer().analyzer(), instanceOf(EnglishAnalyzer.class));
    assertThat(indexAnalyzers.getDefaultSearchQuoteAnalyzer().analyzer(), instanceOf(EnglishAnalyzer.class));
}
项目:elasticsearch_my    文件:AnalysisRegistryTests.java   
public void testBackCompatOverrideDefaultIndexAndSearchAnalyzer() {
    Version version = VersionUtils.randomVersionBetween(random(), VersionUtils.getFirstVersion(),
            VersionUtils.getPreviousVersion(Version.V_5_0_0_alpha1));
    Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
    Map<String, AnalyzerProvider<?>> analyzers = new HashMap<>();
    analyzers.put("default_index", analyzerProvider("default_index"));
    analyzers.put("default_search", analyzerProvider("default_search"));
    IndexAnalyzers indexAnalyzers = registry.build(IndexSettingsModule.newIndexSettings("index", settings),
            analyzers, Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap());
    assertThat(indexAnalyzers.getDefaultIndexAnalyzer().analyzer(), instanceOf(EnglishAnalyzer.class));
    assertThat(indexAnalyzers.getDefaultSearchAnalyzer().analyzer(), instanceOf(EnglishAnalyzer.class));
    assertThat(indexAnalyzers.getDefaultSearchQuoteAnalyzer().analyzer(), instanceOf(EnglishAnalyzer.class));
    assertWarnings("setting [index.analysis.analyzer.default_index] is deprecated, use [index.analysis.analyzer.default] " +
            "instead for index [index]");
}
项目:Elasticsearch    文件:EnglishAnalyzerProvider.java   
@Inject
public EnglishAnalyzerProvider(Index index, IndexSettingsService indexSettingsService, Environment env, @Assisted String name, @Assisted Settings settings) {
    super(index, indexSettingsService.getSettings(), name, settings);
    analyzer = new EnglishAnalyzer(Analysis.parseStopWords(env, settings, EnglishAnalyzer.getDefaultStopSet()),
                                   Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET));
    analyzer.setVersion(version);
}
项目:appng-examples    文件:PersonSearchProvider.java   
public Iterable<Document> doSearch(Environment env, Site site, Application application, Directory directory,
        String term, String language, String[] parseFields, Analyzer analyzer, String highlightWith,
        Map<String, String> parameters) throws IOException {
    List<Document> documents = new ArrayList<>();

    if("en".equalsIgnoreCase(language) && analyzer instanceof EnglishAnalyzer){
        List<String> fieldList = Arrays.asList(parseFields);
        if(fieldList.contains(Document.FIELD_TITLE)){
            List<Person> persons = service.getPersonsByLastNameLikeOrNameLike(term);
            persons.forEach(p -> documents.add(p.toDocument(site, application)));
        }
    }

    return documents;
}
项目:appng-examples    文件:PersonDocumentProvider.java   
public Iterable<DocumentProducer> getDocumentProducers(Site site, Application application)
        throws InterruptedException, TimeoutException {
    DocumentProducer documentProducer = new DocumentProducer(EnglishAnalyzer.class, application.getName());
    List<Person> all = service.getAllPersons();
    for (Person person : all) {
        Document document = person.toDocument(site, application);
        // the index has been cleared anyways, so we can use create here
        documentProducer.put(new DocumentEvent(document, Document.CREATE));
    }
    return java.util.Arrays.asList(documentProducer);
}
项目:cassandra-fhir-index    文件:SearchOptionsTest.java   
@Test
public void testConfiguration() {
    //@formatter:off
    String json = "{" +
               "  \"default_analyzer\" : \"org.apache.lucene.analysis.en.EnglishAnalyzer\"," +
               "  \"resources\" : {"+
            "     \"Patient\" : [\"family\", \"email\"],"+
            "     \"Observation\" : [\"code\", \"value-quantity\"]"+
            "  }"+
               "}";
    //@formatter:on

    ResourceOptions options;
    try {
        options = JsonSerializer.fromString(json, ResourceOptions.class);

        Analyzer defaultAnalyzer = options.defaultAnalyzer;
        assertTrue("Expected english analyzer", defaultAnalyzer instanceof EnglishAnalyzer);

        Map<String, Set<String>> resources = options.resources;
        assertEquals("Expected 2", 2, resources.size());

        resources.forEach((k, v) -> {
            System.out.println(k + "=" + v);
            assertEquals(2, v.size());
            v.forEach(p -> {
                System.out.println(p);
            });
        });

    } catch (IOException e) {
        fail(e.getMessage());
    }
}