KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > search > JahiaIndexableDocumentImpl


1 package org.jahia.services.search;
2
3 import java.io.*;
4 import java.util.*;
5
6 //import org.apache.jetspeed.services.search.ParsedObject;
7
//import org.apache.jetspeed.services.search.BaseParsedObject;
8

9 /**
10  * <p>Title: Base implementation for Jahia indexable content</p>
11  * <p>Description: </p>
12  * <p>Copyright: Copyright (c) 2002</p>
13  * <p>Company: </p>
14  *
15  * @author Khue Nguyen
16  * @version 1.0
17  */

18 public class JahiaIndexableDocumentImpl implements JahiaIndexableDocument ,
19     Serializable {
20
21     protected int siteId;
22
23     protected String JavaDoc key;
24
25     protected String JavaDoc keyFieldName = JahiaSearchConstant.OBJECT_KEY;
26
27     protected Hashtable fields;
28
29     protected Set unStoreFields = new HashSet ();
30
31     protected boolean toBeAdded = true;
32
33     protected boolean isCacheableWithRAMIndexer = true;
34
35
36     /**
37      * @param siteId
38      * @param key
39      * @param fields
40      */

41     public JahiaIndexableDocumentImpl (int siteId, String JavaDoc key,
42                                        Hashtable fields) {
43         this.siteId = siteId;
44         this.key = key;
45         this.fields = fields;
46         if (this.fields == null) {
47             this.fields = new Hashtable ();
48         }
49     }
50
51     /**
52      * @param siteId
53      * @param keyFieldName
54      * @param key
55      * @param fields
56      */

57     public JahiaIndexableDocumentImpl (int siteId, String JavaDoc keyFieldName,
58                                        String JavaDoc key, Hashtable fields) {
59         this.siteId = siteId;
60         if ( keyFieldName != null ){
61             this.keyFieldName = keyFieldName;
62         }
63         this.key = key;
64         this.fields = fields;
65         if (this.fields == null) {
66             this.fields = new Hashtable ();
67         }
68     }
69
70     /**
71      * Return true if this object is to be added to search engine
72      *
73      * @return
74      */

75     public boolean toBeAdded () {
76         return this.toBeAdded;
77     }
78
79     /**
80      * Return true if this object is to be removed from search engine
81      *
82      * @return
83      */

84     public boolean toBeRemoved () {
85         return !this.toBeAdded;
86     }
87
88     /**
89      * Set the state to be added / to be removed
90      *
91      * @return
92      */

93     public void setBeAdded (boolean val) {
94         this.toBeAdded = val;
95     }
96
97     /**
98      * The search engine will call this method before indexing this object,
99      * allowing custom processing.
100      * It will continue indexing only if the result of this method return true
101      *
102      * @return
103      */

104     public boolean beforeAddingToSearchEngine () {
105         return true;
106     }
107
108     /**
109      * The search engine will call this method before removing from search engine,
110      * allowing custom processing.
111      * It will continue indexing only if the result of this method return true
112      *
113      * @return
114      */

115     public boolean beforeRemovingFromSearchEngine () {
116         return true;
117     }
118
119     /**
120      * return the site id
121      *
122      * @return
123      */

124     public int getSiteId () {
125         return this.siteId;
126     }
127
128     /**
129      * Set the site id
130      *
131      * @param siteId
132      */

133     public void setSiteId (int siteId) {
134         this.siteId = siteId;
135     }
136
137     /**
138      * return the unique key identifier
139      *
140      * @return
141      */

142     public String JavaDoc getKey () {
143         return this.key;
144     }
145
146     /**
147      * Set the unique key identifier
148      *
149      * @param key
150      */

151     public void setKey (String JavaDoc key) {
152         this.key = key;
153     }
154
155     /**
156      * Set the key field name.
157      * It is the field name under which the key value is stored ( when adding to
158      * the index ), and from which we look for when removing from search engine.
159      * By Default the key field name is initialized with JahiaSearchConstant.OBJECT_KEY
160      *
161      * @param key
162      */

163     public void setKeyFieldName (String JavaDoc keyFieldName) {
164         if (keyFieldName != null && !"".equals (keyFieldName.trim ())) {
165             this.keyFieldName = keyFieldName;
166         }
167     }
168
169     /**
170      * Return the key field name.
171      *
172      * @param key
173      */

174     public String JavaDoc getKeyFieldName () {
175         return this.keyFieldName;
176     }
177
178     /**
179      * Return an hastable of key/values to store as fields for this object
180      * the key is a String and the values is an array of string values
181      *
182      * @return
183      */

184     public Hashtable getFields () {
185         return this.fields;
186     }
187
188     /**
189      * Add a single value field
190      *
191      * @param key
192      * @param vals
193      */

194     public void setField (String JavaDoc key, String JavaDoc val) {
195         if (key != null && val != null) {
196             String JavaDoc[] vals = {val};
197             this.fields.put (key, vals);
198         }
199     }
200
201     /**
202      * Add a multi-values field
203      *
204      * @param key
205      * @param vals
206      */

207     public void setField (String JavaDoc key, String JavaDoc[] vals) {
208         if (key != null && vals != null && vals.length > 0) {
209             this.fields.put (key, vals);
210         }
211     }
212
213     /**
214      * Remove an field
215      */

216     public void removeField (String JavaDoc key) {
217         if (key != null) {
218             this.fields.remove (key);
219         }
220     }
221
222     /**
223      * Define which field's value can be stored in the index
224      * Only small value should be stored in the index.
225      * On the other hand a whole file content should not.
226      * By default, field's value are stored in the index file.
227      * If you want to not store an field's value ( i.e a whole file content )
228      * Set this field to unstore
229      *
230      * @param key , the field key
231      * @param store, should the value stored in the index or not
232      */

233     public void unStoreField (String JavaDoc key) {
234         this.unStoreFields.add (key);
235     }
236
237     /**
238      * Return true if the given field's value will be stored in the index file
239      * or not
240      *
241      * @param key, the field key
242      *
243      * @return
244      */

245     public boolean isFieldUnStored (String JavaDoc key) {
246         if (key == null) {
247             return false;
248         }
249         return (this.unStoreFields.contains (key));
250     }
251
252     /**
253      * If this document can be scheduled ( indexation can be delayed, i.e in case of File Field Document which can take a lot
254      * of time when parsing pdf file ), it should return true and add itself in the indexationJob
255      *
256      * By default, return false.
257      *
258      * @param indexationJobDetail
259      * @return
260      */

261     public boolean scheduled(IndexationJobDetail indexationJobDetail){
262         return false;
263     }
264
265
266     /**
267      * This method is called when the document add itself in the ScheduledIndexationJob's vector of schedulable documents
268      *
269      */

270     public void doScheduledLoad(){
271         // by default do nothing
272
}
273
274     /**
275      * Return true if this document is allowed to be indexed by RAMIndexer
276      *
277      * @return
278      */

279     public boolean isCacheableWithRAMIndexer() {
280         return this.isCacheableWithRAMIndexer;
281     }
282
283     public void setCacheableWithRAMIndexer(boolean cacheableWithRAMIndexer) {
284         this.isCacheableWithRAMIndexer = cacheableWithRAMIndexer;
285     }
286
287 }
288
Popular Tags