1 11 package org.eclipse.help.internal.search.federated; 12 13 import java.util.ArrayList ; 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 25 public class LocalHelp implements ISearchEngine2 { 26 private static final int MAX_HITS = 500; 27 28 36 public void run(String 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 try { 51 Job.getJobManager().join(IndexerJob.FAMILY, monitor); 52 } catch (InterruptedException 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 ArrayList enabledHits = new ArrayList (); 68 for (int i = 0; i < searchHits.length; i++) { 69 SearchHit hit = searchHits[i]; 70 if (hit.getParticipantId()!=null) { 71 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 toAbsoluteHref(String href, boolean frames) { 85 return null; 86 } 87 88 89 public boolean open(String id) { 90 int sep = id.indexOf('/'); 91 if (sep== -1) 92 return false; 93 String 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 t) { 102 HelpBasePlugin.logError("Error occured in search participant trying to open document with id: " + id + ", participant: " + participant.getClass().getName(), t); return false; 104 } 105 } 106 } 107 | Popular Tags |