diff --git oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/spi/IndexDescription.java oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/spi/IndexDescription.java new file mode 100644 index 0000000..5c97470 --- /dev/null +++ oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/spi/IndexDescription.java @@ -0,0 +1,75 @@ +package org.apache.jackrabbit.oak.plugins.index.lucene.spi; + +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; + +/** + * An immutable description of an index definition. The IndexDescription + * is an API agnostic description of a hierarchy, which can describe both + * NodeState hierarchies as well as JCR Node hierarchies. + *
+ * It is used by {@link IndexableFieldProvider}s to learn about the + * definition of an index for which they could provide fields. + */ +public interface IndexDescription { + + /** + * Allow exploratory access to an IndexDescription instance. + * + * @return The names of the keys of all values of this instance. + */ + @Nonnull + Iterable keys(); + + /** + * Allow querying for existence of a key. + * + * @return Whether or not an entry with the given key exists. + */ + boolean hasKey(@Nonnull String key); + + /** + * Type-safe accessor to retrieve a value given a key. If the key + * does not exist, the defaultValue is returned. + *
+ * To check for existence of a key use {@link #hasKey(String)}. + *
+ * If the key maps to a value that is not the same as the defaultValue, + * an implementation may try to coerce the value to the defaultValue's + * type. If this fails, an IllegalArgumentException is thrown. + * + * @param key The name of the key. + * @param defaultValue The value to return if the key does not exist. + * @param The type of the value to be returned is the same as the defaultValue's type. + * @return The value for the given key or the defaultValue. + * @throws IllegalArgumentException if the value mapped to by the key cannot be coerced to + * the type of the default value. + */ + @Nonnull + T getWithDefault(@Nonnull String key, @Nonnull T defaultValue); + + /** + * Allow exploratory access to the names of all children. + * + * @return The names of all existing children. + */ + @Nonnull + Iterable getChildNames(); + + /** + * Allow querying for the existence of a child. + * + * @param name The name of the child. + * @return Whether or not a child of the given name exists. + */ + boolean hasChild(@Nonnull String name); + + /** + * Allow retrieving a child by its name. + * + * @param name The name of the child. + * @return The child if it exists, otherwise null. + */ + @CheckForNull + IndexDescription getChild(@Nonnull String name); +} diff --git oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/spi/IndexableFieldProvider.java oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/spi/IndexableFieldProvider.java new file mode 100644 index 0000000..6777422 --- /dev/null +++ oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/spi/IndexableFieldProvider.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.apache.jackrabbit.oak.plugins.index.lucene.spi; + +import org.apache.jackrabbit.oak.spi.state.NodeState; +import org.apache.lucene.document.Field; +import org.apache.lucene.index.IndexableField; + +import javax.annotation.Nonnull; + +/** + * An IndexableFieldProvider may provide Lucene {@link Field}s to be indexed by + * the index described by the {@code IndexDescription} for a given {@code NodeState} + * at a given path. + */ +public interface IndexableFieldProvider { + /** + * LuceneIndexEditor calls this method for each NodeState that should be indexed. + * An IndexDescription allows quick access to properties of the index definition, + * which may be used by an implementation to determine what to do, e.g. whether + * it should act at all for the given index or not. + *
+ * The IndexableFieldProvider may choose to index any or all properties of the + * given NodeState. + * + * @param description A description of the index definition. + * @param nodeState The NodeState to be indexed. + * @param path The path of given NodeState. + * @return An Iterable with all IndexableFields provided by this instance. If no + * fields are provided this must be an empty Iterable. + */ + @Nonnull + Iterable provideFields( + @Nonnull IndexDescription description, @Nonnull NodeState nodeState, @Nonnull String path); +}