KickJava   Java API By Example, From Geeks To Geeks.

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


1 //
2
// ____.
3
// __/\ ______| |__/\. _______
4
// __ .____| | \ | +----+ \
5
// _______| /--| | | - \ _ | : - \_________
6
// \\______: :---| : : | : | \________>
7
// |__\---\_____________:______: :____|____:_____\
8
// /_____|
9
//
10
// . . . i n j a h i a w e t r u s t . . .
11
//
12

13 //
14
// JahiaSearchService
15
// NK 25.01.2002 Integrate Lucene to implement search on container list.
16
//
17

18 package org.jahia.services.search;
19
20
21 import org.jahia.data.fields.JahiaField;
22 import org.jahia.data.search.JahiaSearchResult;
23 import org.jahia.exceptions.JahiaException;
24 import org.jahia.params.ParamBean;
25 import org.jahia.services.JahiaService;
26 import org.jahia.services.fields.ContentField;
27
28 import java.util.ArrayList JavaDoc;
29 import java.io.IOException JavaDoc;
30
31 import org.jahia.utils.fileparsers.FileExtractor;
32 import org.apache.lucene.index.IndexReader;
33
34 /**
35  * Search Service.
36  *
37  * @author DJ Original implementation
38  * @author NK Extended for lucene integration.
39  */

