KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > search > federated > LocalHelp


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.federated;
12
13 import java.util.ArrayList JavaDoc;
14
15 import org.eclipse.core.runtime.*;
16 import org.eclipse.core.runtime.jobs.Job;
17 import org.eclipse.help.internal.base.*;
18 import org.eclipse.help.internal.search.*;
19 import org.eclipse.help.internal.workingset.WorkingSet;
20 import org.eclipse.help.search.*;
21
22 /**
23  * Local Help search engine participant in the federated search.
24  */

25 public class LocalHelp implements ISearchEngine2 {
26     private static final int MAX_HITS = 500;
27
28     /*
29      * (non-Javadoc)
30      *
31      * @see org.eclipse.help.internal.search.federated.ISearchEngine#run(java.lang.String,
32      * org.eclipse.help.internal.search.ISearchScope,
33      * org.eclipse.help.internal.search.federated.ISearchEngineResultCollector,
34      * org.eclipse.core.runtime.IProgressMonitor)
35      */

36     public void run(String JavaDoc query, ISearchScope scope,
37             final ISearchEngineResultCollector collector,
38             IProgressMonitor monitor) throws CoreException {
39
40         SearchQuery searchQuery = new SearchQuery();
41         searchQuery.setSearchWord(query);
42         WorkingSet[] workingSets = null;
43         LocalHelpScope localScope = (LocalHelpScope) scope;
44         if (localScope.getWorkingSet() != null)
45             workingSets = new WorkingSet[] { localScope.getWorkingSet() };
46         SearchResults localResults = new SearchResults(workingSets, MAX_HITS,
47                 Platform.getNL());
48         // If the indexer has been started and is currently running,
49
// wait for it to finish.
50
try {
51             Job.getJobManager().join(IndexerJob.FAMILY, monitor);
52         } catch (InterruptedException JavaDoc e) {
53         }
54         BaseHelpSystem.getSearchManager().search(searchQuery, localResults,
55                 monitor);
56         postResults(localResults, collector, localScope.getCapabilityFiltered());
57     }
58
59     private void postResults(SearchResults results,
60             ISearchEngineResultCollector collector, boolean activityFiltering) {
61         SearchHit[] searchHits = results.getSearchHits();
62         if (!activityFiltering) {
63             collector.accept(searchHits);
64             return;
65         }
66         // Filtering of results by activities
67
ArrayList JavaDoc enabledHits = new ArrayList JavaDoc();
68         for (int i = 0; i < searchHits.length; i++) {
69             SearchHit hit = searchHits[i];
70             if (hit.getParticipantId()!=null) {
71                 // hit comes from a search participant
72
if (HelpBasePlugin.getActivitySupport().isEnabled(hit.getHref()))
73                     enabledHits.add(hit);
74             }
75             else if (HelpBasePlugin.getActivitySupport().isEnabledTopic(
76                     hit.getHref(), Platform.getNL())) {
77                 enabledHits.add(hit);
78             }
79         }
80         collector.accept((SearchHit[]) enabledHits
81                 .toArray(new SearchHit[enabledHits.size()]));
82     }
83
84     public String JavaDoc toAbsoluteHref(String JavaDoc href, boolean frames) {
85         return null;
86     }
87     
88     
89     public boolean open(String JavaDoc id) {
90         int sep = id.indexOf('/');
91         if (sep== -1)
92             return false;
93         String JavaDoc participantId = id.substring(0, sep);
94         id = id.substring(sep+1);
95         LuceneSearchParticipant participant = BaseHelpSystem.getLocalSearchManager().getGlobalParticipant(participantId);
96         if (participant==null)
97             return false;
98         try {
99             return participant.open(id);
100         }
101         catch (Throwable JavaDoc t) {
102             HelpBasePlugin.logError("Error occured in search participant trying to open document with id: " + id + ", participant: " + participant.getClass().getName(), t); //$NON-NLS-1$ //$NON-NLS-2$
103
return false;
104         }
105     }
106 }
107
Popular Tags