View Javadoc
1   /*
2    * Copyright 2012-2025 CodeLibs Project and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.codelibs.fess.ingest;
17  
18  import java.util.Map;
19  
20  import org.codelibs.fess.crawler.entity.AccessResult;
21  import org.codelibs.fess.crawler.entity.ResponseData;
22  import org.codelibs.fess.crawler.entity.ResultData;
23  import org.codelibs.fess.entity.DataStoreParams;
24  import org.codelibs.fess.util.ComponentUtil;
25  
26  /**
27   * Abstract base class for document ingesters that process and transform documents
28   * before they are indexed. Ingesters can be used to modify document content,
29   * extract additional metadata, or perform other transformations during the
30   * indexing process.
31   *
32   * Ingesters are processed in priority order, with lower numbers having higher priority.
33   */
34  public abstract class Ingester {
35  
36      /** Priority of this ingester (lower numbers = higher priority) */
37      protected int priority = 99;
38  
39      /**
40       * Default constructor.
41       */
42      public Ingester() {
43          // Default constructor
44      }
45  
46      /**
47       * Gets the priority of this ingester.
48       * Lower numbers indicate higher priority.
49       *
50       * @return the priority value
51       */
52      public int getPriority() {
53          return priority;
54      }
55  
56      /**
57       * Sets the priority of this ingester.
58       * Lower numbers indicate higher priority.
59       *
60       * @param priority the priority value to set
61       */
62      public void setPriority(final int priority) {
63          this.priority = priority;
64      }
65  
66      /**
67       * Registers this ingester with the ingest factory.
68       * This makes the ingester available for processing documents.
69       */
70      public void register() {
71          getIngestFactory().add(this);
72      }
73  
74      /**
75       * Gets the ingest factory instance for managing ingesters.
76       *
77       * @return the ingest factory instance
78       */
79      protected IngestFactory getIngestFactory() {
80          return ComponentUtil.getIngestFactory();
81      }
82  
83      /**
84       * Processes a result data object for web/file crawling.
85       * Default implementation returns the target unchanged.
86       *
87       * @param target the result data to process
88       * @param responseData the response data from crawling
89       * @return the processed result data
90       */
91      public ResultData process(final ResultData target, final ResponseData responseData) {
92          return target;
93      }
94  
95      /**
96       * Processes a document map for web/file crawling with access result.
97       * Default implementation delegates to the basic process method.
98       *
99       * @param target the document data to process
100      * @param accessResult the access result from crawling
101      * @return the processed document data
102      */
103     public Map<String, Object> process(final Map<String, Object> target, final AccessResult<String> accessResult) {
104         return process(target);
105     }
106 
107     /**
108      * Processes a document map for datastore operations.
109      * Default implementation delegates to the basic process method.
110      *
111      * @param target the document data to process
112      * @param params the data store parameters
113      * @return the processed document data
114      */
115     public Map<String, Object> process(final Map<String, Object> target, final DataStoreParams params) {
116         return process(target);
117     }
118 
119     /**
120      * Basic processing method that other process methods delegate to.
121      * Default implementation returns the target unchanged.
122      * Subclasses should override this method to implement specific processing logic.
123      *
124      * @param target the document data to process
125      * @return the processed document data
126      */
127     protected Map<String, Object> process(final Map<String, Object> target) {
128         return target;
129     }
130 
131 }