diff --git a/src/main/java/org/elasticsearch/common/lucene/HashedBytesRef.java b/src/main/java/org/elasticsearch/common/lucene/HashedBytesRef.java new file mode 100644 index 00000000000..299de543e9a --- /dev/null +++ b/src/main/java/org/elasticsearch/common/lucene/HashedBytesRef.java @@ -0,0 +1,76 @@ +/* + * Licensed to ElasticSearch and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. ElasticSearch licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.common.lucene; + +import org.apache.lucene.util.BytesRef; + +/** + * A wrapped to {@link BytesRef} that also caches the hashCode for it. + */ +public class HashedBytesRef { + + public BytesRef bytes; + public int hash; + + public HashedBytesRef() { + } + + public HashedBytesRef(String bytes) { + this(new BytesRef(bytes)); + } + + public HashedBytesRef(BytesRef bytes) { + this(bytes, bytes.hashCode()); + } + + public HashedBytesRef(BytesRef bytes, int hash) { + this.bytes = bytes; + this.hash = hash; + } + + public HashedBytesRef resetHashCode() { + this.hash = bytes.hashCode(); + return this; + } + + public HashedBytesRef reset(BytesRef bytes, int hash) { + this.bytes = bytes; + this.hash = hash; + return this; + } + + @Override + public int hashCode() { + return hash; + } + + @Override + public boolean equals(Object other) { + if (other instanceof HashedBytesRef) { + return bytes.equals(((HashedBytesRef) other).bytes); + } + return false; + } + + @Override + public String toString() { + return bytes.toString(); + } +} diff --git a/src/main/java/org/elasticsearch/index/fielddata/AbstractIndexFieldData.java b/src/main/java/org/elasticsearch/index/fielddata/AbstractIndexFieldData.java new file mode 100644 index 00000000000..894d98f50fa --- /dev/null +++ b/src/main/java/org/elasticsearch/index/fielddata/AbstractIndexFieldData.java @@ -0,0 +1,32 @@ +package org.elasticsearch.index.fielddata; + +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.AbstractIndexComponent; +import org.elasticsearch.index.Index; +import org.elasticsearch.index.settings.IndexSettings; + +/** + */ +public abstract class AbstractIndexFieldData extends AbstractIndexComponent implements IndexFieldData { + + private final String fieldName; + protected final FieldDataType fieldDataType; + protected final IndexFieldDataCache cache; + + public AbstractIndexFieldData(Index index, @IndexSettings Settings indexSettings, String fieldName, FieldDataType fieldDataType, IndexFieldDataCache cache) { + super(index, indexSettings); + this.fieldName = fieldName; + this.fieldDataType = fieldDataType; + this.cache = cache; + } + + @Override + public String getFieldName() { + return this.fieldName; + } + + @Override + public void clear() { + cache.clear(index, fieldName); + } +} diff --git a/src/main/java/org/elasticsearch/index/fielddata/AtomicFieldData.java b/src/main/java/org/elasticsearch/index/fielddata/AtomicFieldData.java new file mode 100644 index 00000000000..1648a320397 --- /dev/null +++ b/src/main/java/org/elasticsearch/index/fielddata/AtomicFieldData.java @@ -0,0 +1,66 @@ +/* + * Licensed to ElasticSearch and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. ElasticSearch licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.fielddata; + +/** + * The thread safe {@link org.apache.lucene.index.AtomicReader} level cache of the data. + */ +public interface AtomicFieldData