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


Java IndexOptions类代码示例

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


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

示例1: parseCreateField

import org.apache.lucene.index.IndexOptions; //导入依赖的package包/类
@Override
protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException {
    final String value;
    if (context.externalValueSet()) {
        value = context.externalValue().toString();
    } else {
        value = context.parser().textOrNull();
    }

    final int tokenCount;
    if (value == null) {
        tokenCount = (Integer) fieldType().nullValue();
    } else {
        tokenCount = countPositions(analyzer, name(), value);
    }

    boolean indexed = fieldType().indexOptions() != IndexOptions.NONE;
    boolean docValued = fieldType().hasDocValues();
    boolean stored = fieldType().stored();
    fields.addAll(NumberFieldMapper.NumberType.INTEGER.createFields(fieldType().name(), tokenCount, indexed, docValued, stored));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:TokenCountFieldMapper.java

示例2: parse

import org.apache.lucene.index.IndexOptions; //导入依赖的package包/类
/**
 * Parse using the provided {@link ParseContext} and return a mapping
 * update if dynamic mappings modified the mappings, or {@code null} if
 * mappings were not modified.
 */
public Mapper parse(ParseContext context) throws IOException {
    final List<IndexableField> fields = new ArrayList<>(2);
    try {
        parseCreateField(context, fields);
        for (IndexableField field : fields) {
            if (!customBoost()
                    // don't set boosts eg. on dv fields
                    && field.fieldType().indexOptions() != IndexOptions.NONE
                    && indexCreatedVersion.before(Version.V_5_0_0_alpha1)) {
                ((Field)(field)).setBoost(fieldType().boost());
            }
            context.doc().add(field);
        }
    } catch (Exception e) {
        throw new MapperParsingException("failed to parse [" + fieldType().name() + "]", e);
    }
    multiFields.parse(this, context);
    return null;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:FieldMapper.java

示例3: parseCreateField

import org.apache.lucene.index.IndexOptions; //导入依赖的package包/类
@Override
protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException {
    if (fieldType().indexOptions() == IndexOptions.NONE && !fieldType().stored() && !fieldType().hasDocValues()) {
        return;
    }

    Boolean value = context.parseExternalValue(Boolean.class);
    if (value == null) {
        XContentParser.Token token = context.parser().currentToken();
        if (token == XContentParser.Token.VALUE_NULL) {
            if (fieldType().nullValue() != null) {
                value = fieldType().nullValue();
            }
        } else {
            if (indexCreatedVersion.onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) {
                value = context.parser().booleanValue();
            } else {
                value = context.parser().booleanValueLenient();
                if (context.parser().isBooleanValueLenient() != context.parser().isBooleanValue()) {
                    String rawValue = context.parser().text();
                    deprecationLogger.deprecated("Expected a boolean for property [{}] but got [{}]", fieldType().name(), rawValue);
                }
            }
        }
    }

    if (value == null) {
        return;
    }
    if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
        fields.add(new Field(fieldType().name(), value ? "T" : "F", fieldType()));
    }
    if (fieldType().hasDocValues()) {
        fields.add(new SortedNumericDocValuesField(fieldType().name(), value ? 1 : 0));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:37,代码来源:BooleanFieldMapper.java

示例4: build

import org.apache.lucene.index.IndexOptions; //导入依赖的package包/类
@Override
public AllFieldMapper build(BuilderContext context) {
    // In case the mapping overrides these
    // TODO: this should be an exception! it doesnt make sense to not index this field
    if (fieldType.indexOptions() == IndexOptions.NONE) {
        fieldType.setIndexOptions(Defaults.FIELD_TYPE.indexOptions());
    } else {
        fieldType.setIndexAnalyzer(new NamedAnalyzer(fieldType.indexAnalyzer(),
            Defaults.POSITION_INCREMENT_GAP));
        fieldType.setSearchAnalyzer(new NamedAnalyzer(fieldType.searchAnalyzer(),
            Defaults.POSITION_INCREMENT_GAP));
        fieldType.setSearchQuoteAnalyzer(new NamedAnalyzer(fieldType.searchQuoteAnalyzer(),
            Defaults.POSITION_INCREMENT_GAP));
    }
    fieldType.setTokenized(true);

    return new AllFieldMapper(fieldType, enabled, context.indexSettings());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:AllFieldMapper.java

示例5: build

import org.apache.lucene.index.IndexOptions; //导入依赖的package包/类
@Override
public TextFieldMapper build(BuilderContext context) {
    if (positionIncrementGap != POSITION_INCREMENT_GAP_USE_ANALYZER) {
        if (fieldType.indexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0) {
            throw new IllegalArgumentException("Cannot set position_increment_gap on field ["
                + name + "] without positions enabled");
        }
        fieldType.setIndexAnalyzer(new NamedAnalyzer(fieldType.indexAnalyzer(), positionIncrementGap));
        fieldType.setSearchAnalyzer(new NamedAnalyzer(fieldType.searchAnalyzer(), positionIncrementGap));
        fieldType.setSearchQuoteAnalyzer(new NamedAnalyzer(fieldType.searchQuoteAnalyzer(), positionIncrementGap));
    }
    setupFieldType(context);
    return new TextFieldMapper(
            name, fieldType, defaultFieldType, positionIncrementGap, includeInAll,
            context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:TextFieldMapper.java

示例6: parseCreateField

import org.apache.lucene.index.IndexOptions; //导入依赖的package包/类
@Override
protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException {
    final String value;
    if (context.externalValueSet()) {
        value = context.externalValue().toString();
    } else {
        value = context.parser().textOrNull();
    }

    if (value == null) {
        return;
    }

    if (context.includeInAll(includeInAll, this)) {
        context.allEntries().addText(fieldType().name(), value, fieldType().boost());
    }

    if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
        Field field = new Field(fieldType().name(), value, fieldType());
        fields.add(field);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:TextFieldMapper.java

示例7: indexOneDoc

import org.apache.lucene.index.IndexOptions; //导入依赖的package包/类
private IndexReader indexOneDoc(Directory dir, String field, String value, Analyzer analyzer) throws IOException {
    IndexWriterConfig iwc = newIndexWriterConfig(analyzer);
    iwc.setMergePolicy(newLogMergePolicy());
    RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwc);

    FieldType ft = new FieldType(TextField.TYPE_STORED);
    ft.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
    Field textField = new Field(field, "", ft);
    Document doc = new Document();
    doc.add(textField);

    textField.setStringValue(value);
    iw.addDocument(doc);
    IndexReader ir = iw.getReader();
    iw.close();
    return ir;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:CustomUnifiedHighlighterTests.java

示例8: testTermQuery

import org.apache.lucene.index.IndexOptions; //导入依赖的package包/类
public void testTermQuery() {
    MappedFieldType ft = createDefaultFieldType();
    ft.setName("field");

    String ip = "2001:db8::2:1";
    assertEquals(InetAddressPoint.newExactQuery("field", InetAddresses.forString(ip)), ft.termQuery(ip, null));

    ip = "192.168.1.7";
    assertEquals(InetAddressPoint.newExactQuery("field", InetAddresses.forString(ip)), ft.termQuery(ip, null));

    ip = "2001:db8::2:1";
    String prefix = ip + "/64";
    assertEquals(InetAddressPoint.newPrefixQuery("field", InetAddresses.forString(ip), 64), ft.termQuery(prefix, null));

    ip = "192.168.1.7";
    prefix = ip + "/16";
    assertEquals(InetAddressPoint.newPrefixQuery("field", InetAddresses.forString(ip), 16), ft.termQuery(prefix, null));

    ft.setIndexOptions(IndexOptions.NONE);
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
            () -> ft.termQuery("::1", null));
    assertEquals("Cannot search on field [field] since it is not indexed.", e.getMessage());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:IpFieldTypeTests.java

示例9: testTermQuery

import org.apache.lucene.index.IndexOptions; //导入依赖的package包/类
public void testTermQuery() {
    Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
            .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1).build();
    QueryShardContext context = new QueryShardContext(0,
            new IndexSettings(IndexMetaData.builder("foo").settings(indexSettings).build(),
                    indexSettings),
            null, null, null, null, null, xContentRegistry(), null, null, () -> nowInMillis);
    MappedFieldType ft = createDefaultFieldType();
    ft.setName("field");
    String date = "2015-10-12T14:10:55";
    long instant = DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.parser().parseDateTime(date).getMillis();
    ft.setIndexOptions(IndexOptions.DOCS);
    Query expected = new IndexOrDocValuesQuery(
            LongPoint.newRangeQuery("field", instant, instant + 999),
            SortedNumericDocValuesField.newRangeQuery("field", instant, instant + 999));
    assertEquals(expected, ft.termQuery(date, context));

    ft.setIndexOptions(IndexOptions.NONE);
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
            () -> ft.termQuery(date, context));
    assertEquals("Cannot search on field [field] since it is not indexed.", e.getMessage());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:DateFieldTypeTests.java

示例10: testRangeQuery

import org.apache.lucene.index.IndexOptions; //导入依赖的package包/类
public void testRangeQuery() throws IOException {
    Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
            .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1).build();
    QueryShardContext context = new QueryShardContext(0,
            new IndexSettings(IndexMetaData.builder("foo").settings(indexSettings).build(), indexSettings),
            null, null, null, null, null, xContentRegistry(), null, null, () -> nowInMillis);
    MappedFieldType ft = createDefaultFieldType();
    ft.setName("field");
    String date1 = "2015-10-12T14:10:55";
    String date2 = "2016-04-28T11:33:52";
    long instant1 = DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.parser().parseDateTime(date1).getMillis();
    long instant2 = DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.parser().parseDateTime(date2).getMillis() + 999;
    ft.setIndexOptions(IndexOptions.DOCS);
    Query expected = new IndexOrDocValuesQuery(
            LongPoint.newRangeQuery("field", instant1, instant2),
            SortedNumericDocValuesField.newRangeQuery("field", instant1, instant2));
    assertEquals(expected,
            ft.rangeQuery(date1, date2, true, true, context).rewrite(new MultiReader()));

    ft.setIndexOptions(IndexOptions.NONE);
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
            () -> ft.rangeQuery(date1, date2, true, true, context));
    assertEquals("Cannot search on field [field] since it is not indexed.", e.getMessage());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:DateFieldTypeTests.java

示例11: testRangeQuery

import org.apache.lucene.index.IndexOptions; //导入依赖的package包/类
public void testRangeQuery() throws Exception {
    Settings indexSettings = Settings.builder()
        .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
    IndexSettings idxSettings = IndexSettingsModule.newIndexSettings(randomAsciiOfLengthBetween(1, 10), indexSettings);
    QueryShardContext context = new QueryShardContext(0, idxSettings, null, null, null, null, null, xContentRegistry(),
            null, null, () -> nowInMillis);
    RangeFieldMapper.RangeFieldType ft = new RangeFieldMapper.RangeFieldType(type);
    ft.setName(FIELDNAME);
    ft.setIndexOptions(IndexOptions.DOCS);

    ShapeRelation relation = RandomPicks.randomFrom(random(), ShapeRelation.values());
    boolean includeLower = random().nextBoolean();
    boolean includeUpper = random().nextBoolean();
    Object from = nextFrom();
    Object to = nextTo(from);

    assertEquals(getExpectedRangeQuery(relation, from, to, includeLower, includeUpper),
        ft.rangeQuery(from, to, includeLower, includeUpper, relation, context));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:RangeFieldTypeTests.java

示例12: parseCreateField

import org.apache.lucene.index.IndexOptions; //导入依赖的package包/类
@Override
protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException {
    String value;
    if (context.externalValueSet()) {
        value = context.externalValue().toString();
    } else {
        value = context.parser().textOrNull();
    }
    
    if (value == null) {
        return;
    }

    if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
        Field field = new Field(fieldType().name(), value, fieldType());
        fields.add(field);
    }
    if (fieldType().hasDocValues()) {
        fields.add(new SortedSetDocValuesField(fieldType().name(), new BytesRef(value)));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:FakeStringFieldMapper.java

示例13: testMatchTypeOnly

import org.apache.lucene.index.IndexOptions; //导入依赖的package包/类
public void testMatchTypeOnly() throws Exception {
    XContentBuilder builder = JsonXContent.contentBuilder();
    builder.startObject().startObject("person").startArray("dynamic_templates").startObject().startObject("test")
            .field("match_mapping_type", "string")
            .startObject("mapping").field("index", false).endObject()
            .endObject().endObject().endArray().endObject().endObject();
    IndexService index = createIndex("test");
    client().admin().indices().preparePutMapping("test").setType("person").setSource(builder).get();
    DocumentMapper docMapper = index.mapperService().documentMapper("person");
    builder = JsonXContent.contentBuilder();
    builder.startObject().field("s", "hello").field("l", 1).endObject();
    ParsedDocument parsedDoc = docMapper.parse("test", "person", "1", builder.bytes());
    client().admin().indices().preparePutMapping("test").setType("person")
        .setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get();

    docMapper = index.mapperService().documentMapper("person");
    DocumentFieldMappers mappers = docMapper.mappers();

    assertThat(mappers.smartNameFieldMapper("s"), Matchers.notNullValue());
    assertEquals(IndexOptions.NONE, mappers.smartNameFieldMapper("s").fieldType().indexOptions());

    assertThat(mappers.smartNameFieldMapper("l"), Matchers.notNullValue());
    assertNotSame(IndexOptions.NONE, mappers.smartNameFieldMapper("l").fieldType().indexOptions());


}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:DynamicTemplatesTests.java

示例14: tokenStream

import org.apache.lucene.index.IndexOptions; //导入依赖的package包/类
@Override
public TokenStream tokenStream(Analyzer analyzer, TokenStream previous) {
    try {
        allEntries.reset(); // reset the all entries, just in case it was read already
        if (allEntries.customBoost() && fieldType().indexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0) {
            // TODO: we should be able to reuse "previous" if its instanceof AllTokenStream?
            // but we need to be careful this optimization is safe (and tested)...
            
            // AllTokenStream maps boost to 4-byte payloads, so we only need to use it any field had non-default (!= 1.0f) boost and if
            // positions are indexed:
            return AllTokenStream.allTokenStream(name, allEntries, analyzer);
        } else {
            return analyzer.tokenStream(name, allEntries);
        }
    } catch (IOException e) {
        throw new ElasticsearchException("Failed to create token stream");
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:19,代码来源:AllField.java

示例15: toXContent

import org.apache.lucene.index.IndexOptions; //导入依赖的package包/类
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    if (indexCreatedBefore2x == false) {
        return builder;
    }
    boolean includeDefaults = params.paramAsBoolean("include_defaults", false);

    // if all are defaults, no sense to write it at all
    boolean indexed = fieldType().indexOptions() != IndexOptions.NONE;
    boolean defaultIndexed = Defaults.FIELD_TYPE.indexOptions() != IndexOptions.NONE;
    if (!includeDefaults && fieldType().stored() == Defaults.FIELD_TYPE.stored() && indexed == defaultIndexed) {
        return builder;
    }
    builder.startObject(CONTENT_TYPE);
    if (includeDefaults || fieldType().stored() != Defaults.FIELD_TYPE.stored()) {
        builder.field("store", fieldType().stored());
    }
    if (includeDefaults || indexed != defaultIndexed) {
        builder.field("index", indexTokenizeOptionToString(indexed, fieldType().tokenized()));
    }
    builder.endObject();
    return builder;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:24,代码来源:TypeFieldMapper.java


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