KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > search > SearchIndexCache


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.help.internal.search;
12
13 import java.io.File JavaDoc;
14 import java.net.URL JavaDoc;
15
16 import org.apache.lucene.document.Document;
17 import org.apache.lucene.document.Field;
18 import org.eclipse.core.runtime.IStatus;
19 import org.eclipse.help.internal.base.HelpBasePlugin;
20 import org.eclipse.help.internal.toc.TocManager;
21
22 /**
23  * A search index used for caching filtered indexed documents. The master index
24  * documents are indexed unfiltered so there are potential false hits. This index
25  * is used to reindex those potential false hits (filtered this time) and search
26  * again. The index is updated as needed.
27  */

28 public class SearchIndexCache extends SearchIndex {
29
30     private String JavaDoc filters;
31     
32     /**
33      * Constructs a new cache index with the given info. The cache index sits
34      * beside the master index in the file system.
35      *
36      * @param locale the locale for this index
37      * @param analyzerDesc the analyzer to use
38      * @param tocManager the toc manager to use
39      */

40     public SearchIndexCache(String JavaDoc locale, AnalyzerDescriptor analyzerDesc, TocManager tocManager) {
41         super(new File JavaDoc(HelpBasePlugin.getConfigurationDirectory(), "indexCache/" + locale), //$NON-NLS-1$
42
locale, analyzerDesc, tocManager, null);
43     }
44
45     /**
46      * A variant of addDocument() that also takes the current state of filters
47      * at the time of indexing.
48      *
49      * e.g. "os=win32,plugin=org.eclipse.help,plugin=org.eclipse.help.base"
50      *
51      * @param name the document name (href in our case)
52      * @param url the URL to get the content to index
53      * @param filters the currently active filters
54      * @return the status of the operation
55      */

56     public IStatus addDocument(String JavaDoc name, URL JavaDoc url, String JavaDoc filters) {
57         this.filters = filters;
58         return super.addDocument(name, url);
59     }
60     
61     protected void addExtraFields(Document doc) {
62         super.addExtraFields(doc);
63         if (filters != null) {
64             doc.add(Field.UnIndexed("filters", filters)); //$NON-NLS-1$
65
}
66     }
67 }
Popular Tags