1 package org.apache.lucene;
3 import org.apache.lucene.document.Document;
4 import org.apache.lucene.document.Field;
7 * Licensed to the Apache Software Foundation (ASF) under one or more
8 * contributor license agreements. See the NOTICE file distributed with
9 * this work for additional information regarding copyright ownership.
10 * The ASF licenses this file to You under the Apache License, Version 2.0
11 * (the "License"); you may not use this file except in compliance with
12 * the License. You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
24 * An interface which standardizes the process of building an indexable
27 * The idea is that implementations implement {@link #build(Document doc)},
28 * which adds to the given Document whatever {@link Field}s it wants to add. A
29 * DocumentBuilder is also allowed to inspect or change existing Fields in the
30 * Document, if it wishes to.
32 * Implementations should normally have a constructor with parameters which
33 * determine what {@link #build(Document)} will add to doc.<br>
34 * To allow reuse of the DocumentBuilder object, implementations are also
35 * encouraged to have a setter method, which remembers its parameters just like
36 * the constructor. This setter method cannot be described in this interface,
37 * because it will take different parameters in each implementation.
39 * The interface defines a builder pattern, which allows applications to invoke
40 * several document builders in the following way:
43 * builder1.build(builder2.build(builder3.build(new Document())));
46 * @lucene.experimental
48 public interface DocumentBuilder {
50 /** An exception thrown from {@link DocumentBuilder}'s build(). */
51 public static class DocumentBuilderException extends Exception {
53 public DocumentBuilderException() {
57 public DocumentBuilderException(String message) {
61 public DocumentBuilderException(String message, Throwable cause) {
62 super(message, cause);
65 public DocumentBuilderException(Throwable cause) {
72 * Adds to the given document whatever {@link Field}s the implementation needs
73 * to add. Return the docunment instance to allow for chaining calls.
75 public Document build(Document doc) throws DocumentBuilderException;