Java 类org.apache.lucene.index.IndexOptions 实例源码

项目:elasticsearch_my    文件:TokenCountFieldMapper.java   
@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));
}
项目:elasticsearch_my    文件:FieldMapper.java   
/**
 * 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;
}
项目:elasticsearch_my    文件:BooleanFieldMapper.java   
@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));
    }
}
项目:elasticsearch_my    文件:AllFieldMapper.java   
@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());
}
项目:elasticsearch_my    文件:TextFieldMapper.java   
@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);
}
项目:elasticsearch_my    文件:TextFieldMapper.java   
@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);
    }
}
项目:elasticsearch_my    文件:CustomUnifiedHighlighterTests.java   
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;
}
项目:elasticsearch_my    文件:IpFieldTypeTests.java   
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());
}
项目:elasticsearch_my    文件:DateFieldTypeTests.java   
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());
}
项目:elasticsearch_my    文件:DateFieldTypeTests.java   
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());
}
项目:elasticsearch_my    文件:RangeFieldTypeTests.java   
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));
}
项目:elasticsearch_my    文件:FakeStringFieldMapper.java   
@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)));
    }
}
项目:elasticsearch_my    文件:DynamicTemplatesTests.java   
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());


}
项目:Elasticsearch    文件:AllField.java   
@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");
    }
}
项目:Elasticsearch    文件:TypeFieldMapper.java   
@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;
}
项目:Elasticsearch    文件:SingleDocumentPercolatorIndex.java   
@Override
public void prepare(PercolateContext context, ParsedDocument parsedDocument) {
    MemoryIndex memoryIndex = cache.get();
    for (IndexableField field : parsedDocument.rootDoc().getFields()) {
        if (field.fieldType().indexOptions() == IndexOptions.NONE && field.name().equals(UidFieldMapper.NAME)) {
            continue;
        }
        try {
            Analyzer analyzer = context.mapperService().documentMapper(parsedDocument.type()).mappers().indexAnalyzer();
            // TODO: instead of passing null here, we can have a CTL<Map<String,TokenStream>> and pass previous,
            // like the indexer does
            try (TokenStream tokenStream = field.tokenStream(analyzer, null)) {
                if (tokenStream != null) {
                    memoryIndex.addField(field.name(), tokenStream, field.boost());
                }
             }
        } catch (Exception e) {
            throw new ElasticsearchException("Failed to create token stream for [" + field.name() + "]", e);
        }
    }
    context.initialize(new DocEngineSearcher(memoryIndex), parsedDocument);
}
项目:Elasticsearch    文件:GeoPointFieldMapper.java   
@Override
protected void parse(ParseContext context, GeoPoint point, String geoHash) throws IOException {
    if (ignoreMalformed.value() == false) {
        if (point.lat() > 90.0 || point.lat() < -90.0) {
            throw new IllegalArgumentException("illegal latitude value [" + point.lat() + "] for " + name());
        }
        if (point.lon() > 180.0 || point.lon() < -180) {
            throw new IllegalArgumentException("illegal longitude value [" + point.lon() + "] for " + name());
        }
    } else {
        // LUCENE WATCH: This will be folded back into Lucene's GeoPointField
        GeoUtils.normalizePoint(point);
    }
    if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
        context.doc().add(new GeoPointField(fieldType().names().indexName(), point.lon(), point.lat(), fieldType() ));
    }
    super.parse(context, point, geoHash);
}
项目:Elasticsearch    文件:FieldMapper.java   
protected void setupFieldType(BuilderContext context) {
    fieldType.setNames(buildNames(context));
    if (fieldType.indexAnalyzer() == null && fieldType.tokenized() == false && fieldType.indexOptions() != IndexOptions.NONE) {
        fieldType.setIndexAnalyzer(Lucene.KEYWORD_ANALYZER);
        fieldType.setSearchAnalyzer(Lucene.KEYWORD_ANALYZER);
    }
    if (fieldDataSettings != null) {
        Settings settings = Settings.builder().put(fieldType.fieldDataType().getSettings()).put(fieldDataSettings).build();
        fieldType.setFieldDataType(new FieldDataType(fieldType.fieldDataType().getType(), settings));
    }
    boolean defaultDocValues = false; // pre 2.0
    if (context.indexCreatedVersion().onOrAfter(Version.V_2_0_0_beta1)) {
        defaultDocValues = fieldType.tokenized() == false && fieldType.indexOptions() != IndexOptions.NONE;
    }
    // backcompat for "fielddata: format: docvalues" for now...
    boolean fieldDataDocValues = fieldType.fieldDataType() != null
        && FieldDataType.DOC_VALUES_FORMAT_VALUE.equals(fieldType.fieldDataType().getFormat(context.indexSettings()));
    if (fieldDataDocValues && docValuesSet && fieldType.hasDocValues() == false) {
        // this forces the doc_values setting to be written, so fielddata does not mask the original setting
        defaultDocValues = true;
    }
    defaultFieldType.setHasDocValues(defaultDocValues);
    if (docValuesSet == false) {
        fieldType.setHasDocValues(defaultDocValues || fieldDataDocValues);
    }
}
项目:Elasticsearch    文件:FieldNamesFieldMapper.java   
@Override
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException {
    if (fieldType().isEnabled() == false) {
        return;
    }
    for (ParseContext.Document document : context.docs()) {
        final List<String> paths = new ArrayList<>();
        for (IndexableField field : document.getFields()) {
            paths.add(field.name());
        }
        for (String path : paths) {
            for (String fieldName : extractFieldNames(path)) {
                if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
                    document.add(new Field(fieldType().names().indexName(), fieldName, fieldType()));
                }
            }
        }
    }
}
项目:Elasticsearch    文件:IdFieldMapper.java   
@Override
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException {
    XContentParser parser = context.parser();
    if (parser.currentName() != null && parser.currentName().equals(Defaults.NAME) && parser.currentToken().isValue()) {
        // we are in the parse Phase
        String id = parser.text();
        if (context.id() != null && !context.id().equals(id)) {
            throw new MapperParsingException("Provided id [" + context.id() + "] does not match the content one [" + id + "]");
        }
        context.id(id);
    } // else we are in the pre/post parse phase

    if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
        fields.add(new Field(fieldType().names().indexName(), context.id(), fieldType()));
    }
    if (fieldType().hasDocValues()) {
        fields.add(new BinaryDocValuesField(fieldType().names().indexName(), new BytesRef(context.id())));
    }
}
项目:elasticsearch_my    文件:PercolatorFieldMapper.java   
static KeywordFieldMapper createExtractQueryFieldBuilder(String name, BuilderContext context) {
    KeywordFieldMapper.Builder queryMetaDataFieldBuilder = new KeywordFieldMapper.Builder(name);
    queryMetaDataFieldBuilder.docValues(false);
    queryMetaDataFieldBuilder.store(false);
    queryMetaDataFieldBuilder.indexOptions(IndexOptions.DOCS);
    return queryMetaDataFieldBuilder.build(context);
}
项目:elasticsearch_my    文件:PercolatorFieldMapper.java   
static BinaryFieldMapper createQueryBuilderFieldBuilder(BuilderContext context) {
    BinaryFieldMapper.Builder builder = new BinaryFieldMapper.Builder(QUERY_BUILDER_FIELD_NAME);
    builder.docValues(true);
    builder.indexOptions(IndexOptions.NONE);
    builder.store(false);
    builder.fieldType().setDocValuesType(DocValuesType.BINARY);
    return builder.build(context);
}
项目:elasticsearch_my    文件:CollapseBuilder.java   
public CollapseContext build(SearchContext context) {
    if (context.scrollContext() != null) {
        throw new SearchContextException(context, "cannot use `collapse` in a scroll context");
    }
    if (context.searchAfter() != null) {
        throw new SearchContextException(context, "cannot use `collapse` in conjunction with `search_after`");
    }
    if (context.rescore() != null && context.rescore().isEmpty() == false) {
        throw new SearchContextException(context, "cannot use `collapse` in conjunction with `rescore`");
    }

    MappedFieldType fieldType = context.getQueryShardContext().fieldMapper(field);
    if (fieldType == null) {
        throw new SearchContextException(context, "no mapping found for `" + field + "` in order to collapse on");
    }
    if (fieldType instanceof KeywordFieldMapper.KeywordFieldType == false &&
        fieldType instanceof NumberFieldMapper.NumberFieldType == false) {
        throw new SearchContextException(context, "unknown type for collapse field `" + field +
            "`, only keywords and numbers are accepted");
    }

    if (fieldType.hasDocValues() == false) {
        throw new SearchContextException(context, "cannot collapse on field `" + field + "` without `doc_values`");
    }
    if (fieldType.indexOptions() == IndexOptions.NONE && innerHit != null) {
        throw new SearchContextException(context, "cannot expand `inner_hits` for collapse field `"
            + field + "`, " + "only indexed field can retrieve `inner_hits`");
    }
    return new CollapseContext(fieldType, innerHit);
}
项目:elasticsearch_my    文件:RoutingFieldMapper.java   
@Override
protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException {
    String routing = context.sourceToParse().routing();
    if (routing != null) {
        if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
            fields.add(new Field(fieldType().name(), routing, fieldType()));
        }
    }
}
项目:Elasticsearch    文件:MappedFieldType.java   
public MappedFieldType() {
    setTokenized(true);
    setStored(false);
    setStoreTermVectors(false);
    setOmitNorms(false);
    setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS);
    setBoost(1.0f);
    fieldDataType = new FieldDataType(typeName());
}
项目:Elasticsearch    文件:StringFieldMapper.java   
@Override
public StringFieldMapper build(BuilderContext context) {
    if (positionIncrementGap != POSITION_INCREMENT_GAP_USE_ANALYZER) {
        fieldType.setIndexAnalyzer(new NamedAnalyzer(fieldType.indexAnalyzer(), positionIncrementGap));
        fieldType.setSearchAnalyzer(new NamedAnalyzer(fieldType.searchAnalyzer(), positionIncrementGap));
        fieldType.setSearchQuoteAnalyzer(new NamedAnalyzer(fieldType.searchQuoteAnalyzer(), positionIncrementGap));
    }
    // if the field is not analyzed, then by default, we should omit norms and have docs only
    // index options, as probably what the user really wants
    // if they are set explicitly, we will use those values
    // we also change the values on the default field type so that toXContent emits what
    // differs from the defaults
    if (fieldType.indexOptions() != IndexOptions.NONE && !fieldType.tokenized()) {
        defaultFieldType.setOmitNorms(true);
        defaultFieldType.setIndexOptions(IndexOptions.DOCS);
        if (!omitNormsSet && fieldType.boost() == 1.0f) {
            fieldType.setOmitNorms(true);
        }
        if (!indexOptionsSet) {
            fieldType.setIndexOptions(IndexOptions.DOCS);
        }
    }
    setupFieldType(context);
    StringFieldMapper fieldMapper = new StringFieldMapper(
            name, fieldType, defaultFieldType, positionIncrementGap, ignoreAbove,
            context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo);
    return fieldMapper.includeInAll(includeInAll);
}
项目:elasticsearch_my    文件:FieldMapper.java   
protected boolean defaultDocValues(Version indexCreated) {
    if (indexCreated.onOrAfter(Version.V_5_0_0_alpha1)) {
        // add doc values by default to keyword (boolean, numerics, etc.) fields
        return fieldType.tokenized() == false;
    } else {
        return fieldType.tokenized() == false && fieldType.indexOptions() != IndexOptions.NONE;
    }
}
项目:elasticsearch_my    文件:FieldMapper.java   
protected void setupFieldType(BuilderContext context) {
    fieldType.setName(buildFullName(context));
    if (context.indexCreatedVersion().before(Version.V_5_0_0_alpha1)) {
        fieldType.setOmitNorms(fieldType.omitNorms() && fieldType.boost() == 1.0f);
    }
    if (fieldType.indexAnalyzer() == null && fieldType.tokenized() == false && fieldType.indexOptions() != IndexOptions.NONE) {
        fieldType.setIndexAnalyzer(Lucene.KEYWORD_ANALYZER);
        fieldType.setSearchAnalyzer(Lucene.KEYWORD_ANALYZER);
    }
    boolean defaultDocValues = defaultDocValues(context.indexCreatedVersion());
    defaultFieldType.setHasDocValues(defaultDocValues);
    if (docValuesSet == false) {
        fieldType.setHasDocValues(defaultDocValues);
    }
}
项目:elasticsearch_my    文件:FieldMapper.java   
protected static String indexOptionToString(IndexOptions indexOption) {
    switch (indexOption) {
        case DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS:
            return TypeParsers.INDEX_OPTIONS_OFFSETS;
        case DOCS_AND_FREQS:
            return TypeParsers.INDEX_OPTIONS_FREQS;
        case DOCS_AND_FREQS_AND_POSITIONS:
            return TypeParsers.INDEX_OPTIONS_POSITIONS;
        case DOCS:
            return TypeParsers.INDEX_OPTIONS_DOCS;
        default:
            throw new IllegalArgumentException("Unknown IndexOptions [" + indexOption + "]");
    }
}
项目:elasticsearch_my    文件:TypeFieldMapper.java   
@Override
public Query termQuery(Object value, @Nullable QueryShardContext context) {
    if (indexOptions() == IndexOptions.NONE) {
        throw new AssertionError();
    }
    return new TypesQuery(indexedValueForSearch(value));
}
项目:elasticsearch_my    文件:TypeFieldMapper.java   
@Override
protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException {
    if (fieldType().indexOptions() == IndexOptions.NONE && !fieldType().stored()) {
        return;
    }
    fields.add(new Field(fieldType().name(), context.sourceToParse().type(), fieldType()));
    if (fieldType().hasDocValues()) {
        fields.add(new SortedSetDocValuesField(fieldType().name(), new BytesRef(context.sourceToParse().type())));
    }
}
项目:elasticsearch_my    文件:GeoPointFieldMapper.java   
protected void parse(ParseContext originalContext, GeoPoint point) throws IOException {
    // Geopoint fields, by default, will not be included in _all
    final ParseContext context = originalContext.setIncludeInAllDefault(false);

    if (ignoreMalformed.value() == false) {
        if (point.lat() > 90.0 || point.lat() < -90.0) {
            throw new IllegalArgumentException("illegal latitude value [" + point.lat() + "] for " + name());
        }
        if (point.lon() > 180.0 || point.lon() < -180) {
            throw new IllegalArgumentException("illegal longitude value [" + point.lon() + "] for " + name());
        }
    } else {
        GeoUtils.normalizePoint(point);
    }
    if (fieldType().indexOptions() != IndexOptions.NONE) {
        context.doc().add(new LatLonPoint(fieldType().name(), point.lat(), point.lon()));
    }
    if (fieldType().stored()) {
        context.doc().add(new StoredField(fieldType().name(), point.toString()));
    }
    if (fieldType.hasDocValues()) {
        context.doc().add(new LatLonDocValuesField(fieldType().name(), point.lat(), point.lon()));
    }
    // if the mapping contains multifields then use the geohash string
    if (multiFields.iterator().hasNext()) {
        multiFields.parse(this, context.createExternalValueContext(point.geohash()));
    }
}
项目:elasticsearch_my    文件:MappedFieldType.java   
public MappedFieldType() {
    setTokenized(true);
    setStored(false);
    setStoreTermVectors(false);
    setOmitNorms(false);
    setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS);
    setBoost(1.0f);
}
项目:Elasticsearch    文件:NumberFieldMapper.java   
public NumberFieldType(NumericType numericType) {
    setTokenized(false);
    setOmitNorms(true);
    setIndexOptions(IndexOptions.DOCS);
    setStoreTermVectors(false);
    setNumericType(numericType);
}
项目:elasticsearch_my    文件:TypeParsers.java   
private static IndexOptions nodeIndexOptionValue(final Object propNode) {
    final String value = propNode.toString();
    if (INDEX_OPTIONS_OFFSETS.equalsIgnoreCase(value)) {
        return IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS;
    } else if (INDEX_OPTIONS_POSITIONS.equalsIgnoreCase(value)) {
        return IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
    } else if (INDEX_OPTIONS_FREQS.equalsIgnoreCase(value)) {
        return IndexOptions.DOCS_AND_FREQS;
    } else if (INDEX_OPTIONS_DOCS.equalsIgnoreCase(value)) {
        return IndexOptions.DOCS;
    } else {
        throw new ElasticsearchParseException("failed to parse index option [{}]", value);
    }
}
项目:elasticsearch_my    文件:AllField.java   
@Override
public TokenStream tokenStream(Analyzer analyzer, TokenStream previous) {
    TokenStream ts = analyzer.tokenStream(name(), stringValue());
    if (boost != 1.0f && 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 new AllTokenStream(ts, boost);
    }
    return ts;
}
项目:elasticsearch_my    文件:FiltersAggregatorTests.java   
@Before
public void setUpTest() throws Exception {
    super.setUp();
    fieldType = new KeywordFieldMapper.KeywordFieldType();
    fieldType.setHasDocValues(true);
    fieldType.setIndexOptions(IndexOptions.DOCS);
    fieldType.setName("field");
}
项目:elasticsearch_my    文件:CollapseBuilderTests.java   
public void testBuild() throws IOException {
    Directory dir = new RAMDirectory();
    try (IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())))) {
        writer.commit();
    }
    SearchContext searchContext = mockSearchContext();
    try (IndexReader reader = DirectoryReader.open(dir)) {
        when(searchContext.getQueryShardContext().getIndexReader()).thenReturn(reader);
        MappedFieldType numberFieldType =
            new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.LONG);
        MappedFieldType keywordFieldType =
            new KeywordFieldMapper.KeywordFieldType();
        for (MappedFieldType fieldType : new MappedFieldType[] {numberFieldType, keywordFieldType}) {
            fieldType.setName("field");
            fieldType.setHasDocValues(true);
            when(searchContext.getQueryShardContext().fieldMapper("field")).thenReturn(fieldType);
            CollapseBuilder builder = new CollapseBuilder("field");
            CollapseContext collapseContext = builder.build(searchContext);
            assertEquals(collapseContext.getFieldType(), fieldType);

            fieldType.setIndexOptions(IndexOptions.NONE);
            collapseContext = builder.build(searchContext);
            assertEquals(collapseContext.getFieldType(), fieldType);

            fieldType.setHasDocValues(false);
            SearchContextException exc = expectThrows(SearchContextException.class, () -> builder.build(searchContext));
            assertEquals(exc.getMessage(), "cannot collapse on field `field` without `doc_values`");

            fieldType.setHasDocValues(true);
            builder.setInnerHits(new InnerHitBuilder());
            exc = expectThrows(SearchContextException.class, () -> builder.build(searchContext));
            assertEquals(exc.getMessage(),
                "cannot expand `inner_hits` for collapse field `field`, " +
                    "only indexed field can retrieve `inner_hits`");
        }
    }
}
项目:Elasticsearch    文件:TypeFieldMapper.java   
@Override
public Query termQuery(Object value, @Nullable QueryParseContext context) {
    if (indexOptions() == IndexOptions.NONE) {
        return new ConstantScoreQuery(new PrefixQuery(new Term(UidFieldMapper.NAME, Uid.typePrefixAsBytes(BytesRefs.toBytesRef(value)))));
    }
    return new ConstantScoreQuery(new TermQuery(createTerm(value)));
}
项目:Elasticsearch    文件:IntegerFieldMapper.java   
protected void addIntegerFields(ParseContext context, List<Field> fields, int value, float boost) {
    if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
        CustomIntegerNumericField field = new CustomIntegerNumericField(value, fieldType());
        field.setBoost(boost);
        fields.add(field);
    }
    if (fieldType().hasDocValues()) {
        addDocValue(context, fields, value);
    }
}