40 public abstract class JahiaSearchService extends JahiaService {
41
42     //--------------------------------------------------------------------------
43
/**
44      * Adding (indexing) an JahiaIndexableDocument
45      *
46      * @param indObj
47      */

48     public abstract void addToSearchEngine (JahiaIndexableDocument indObj);
49
50     /**
51      * this method is should only be used by the ScheduledIndexationJob to return back a scheduled document in the indexation queue without sending it to the other clusters
52      *
53      * @param indObj
54      */

55     public abstract void addScheduledDocumentToSearchEngine(JahiaIndexableDocument indObj);
56
57     //--------------------------------------------------------------------------
58
/**
59      * Remove a JahiaIndexableDocument from search engine.
60      *
61      * @param indObj
62      */

63     public abstract void removeFromSearchEngine (JahiaIndexableDocument indObj);
64
65     //--------------------------------------------------------------------------
66
/**
67      * Remove any document matching a field key from search index.
68      * The key field is by default JahiaSearchConstant.OBJECT_KEY
69      *
70      * @param siteId
71      * @param keyFieldValue, the key field value
72      */

73     public abstract void removeFromSearchEngine (int siteId,
74                                                  String JavaDoc keyFieldValue);
75
76     //--------------------------------------------------------------------------
77
/**
78      * Remove any document matching a field key from search index
79      *
80      * @param siteId
81      * @param keyFieldName, name of key field for which to remove all documents from index
82      * @param keyFieldValue, the key field value
83      */

84     public abstract void removeFromSearchEngine (int siteId,
85                                                  String JavaDoc keyFieldName,
86                                                  String JavaDoc keyFieldValue);
87
88     //--------------------------------------------------------------------------
89
/**
90      * Perform a search for a given JahiaSearcher object.
91      *
92      * @param ParamBean jParams, to check read access.
93      *
94      * @return JahiaSearchResult, containing a vector of matching objects.
95      */

96     public abstract JahiaSearchResult search (JahiaSearcher jSearcher, ParamBean jParams)
97             throws JahiaException;
98
99     //--------------------------------------------------------------------------
100
/**
101      * Return a vector of matching pages.
102      * Perform a search for a given query ( valid lucene query ).
103      *
104      * @param String queryString, a valid lucene query string.
105      * @param ParamBean jParams, to check read access.
106      * @param LanguageCodes, in which language to search.
107      *
108      * @return JahiaSearchResult, containing a vector of matching page.
109      *
110      * @Deprecated Should use search method with PageSearcher instead.
111      */

112     public abstract JahiaSearchResult doSearch (String JavaDoc queryString,
113                                                 ParamBean jParams,
114                                                 ArrayList JavaDoc languageCodes)
115             throws JahiaException;
116
117     //--------------------------------------------------------------------------
118
/**
119      * Re-index a field.
120      *
121      * @param fieldID int
122      * @param stagingOnly boolean, if false, skip re-index active version
123      * @param jParams ParamBean
124      */

125     public abstract void indexField (int fieldID,
126                                      boolean stagingOnly,
127                                      ParamBean jParams);
128
129     //--------------------------------------------------------------------------
130
/**
131      * Re-index a field.
132      *
133      * @param fieldID int
134      * @param stagingOnly boolean, if false, skip re-index active version
135      * @param jParams ParamBean
136      * @param allowInMemoryIndex boolean if true, index in in memory index ( temporary and limited momory-size index )
137      */

138     public abstract void indexField (int fieldID,
139                                      boolean stagingOnly,
140                                      ParamBean jParams, boolean allowInMemoryIndex);
141
142     //--------------------------------------------------------------------------
143
/**
144      * Add a field to search engine.
145      * With updated field, you should remove it first from search engine before
146      * adding it again.
147      *
148      * @param JahiaField aField, the field to index.
149      * @param workflowState effective workflow state to use
150      */

151     public abstract void addFieldToSearchEngine (JahiaField aField, int workflowState);
152
153     //--------------------------------------------------------------------------
154
/**
155      * Add a field to search engine.
156      * With updated field, you should remove it first from search engine before
157      * adding it again.
158      *
159      * @param JahiaField aField, the field to index.
160      * @param workflowState effective workflow state to use
161      * @param allowInMemoryIndex boolean if true, index in in memory index ( temporary and limited momory-size index )
162      */

163      public abstract void addFieldToSearchEngine (JahiaField aField,
164                                                       int workflowState,
165                                                       boolean allowInMemoryIndex);
166
167     //--------------------------------------------------------------------------
168
/**
169      * Remove a field from search engine.
170      *
171      * @param JahiaField aField, the field to remove.
172      */

173     public abstract void removeFieldFromSearchEngine (JahiaField aField);
174
175     //--------------------------------------------------------------------------
176
/**
177      * Remove a field from search engine.Remove all entry ( all lang,workflow...)
178      *
179      * @param JahiaField aField, the field to remove.
180      */

181     public abstract void removeFieldFromSearchEngine (ContentField contentField);
182
183     //--------------------------------------------------------------------------
184
/**
185      * Remove a field by it's wfs and language code.
186      * The key field is by default JahiaSearchConstant.OBJECT_KEY
187      *
188      * @param siteId
189      * @param fieldId
190      * @param workflowState
191      * @param languageCode
192      */

193     public abstract void removeFieldFromSearchEngine (int siteId,
194                                                       int fieldId,
195                                                       int workflowState,
196                                                       String JavaDoc languageCode);
197
198     //--------------------------------------------------------------------------
199
/**
200      * Return the current site's indexation status if any.
201      *
202      * @param siteID
203      * @return
204      */

205     public abstract SiteIndexationStatus getSiteIndexationStatus (int siteID);
206
207     /**
208      * This method is used to reflect amy changes to all clusters.
209      *
210      * @param status
211      */

212     public abstract void updateSiteIndexationStatus(SiteIndexationStatus status);
213
214     //--------------------------------------------------------------------------
215
/**
216      * Re-index a full site.
217      *
218      * @param siteID
219      * @param jParams
220      * @param deleteIndexFirst
221      * @param abortPreviousJob
222      * @return
223      */

224     public abstract boolean indexSite (int siteID,
225                               ParamBean jParams,
226                               boolean deleteIndexFirst,
227                               boolean abortPreviousJob);
228
229
230     //--------------------------------------------------------------------------
231
/**
232      * Abort site indexation.
233      *
234      * @param siteID
235      * @return
236      */

237     public abstract boolean abortSiteIndexation (int siteID);
238
239     //--------------------------------------------------------------------------
240
/**
241      * Perform an index optimization for a given site.
242      *
243      * @param int siteID
244      *
245      * @return boolean false on error.
246      */

247     public abstract boolean optimizeIndex (int siteID);
248
249     //--------------------------------------------------------------------------
250
/**
251      * Return the full path to the directory containing the index for a given site.
252      *
253      * @param int siteID
254      *
255      * @return String the site's index path, null if not exist.
256      */

257     public abstract String JavaDoc getSiteIndex (int siteID) throws JahiaException;
258
259     //--------------------------------------------------------------------------
260
/**
261      * Return the full path to search indexes root directory.
262      *
263      * @return String the site's index path, null if not exist.
264      */

265     public abstract String JavaDoc getSearchIndexRootDir () throws JahiaException;
266
267     /**
268      * Return a file extractor for a given content type
269      *
270      * @param contentType String
271      * @throws JahiaException
272      * @return FileExtractor
273      */

274     public abstract FileExtractor getFileExtractor(String JavaDoc contentType)
275         throws JahiaException;
276
277
278     /**
279      * Returns the number of pending files indexing queue
280      * -1 on error
281      * @return
282      */

283     public abstract int getNbOfFilesInQueue();
284
285     /**
286      * Returns the number of pending documents in the indexing queue
287      * -1 on error
288      * @return
289      */

290     public abstract int getNbDocumentsInQueue();
291
292     /**
293      * Wake up the main index thread
294      */

295     public abstract void notifyMainIndexThread();
296
297     public abstract RAMIndexer getRAMIndexer();
298
299     //--------------------------------------------------------------------------
300
/**
301      * Returns the IndexReader for a given site.
302      * Don't forget to close the returned index reader to flush change to the index file !
303      *
304      * @param int siteID, the site id.
305      *
306      * @return IndexReader reader, the IndexReader, null if not found.
307      */

308     public abstract IndexReader getIndexReader (int siteID)
309             throws IOException JavaDoc, JahiaException;
310
311 }
312
Popular Tags