Example usage for org.apache.lucene.document FeatureField tokenStream

List of usage examples for org.apache.lucene.document FeatureField tokenStream

Introduction

In this page you can find the example usage for org.apache.lucene.document FeatureField tokenStream.

Prototype

@Override
    public TokenStream tokenStream(Analyzer analyzer, TokenStream reuse) 

Source Link

Usage

From source file:org.elasticsearch.index.mapper.FeatureFieldMapperTests.java

License:Apache License

public void testDefaults() throws Exception {
    String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties").startObject("field").field("type", "feature").endObject().endObject()
            .endObject().endObject());// w ww. j ava2  s. c om

    DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));

    assertEquals(mapping, mapper.mappingSource().toString());

    ParsedDocument doc1 = mapper.parse(SourceToParse.source("test", "type", "1",
            BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", 10).endObject()),
            XContentType.JSON));

    IndexableField[] fields = doc1.rootDoc().getFields("_feature");
    assertEquals(1, fields.length);
    assertThat(fields[0], Matchers.instanceOf(FeatureField.class));
    FeatureField featureField1 = (FeatureField) fields[0];

    ParsedDocument doc2 = mapper.parse(SourceToParse.source("test", "type", "1",
            BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", 12).endObject()),
            XContentType.JSON));

    FeatureField featureField2 = (FeatureField) doc2.rootDoc().getFields("_feature")[0];

    int freq1 = getFrequency(featureField1.tokenStream(null, null));
    int freq2 = getFrequency(featureField2.tokenStream(null, null));
    assertTrue(freq1 < freq2);
}

From source file:org.elasticsearch.index.mapper.FeatureFieldMapperTests.java

License:Apache License

public void testNegativeScoreImpact() throws Exception {
    String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties").startObject("field").field("type", "feature")
            .field("positive_score_impact", false).endObject().endObject().endObject().endObject());

    DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));

    assertEquals(mapping, mapper.mappingSource().toString());

    ParsedDocument doc1 = mapper.parse(SourceToParse.source("test", "type", "1",
            BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", 10).endObject()),
            XContentType.JSON));/*from  www . j av  a2s . c o m*/

    IndexableField[] fields = doc1.rootDoc().getFields("_feature");
    assertEquals(1, fields.length);
    assertThat(fields[0], Matchers.instanceOf(FeatureField.class));
    FeatureField featureField1 = (FeatureField) fields[0];

    ParsedDocument doc2 = mapper.parse(SourceToParse.source("test", "type", "1",
            BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", 12).endObject()),
            XContentType.JSON));

    FeatureField featureField2 = (FeatureField) doc2.rootDoc().getFields("_feature")[0];

    int freq1 = getFrequency(featureField1.tokenStream(null, null));
    int freq2 = getFrequency(featureField2.tokenStream(null, null));
    assertTrue(freq1 > freq2);
}

From source file:org.elasticsearch.index.mapper.FeatureVectorFieldMapperTests.java

License:Apache License

public void testDefaults() throws Exception {
    String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties").startObject("field").field("type", "feature_vector").endObject()
            .endObject().endObject().endObject());

    DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));

    assertEquals(mapping, mapper.mappingSource().toString());

    ParsedDocument doc1 = mapper.parse(SourceToParse.source(
            "test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder().startObject()
                    .startObject("field").field("foo", 10).field("bar", 20).endObject().endObject()),
            XContentType.JSON));/*w w w.  j  a  v  a2s  .  c om*/

    IndexableField[] fields = doc1.rootDoc().getFields("field");
    assertEquals(2, fields.length);
    assertThat(fields[0], Matchers.instanceOf(FeatureField.class));
    FeatureField featureField1 = (FeatureField) fields[0];
    assertThat(featureField1.stringValue(), Matchers.equalTo("foo"));
    FeatureField featureField2 = (FeatureField) fields[1];
    assertThat(featureField2.stringValue(), Matchers.equalTo("bar"));

    int freq1 = FeatureFieldMapperTests.getFrequency(featureField1.tokenStream(null, null));
    int freq2 = FeatureFieldMapperTests.getFrequency(featureField2.tokenStream(null, null));
    assertTrue(freq1 < freq2);
}