diff options
22 files changed, 149 insertions, 1042 deletions
diff --git a/org.eclipse.help.base/preferences.ini b/org.eclipse.help.base/preferences.ini index dae65a067..973eeb784 100644 --- a/org.eclipse.help.base/preferences.ini +++ b/org.eclipse.help.base/preferences.ini @@ -150,15 +150,6 @@ showDisabledActivityTopics=off activeHelp=true ######################### -# Searching -######################### - -# Whether or not to show potential hits in the search results by default. -# Potential hits may arise when search found a match in a section that may or may -# not be filtered out. Note: Setting to false may adversely affect performance. -show_potential_hits=true - -######################### # Remote help ######################### remoteHelpOn=false diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/base/BaseHelpSystem.java b/org.eclipse.help.base/src/org/eclipse/help/internal/base/BaseHelpSystem.java index 2a5a62e32..4205909c5 100644 --- a/org.eclipse.help.base/src/org/eclipse/help/internal/base/BaseHelpSystem.java +++ b/org.eclipse.help.base/src/org/eclipse/help/internal/base/BaseHelpSystem.java @@ -40,50 +40,34 @@ import org.osgi.framework.Bundle; * Base Help System. */ public final class BaseHelpSystem { - protected static final BaseHelpSystem instance = new BaseHelpSystem(); - - private final static String WEBAPP_EXTENSION_ID = HelpBasePlugin.PLUGIN_ID - + ".webapp"; //$NON-NLS-1$ - + + private static final BaseHelpSystem instance = new BaseHelpSystem(); + + private static final String WEBAPP_EXTENSION_ID = HelpBasePlugin.PLUGIN_ID + ".webapp"; //$NON-NLS-1$ private static final String WEBAPP_DEFAULT_ATTRIBUTE = "default"; //$NON-NLS-1$ - - public final static String BOOKMARKS = "bookmarks"; //$NON-NLS-1$ - - public final static String WORKING_SETS = "workingSets"; //$NON-NLS-1$ - - public final static String WORKING_SET = "workingSet"; //$NON-NLS-1$ - - public final static int MODE_WORKBENCH = 0; - - public final static int MODE_INFOCENTER = 1; - - public final static int MODE_STANDALONE = 2; - - protected SearchManager searchManager; - - protected WorkingSetManager workingSetManager; - - protected BookmarkManager bookmarkManager; + + public static final String BOOKMARKS = "bookmarks"; //$NON-NLS-1$ + public static final String WORKING_SETS = "workingSets"; //$NON-NLS-1$ + public static final String WORKING_SET = "workingSet"; //$NON-NLS-1$ + + public static final int MODE_WORKBENCH = 0; + public static final int MODE_INFOCENTER = 1; + public static final int MODE_STANDALONE = 2; private int mode = MODE_WORKBENCH; + + private SearchManager searchManager; + private WorkingSetManager workingSetManager; + private BookmarkManager bookmarkManager; private boolean webappStarted = false; - + private boolean webappRunning = false; private IErrorUtil defaultErrorMessenger; - private IBrowser browser; - private IBrowser internalBrowser; - private HelpDisplay helpDisplay = null; - - private boolean webappRunning = false; - private boolean rtl = false; - /** - * Constructor. - */ private BaseHelpSystem() { super(); rtl = initializeRTL(); @@ -116,11 +100,6 @@ public final class BaseHelpSystem { return getSearchManager().getLocalSearchManager(); } - /** - * Used to obtain Working Set Manager - * - * @return instance of WorkingSetManager - */ public static synchronized WorkingSetManager getWorkingSetManager() { if (getInstance().workingSetManager == null) { getInstance().workingSetManager = new WorkingSetManager(); @@ -128,11 +107,6 @@ public final class BaseHelpSystem { return getInstance().workingSetManager; } - /** - * Used to obtain Bookmark Manager - * - * @return instance of BookmarkManager - */ public static synchronized BookmarkManager getBookmarkManager() { if (getInstance().bookmarkManager == null) { getInstance().bookmarkManager = new BookmarkManager(); @@ -140,30 +114,24 @@ public final class BaseHelpSystem { return getInstance().bookmarkManager; } - /** + /* * Allows Help UI to plug-in a soft adapter that delegates all the work to * the workbench browser support. - * - * @since 3.1 - * @param browser - * the instance to use when external browser is needed */ - public synchronized void setBrowserInstance(IBrowser browser) { this.browser = browser; } public static synchronized IBrowser getHelpBrowser(boolean forceExternal) { - if (!forceExternal - && !BrowserManager.getInstance().isAlwaysUseExternal()) { - if (getInstance().internalBrowser == null) - getInstance().internalBrowser = BrowserManager.getInstance() - .createBrowser(false); + if (!forceExternal && !BrowserManager.getInstance().isAlwaysUseExternal()) { + if (getInstance().internalBrowser == null) { + getInstance().internalBrowser = BrowserManager.getInstance().createBrowser(false); + } return getInstance().internalBrowser; } - if (getInstance().browser == null) - getInstance().browser = BrowserManager.getInstance() - .createBrowser(true); + if (getInstance().browser == null) { + getInstance().browser = BrowserManager.getInstance().createBrowser(true); + } return getInstance().browser; } @@ -173,30 +141,14 @@ public final class BaseHelpSystem { return getInstance().helpDisplay; } - /** - */ - public BaseHelpSystem newInstance() { - return null; - } - - /** + /* * Shuts down the BaseHelpSystem. - * - * @exception CoreException - * if this method fails to shut down this plug-in */ public static void shutdown() throws CoreException { - if (HelpBasePlugin.DEBUG) { - System.out.println("Base Help System is shutting down."); //$NON-NLS-1$ - } - // close any browsers created - // BrowserManager.getInstance().closeAll(); - if (getInstance().bookmarkManager != null) { getInstance().bookmarkManager.close(); getInstance().bookmarkManager = null; } - if (getInstance().searchManager != null) { getInstance().searchManager.close(); getInstance().searchManager = null; @@ -204,12 +156,9 @@ public final class BaseHelpSystem { if (getInstance().webappStarted) { // stop the web apps WebappManager.stop("help"); //$NON-NLS-1$ - if (getMode() != MODE_WORKBENCH) + if (getMode() != MODE_WORKBENCH) { WebappManager.stop("helpControl"); //$NON-NLS-1$ - } - - if (HelpBasePlugin.DEBUG) { - System.out.println("Help System is shut down."); //$NON-NLS-1$ + } } } @@ -222,21 +171,16 @@ public final class BaseHelpSystem { public void displayError(String msg) { System.out.println(msg); } - public void displayError(String msg, Thread uiThread) { System.out.println(msg); } - }); HelpBasePlugin.getDefault().getPluginPreferences(); - } catch (Exception e) { + } + catch (Exception e) { HelpBasePlugin.getDefault().getLog().log( new Status(IStatus.ERROR, HelpBasePlugin.PLUGIN_ID, 0, - "Error in launching help.", //$NON-NLS-1$ - e)); - } - if (HelpBasePlugin.DEBUG) { - System.out.println("Base Help System started."); //$NON-NLS-1$ + "Error launching help.", e)); //$NON-NLS-1$ } /* @@ -254,19 +198,14 @@ public final class BaseHelpSystem { public static boolean ensureWebappRunning() { if (!getInstance().webappStarted) { getInstance().webappStarted = true; - String webappPlugin = getWebappPlugin(); - + if (getMode() != MODE_WORKBENCH) { // start the help control web app try { - WebappManager.start("helpControl", //$NON-NLS-1$ - webappPlugin, Path.EMPTY); + WebappManager.start("helpControl", webappPlugin, Path.EMPTY); //$NON-NLS-1$ } catch (CoreException e) { - HelpBasePlugin - .logError( - "Stand-alone help control web application failed to run.", //$NON-NLS-1$ - e); + HelpBasePlugin.logError("Stand-alone help control web application failed to run.", e); //$NON-NLS-1$ return false; } } @@ -274,15 +213,11 @@ public final class BaseHelpSystem { try { WebappManager.start("help", webappPlugin, Path.EMPTY); //$NON-NLS-1$ } catch (CoreException e) { - HelpBasePlugin - .logError( - "The embedded application server could not run help web application.", e); //$NON-NLS-1$ - BaseHelpSystem.getDefaultErrorUtil().displayError( - HelpBaseResources.HelpWebappNotStarted); + HelpBasePlugin.logError("The embedded application server could not run help web application.", e); //$NON-NLS-1$ + BaseHelpSystem.getDefaultErrorUtil().displayError(HelpBaseResources.HelpWebappNotStarted); return false; } getInstance().webappRunning = true; - } return getInstance().webappRunning; } @@ -308,19 +243,23 @@ public final class BaseHelpSystem { public static URL resolve(String href, String servlet) { String url = null; - if (href == null || href.indexOf("://") != -1) //$NON-NLS-1$ + if (href == null || href.indexOf("://") != -1) { //$NON-NLS-1$ url = href; + } else { BaseHelpSystem.ensureWebappRunning(); String base = getBase(servlet); - if (href.startsWith("/")) //$NON-NLS-1$ + if (href.startsWith("/")) { //$NON-NLS-1$ url = base + href; - else + } + else { url = base + "/" + href; //$NON-NLS-1$ + } } try { return new URL(url); - } catch (MalformedURLException e) { + } + catch (MalformedURLException e) { return null; } } @@ -335,8 +274,9 @@ public final class BaseHelpSystem { getBase("/help/ntopic"), //$NON-NLS-1$ getBase("/help/rtopic") }; //$NON-NLS-1$ for (int i = 0; i < baseVariants.length; i++) { - if (href.startsWith(baseVariants[i])) + if (href.startsWith(baseVariants[i])) { return href.substring(baseVariants[i].length()); + } } return href; } @@ -352,48 +292,40 @@ public final class BaseHelpSystem { + WebappManager.getPort() + servlet; } - /** - * Returns the mode. - * - * @return int + /* + * Returns the mode of operation. */ public static int getMode() { return getInstance().mode; } - /** - * Sets the mode. - * - * @param mode - * The mode to set + /* + * Sets the mode of operation. */ public static void setMode(int mode) { getInstance().mode = mode; HelpSystem.setShared(mode == MODE_INFOCENTER); } - /** + /* * Sets the error messenger */ public static void setDefaultErrorUtil(IErrorUtil em) { getInstance().defaultErrorMessenger = em; } - /** + /* * Returns the default error messenger. When no UI is present, all errors * are sent to System.out. - * - * @return IErrorMessenger */ public static IErrorUtil getDefaultErrorUtil() { return getInstance().defaultErrorMessenger; } - /** + /* * Returns the plugin id that defines the help webapp */ private static String getWebappPlugin() { - // get the webapp extension from the system plugin registry IExtensionPoint point = Platform.getExtensionRegistry() .getExtensionPoint(WEBAPP_EXTENSION_ID); diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/base/HelpBasePlugin.java b/org.eclipse.help.base/src/org/eclipse/help/internal/base/HelpBasePlugin.java index 9ac8db4b1..c8d2a5764 100644 --- a/org.eclipse.help.base/src/org/eclipse/help/internal/base/HelpBasePlugin.java +++ b/org.eclipse.help.base/src/org/eclipse/help/internal/base/HelpBasePlugin.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. + * Copyright (c) 2000, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,27 +9,24 @@ * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.help.internal.base; -import java.io.*; -import java.net.*; -import org.eclipse.core.runtime.*; -import org.eclipse.osgi.service.datalocation.*; -import org.osgi.framework.*; +import java.io.File; +import java.net.URL; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Plugin; +import org.eclipse.core.runtime.Status; +import org.eclipse.osgi.service.datalocation.Location; +import org.osgi.framework.BundleContext; + /** * Help Base plug-in. - * - * @since 3.0 */ public class HelpBasePlugin extends Plugin { public final static String PLUGIN_ID = "org.eclipse.help.base"; //$NON-NLS-1$ - // debug options - public static boolean DEBUG = false; - public static boolean DEBUG_SEARCH = false; - - protected static HelpBasePlugin plugin; -// private static BundleContext bundleContext; - + private static HelpBasePlugin plugin; private File configurationDirectory; private IHelpActivitySupport helpActivitySupport = new IHelpActivitySupport() { @@ -65,106 +62,56 @@ public class HelpBasePlugin extends Plugin { return null; } }; - /** - * Logs an Error message with an exception. - */ + public static synchronized void logError(String message, Throwable ex) { - if (message == null) + if (message == null) { message = ""; //$NON-NLS-1$ - Status errorStatus = new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, - message, ex); + } + Status errorStatus = new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, message, ex); HelpBasePlugin.getDefault().getLog().log(errorStatus); } - /** - * Logs an IStatus. - */ + public static synchronized void logStatus(IStatus errorStatus) { HelpBasePlugin.getDefault().getLog().log(errorStatus); } - /** - * Logs a Warning message with an exception. - */ - public static synchronized void logWarning(String message) { - if (HelpBasePlugin.DEBUG) { - if (message == null) - message = ""; //$NON-NLS-1$ - Status warningStatus = new Status(IStatus.WARNING, PLUGIN_ID, - IStatus.OK, message, null); - HelpBasePlugin.getDefault().getLog().log(warningStatus); - } - } - /** - * @return the singleton instance of the Help Base plugin - */ public static HelpBasePlugin getDefault() { return plugin; } - /* - * (non-Javadoc) - * - * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) - */ + public void stop(BundleContext context) throws Exception { plugin.savePluginPreferences(); BaseHelpSystem.shutdown(); plugin = null; -// bundleContext = null; super.stop(context); } - /* - * (non-Javadoc) - * - * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) - */ + public void start(BundleContext context) throws Exception { super.start(context); plugin = this; -// bundleContext = context; - // Setup debugging options - DEBUG = isDebugging(); - if (DEBUG) { - DEBUG_SEARCH = "true".equalsIgnoreCase(Platform.getDebugOption(PLUGIN_ID + "/debug/search")); //$NON-NLS-1$ //$NON-NLS-2$ - } // determine configuration location for this plug-in Location location = Platform.getConfigurationLocation(); if (location != null) { URL configURL = location.getURL(); if (configURL != null && configURL.getProtocol().startsWith("file")) { //$NON-NLS-1$ - configurationDirectory = new File(configURL.getFile(), - PLUGIN_ID); + configurationDirectory = new File(configURL.getFile(), PLUGIN_ID); } } if (configurationDirectory == null) { configurationDirectory = getStateLocation().toFile(); } - // BaseHelpSystem.startup(); } - /** - * Used to obtain directory where configuration (like help index) can be - * stored - */ public static File getConfigurationDirectory() { return getDefault().configurationDirectory; } - /** - * Used to obtain help activity support - * - * @return instance of IHelpActivitySupport - */ public static IHelpActivitySupport getActivitySupport() { return getDefault().helpActivitySupport; } - /** - * Sets the activity support - * - * @param activitySupport - */ public static void setActivitySupport(IHelpActivitySupport activitySupport) { getDefault().helpActivitySupport = activitySupport; } diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/base/IHelpBaseConstants.java b/org.eclipse.help.base/src/org/eclipse/help/internal/base/IHelpBaseConstants.java index 6a349366e..8e916e96b 100644 --- a/org.eclipse.help.base/src/org/eclipse/help/internal/base/IHelpBaseConstants.java +++ b/org.eclipse.help.base/src/org/eclipse/help/internal/base/IHelpBaseConstants.java @@ -18,7 +18,6 @@ public interface IHelpBaseConstants { String P_KEY_DIALOG_INFOPOP = "dialog_infopop";//$NON-NLS-1$ String P_KEY_OPEN_IN_EDITOR = "open_in_browser"; //$NON-NLS-1$ String P_KEY_ALWAYS_EXTERNAL_BROWSER = "always_external_browser"; //$NON-NLS-1$ - String P_KEY_SHOW_POTENTIAL_HITS = "show_potential_hits"; //$NON-NLS-1$ String P_KEY_REMOTE_HELP_ON = "remoteHelpOn"; //$NON-NLS-1$ String P_KEY_REMOTE_HELP_HOST = "remoteHelpHost"; //$NON-NLS-1$ String P_KEY_REMOTE_HELP_PATH = "remoteHelpPath"; //$NON-NLS-1$ diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteSearchParser.java b/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteSearchParser.java index 5d8a51d92..5ab71dadb 100644 --- a/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteSearchParser.java +++ b/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteSearchParser.java @@ -111,7 +111,7 @@ public class RemoteSearchParser extends DefaultHandler { private void handleHit(Attributes attr) { String href = attr.getValue("href"); //$NON-NLS-1$ String label = attr.getValue("label"); //$NON-NLS-1$ - String filters = attr.getValue("filters"); //$NON-NLS-1$ + boolean isPotentialHit = (String.valueOf(true).equalsIgnoreCase(attr.getValue("isPotentialHit"))); //$NON-NLS-1$ float score; try { score = Float.parseFloat(attr.getValue("score")); //$NON-NLS-1$ @@ -120,7 +120,7 @@ public class RemoteSearchParser extends DefaultHandler { // score was probably missing; default to 0 score = 0; } - SearchHit hit = new SearchHit(href, label, null, score, null, null, null, filters); + SearchHit hit = new SearchHit(href, label, null, score, null, null, null, isPotentialHit); hits.add(hit); stack.push(hit); } diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/search/HTMLDocParser.java b/org.eclipse.help.base/src/org/eclipse/help/internal/search/HTMLDocParser.java index f5e00171c..5a57daca9 100644 --- a/org.eclipse.help.base/src/org/eclipse/help/internal/search/HTMLDocParser.java +++ b/org.eclipse.help.base/src/org/eclipse/help/internal/search/HTMLDocParser.java @@ -10,13 +10,17 @@ *******************************************************************************/ package org.eclipse.help.internal.search; -import java.io.*; -import java.net.*; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StreamTokenizer; +import java.io.UnsupportedEncodingException; +import java.net.URL; import java.util.Locale; import java.util.StringTokenizer; -import org.apache.lucene.demo.html.*; -import org.eclipse.help.internal.base.*; +import org.apache.lucene.demo.html.HTMLParser; /** * Parser HTML documents. Extracts document encoding from header, and delegates @@ -71,25 +75,12 @@ public class HTMLDocParser { htmlParser = new HTMLParser(new InputStreamReader(inputStream, encoding)); - } catch (UnsupportedEncodingException uee) { - if (HelpBasePlugin.DEBUG_SEARCH) { - System.out - .println(this.getClass().getName() - + " JVM does not support encoding " //$NON-NLS-1$ - + encoding - + " specified in document " //$NON-NLS-1$ - + url.getPath() - + ". Default encoding will be used during indexing."); //$NON-NLS-1$ - } - htmlParser = new HTMLParser(new InputStreamReader(inputStream)); } - } else { - if (HelpBasePlugin.DEBUG_SEARCH) { - System.out.println(this.getClass().getName() - + " Encoding not found in document " //$NON-NLS-1$ - + url.getPath() - + ". Default encoding will be used during indexing."); //$NON-NLS-1$ + catch (UnsupportedEncodingException uee) { + htmlParser = new HTMLParser(new InputStreamReader(inputStream)); } + } + else { htmlParser = new HTMLParser(new InputStreamReader(inputStream)); } } diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/search/IndexingOperation.java b/org.eclipse.help.base/src/org/eclipse/help/internal/search/IndexingOperation.java index fae77d69d..928919db0 100644 --- a/org.eclipse.help.base/src/org/eclipse/help/internal/search/IndexingOperation.java +++ b/org.eclipse.help.base/src/org/eclipse/help/internal/search/IndexingOperation.java @@ -86,10 +86,6 @@ class IndexingOperation { numRemoved = staleDocs.size(); Collection newDocs = getAddedDocuments(index); numAdded = newDocs.size(); - if (HelpBasePlugin.DEBUG_SEARCH) { - System.out - .println("IndexingOperation.execute: " + numRemoved + " documents in deleted plug-ins, " + numAdded + " documents in added plug-ins."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } // if collection is empty, we may return right away // need to check if we have to do anything to the progress monitor @@ -149,31 +145,14 @@ class IndexingOperation { /** * Returns documents that must be deleted - * - * @param pm - * @param newDocs - * @return - * @throws IndexingException */ private Map addNewDocuments(IProgressMonitor pm, Collection newDocs, boolean opened) throws IndexingException { Map prebuiltDocs = mergeIndexes(pm, opened); - if (HelpBasePlugin.DEBUG_SEARCH) { - System.out - .println("IndexOperation.addNewDocuments: " + prebuiltDocs.size() + " different documents merged."); //$NON-NLS-1$ //$NON-NLS-2$ - } checkCancelled(pm); Collection docsToIndex = calculateDocsToAdd(newDocs, prebuiltDocs); checkCancelled(pm); Map docsToDelete = calculateNewToRemove(newDocs, prebuiltDocs); - // IProgressMonitor addMonitor = new SubProgressMonitor(pm, - // docsToDelete.size()*10 + docsToIndex.size()*100; - if (HelpBasePlugin.DEBUG_SEARCH) { - System.out - .println("IndexOperation.addNewDocuments: " + docsToIndex.size() + " documents not yet indexed."); //$NON-NLS-1$ //$NON-NLS-2$ - System.out - .println("IndexOperation.addNewDocuments: " + docsToDelete.size() + " documents have more than one copy indexed."); //$NON-NLS-1$ //$NON-NLS-2$ - } pm.beginTask("", 10 * docsToIndex.size() + docsToDelete.size()); //$NON-NLS-1$ checkCancelled(pm); addDocuments(new SubProgressMonitor(pm, 10 * docsToIndex.size()), @@ -295,12 +274,9 @@ class IndexingOperation { checkCancelled(pm); if (numRemoved > 0) { - if (HelpBasePlugin.DEBUG_SEARCH) { - System.out.println("SearchIndex.removeStaleDocuments"); //$NON-NLS-1$ - } - - if (!index.beginDeleteBatch()) + if (!index.beginDeleteBatch()) { throw new IndexingException(); + } checkCancelled(pm); pm.subTask(HelpBaseResources.UpdatingIndex); MultiStatus multiStatus = null; @@ -539,24 +515,11 @@ class IndexingOperation { return indexes; } - /** - * - * @param monitor - * @param addedDocs - * @param indices - * @return Map. Keys are /pluginid/href of all merged Docs. Values are null - * for added document, or String[] of indexIds with duplicates of - * the document - */ private Map mergeIndexes(IProgressMonitor monitor, boolean opened) throws IndexingException { Collection addedPluginIds = getAddedPlugins(index); PrebuiltIndexes indexes = getIndexesToAdd(addedPluginIds); PluginIndex[] pluginIndexes = indexes.getIndexes(); - if (HelpBasePlugin.DEBUG_SEARCH) { - System.out - .println("IndexingOperation.mergeIndexes: " + pluginIndexes.length + " plugins with prebuilt index."); //$NON-NLS-1$ //$NON-NLS-2$ - } Map mergedDocs = null; // Always perform add batch to ensure that index is created and saved // even if no new documents diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/search/LocalSearchManager.java b/org.eclipse.help.base/src/org/eclipse/help/internal/search/LocalSearchManager.java index 082e2a6a7..74e1f626b 100644 --- a/org.eclipse.help.base/src/org/eclipse/help/internal/search/LocalSearchManager.java +++ b/org.eclipse.help.base/src/org/eclipse/help/internal/search/LocalSearchManager.java @@ -15,7 +15,6 @@ import java.net.URL; import java.nio.channels.OverlappingFileLockException; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -33,16 +32,13 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; -import org.eclipse.help.HelpSystem; import org.eclipse.help.IHelpResource; import org.eclipse.help.internal.HelpPlugin; import org.eclipse.help.internal.ITocsChangedListener; import org.eclipse.help.internal.base.BaseHelpSystem; import org.eclipse.help.internal.base.HelpBasePlugin; -import org.eclipse.help.internal.base.IHelpBaseConstants; import org.eclipse.help.internal.search.IndexingOperation.IndexingException; import org.eclipse.help.internal.util.URLCoder; -import org.eclipse.help.internal.xhtml.XHTMLSupport; import org.eclipse.help.search.LuceneSearchParticipant; import org.osgi.framework.Bundle; @@ -51,18 +47,12 @@ import org.osgi.framework.Bundle; */ public class LocalSearchManager implements ITocsChangedListener { - private static final String EMPTY_STRING = ""; //$NON-NLS-1$ private static final String SEARCH_PARTICIPANT_XP_FULLNAME = "org.eclipse.help.base.luceneSearchParticipants"; //$NON-NLS-1$ private static final String SEARCH_PARTICIPANT_XP_NAME = "searchParticipant"; //$NON-NLS-1$ private static final String BINDING_XP_NAME = "binding"; //$NON-NLS-1$ private static final Object PARTICIPANTS_NOT_FOUND = new Object(); - /** Search indexes, by locale */ private Map indexes = new HashMap(); - private Map indexCaches = new HashMap(); - - /** Caches analyzer descriptors for each locale */ private Map analyzerDescriptors = new HashMap(); - private Map searchParticipantsById = new HashMap(); private Map searchParticipantsByPlugin = new HashMap(); private ArrayList globalSearchParticipants; @@ -178,8 +168,8 @@ public class LocalSearchManager implements ITocsChangedListener { String id = doc.get("id"); //$NON-NLS-1$ String participantId = doc.get("participantId"); //$NON-NLS-1$ String label = doc.get("raw_title"); //$NON-NLS-1$ - String filters = doc.get("filters"); //$NON-NLS-1$ - list.add(new SearchHit(href, label, summary, score, null, id, participantId, filters)); + boolean isPotentialHit = (doc.get("filters") != null); //$NON-NLS-1$ + list.add(new SearchHit(href, label, summary, score, null, id, participantId, isPotentialHit)); } catch (IOException e) { HelpBasePlugin.logError("An error occured while reading search hits", e); //$NON-NLS-1$ @@ -190,25 +180,6 @@ public class LocalSearchManager implements ITocsChangedListener { } /** - * Returns whether or not the given filters match the current filterable - * property values. For example, if the filters contain "os=win32", the filter - * matches only if the OS is windows. - * - * @param filters the filters to check, e.g. "os=linux,ws!=gtk,arch=x86" - * @return whether or not the filters are satisfied - */ - private boolean filtersMatch(String filters) { - StringTokenizer tok = new StringTokenizer(filters, ","); //$NON-NLS-1$ - while (tok.hasMoreTokens()) { - String filter = tok.nextToken(); - if (!XHTMLSupport.getFilterProcessor().isFilteredIn(filter)) { - return false; - } - } - return true; - } - - /** * Public for use by indexing tool */ public SearchIndexWithIndexingProgress getIndex(String locale) { @@ -223,18 +194,6 @@ public class LocalSearchManager implements ITocsChangedListener { } } - private SearchIndexCache getIndexCache(String locale) { - synchronized (indexCaches) { - Object index = indexCaches.get(locale); - if (index == null) { - index = new SearchIndexCache(locale, getAnalyzer(locale), HelpPlugin - .getTocManager()); - indexCaches.put(locale, index); - } - return (SearchIndexCache) index; - } - } - /** * Obtains AnalyzerDescriptor that indexing and search should use for a given locale. * @@ -587,212 +546,23 @@ public class LocalSearchManager implements ITocsChangedListener { return (ArrayList) result; } - /** - * Searches index for documents containing an expression. Searching is - * done in potentially several phases. There are two indexes in play; the - * master index, which has all documents indexed unfiltered, and the cache - * index, which has a subset of all documents indexed filtered, and is created - * on demand. - * - * The procedure for searching is as follows: - * - * 1. Search the master index. This will yield potential false positives - * because the master index docs were unfiltered. - * 2. For those docs that didn't have filters, mark them as hits. For the - * potential false positives, search the cache index. - * 3. For each hit in the cache index, check whether the filters used at the - * time of indexing agree with the current filters. If yes, mark as hit. If - * no, reindex those that didn't match with the current filters (or weren't - * found at all). - * 4. Search the now-updated cache for these remaining documents. - */ public void search(ISearchQuery searchQuery, ISearchHitCollector collector, IProgressMonitor pm) throws QueryTooComplexException { - SearchIndexWithIndexingProgress index = getIndex(searchQuery.getLocale()); - try { - ensureIndexUpdated(pm, index); - if (!index.exists()) { - // no indexable documents, hence no index - // or index is corrupted - return; - } - } catch (IndexingOperation.IndexingException ie) { - if (HelpBasePlugin.DEBUG_SEARCH) { - System.out.println(this.getClass().getName() + " IndexUpdateException occurred."); //$NON-NLS-1$ - } - } - - final List hits = new ArrayList(); - final List potentialHits = new ArrayList(); - final List needReindexingHits = new ArrayList(); - final String[] highlightTerms = new String[1]; - - /* - * Pass 1: Search the master index. This will yield definite hits, - * potentially false hits, and the terms to highlight. - */ - searchPass1(searchQuery, hits, potentialHits, highlightTerms); - - if (!potentialHits.isEmpty()) { - /* - * Pass 2: Ensure that the cache index is up to date. This will yield - * all potential false hits' docs that need to be reindexed for the cache. - */ - searchPass2(searchQuery, potentialHits, needReindexingHits); - if (!needReindexingHits.isEmpty()) { - reindex(needReindexingHits, searchQuery.getLocale()); - } - - /* - * Pass 3: Now that cache is up to date, search the cache and add - * to the definite hits. - */ - searchPass3(searchQuery, hits); - - // sort by score - Collections.sort(hits); - } - - // send out the final results - if (highlightTerms[0] == null) { - highlightTerms[0] = EMPTY_STRING; - } - collector.addHits(hits, highlightTerms[0]); - } - - /** - * Performs the initial search pass. This searches the master index - * (unfiltered documents). This will yield definite hits and potentially - * false hits, added to the corresponding collection parameters. This - * also yields the terms to highlight in the result. - * - * Infocenter doesn't filter, so in this mode there are never - * potential false hits. - * - * @param searchQuery what to search for - * @param hits those hits that we know for sure are not false hits - * @param potentialFalseHits hits that may be false hits (we are not sure) - * @param highlightTerms the terms to highlight - */ - private void searchPass1(ISearchQuery searchQuery, Collection hits, Collection potentialFalseHits, String[] highlightTerms) { - final Collection fHits = hits; - final Collection fPotentialFalseHits = potentialFalseHits; - final String[] fHighlightTerms = highlightTerms; - ISearchHitCollector collector = new ISearchHitCollector() { - public void addHits(List hits, String wordsSearched) { - boolean isInfocenter = HelpSystem.isShared(); - boolean showPotentialHits = HelpBasePlugin.getDefault().getPluginPreferences() - .getBoolean(IHelpBaseConstants.P_KEY_SHOW_POTENTIAL_HITS); - fHighlightTerms[0] = wordsSearched; - Iterator iter = hits.iterator(); - while (iter.hasNext()) { - SearchHit hit = (SearchHit)iter.next(); - String filters = hit.getFilters(); - - // if it has filters it is potentially a false hit - if (!showPotentialHits && !isInfocenter && filters != null) { - fPotentialFalseHits.add(hit); - } - else { - fHits.add(hit); - } - } - } - }; - - /* - * Perform the initial search pass on the master index. This will - * find all potential hits. - */ - SearchIndex index = getIndex(searchQuery.getLocale()); - index.search(searchQuery, collector); - } - - /** - * Performs the second search pass. The only purpose for this pass is - * to check whether the cache index is up to date or not. This will search - * the cache, check whether the filters match the current values, and find - * the potential false hit documents that haven't yet been indexed. - * - * @param searchQuery what to search for - * @param potentialFalseHits the potentially false hits (not modified) - * @param needReindexingHits the hits whose docs need to be indexed or reindexed - */ - private void searchPass2(ISearchQuery searchQuery, Collection potentialFalseHits, Collection needReindexingHits) { - final List secondPassDefiniteHits = new ArrayList(); - final Collection fNeedReindexingHits = needReindexingHits; - ISearchHitCollector collector = new ISearchHitCollector() { - public void addHits(List hits, String wordsSearched) { - Iterator iter = hits.iterator(); - while (iter.hasNext()) { - SearchHit hit = (SearchHit)iter.next(); - String filters = hit.getFilters(); - - /* - * If the current filter property values (e.g. os, - * ws) match those used at indexing time we are ok. - * Otherwise we need to reindex with updated filters. - */ - if (filtersMatch(filters)) { - secondPassDefiniteHits.add(hit); - } - else { - fNeedReindexingHits.add(hit); - } - } - } - }; - - // perform the second search pass - SearchIndexCache indexCache = getIndexCache(searchQuery.getLocale()); - if (indexCache.exists()) { - indexCache.search(searchQuery, collector); - } - - // are all the potential false hits accounted for? - // for ones that aren't, check if need reindexing - Set unaccountedFor = new HashSet(potentialFalseHits); - unaccountedFor.removeAll(secondPassDefiniteHits); - unaccountedFor.removeAll(needReindexingHits); - - Iterator iter = unaccountedFor.iterator(); - while (iter.hasNext()) { - SearchHit hit = (SearchHit)iter.next(); - String filters = (String)indexCache.getIndexedDocs().get(hit.getHref()); - if (filters == null || !filtersMatch(filters)) { - needReindexingHits.add(hit); - } + ensureIndexUpdated(pm, index); + if (index.exists()) { + index.search(searchQuery, collector); } } /** - * Performs the third and final search pass. This searches for all the - * previously collected potential false hits in the cache. Those found are - * now known to be definite hits, since the cache was updated in pass 2. - * - * @param searchQuery what to search for - * @param definiteHits the definite hits - */ - private void searchPass3(ISearchQuery searchQuery, Collection definiteHits) { - final Collection fDefiniteHits = definiteHits; - ISearchHitCollector collector = new ISearchHitCollector() { - public void addHits(List hits, String wordsSearched) { - fDefiniteHits.addAll(hits); - } - }; - SearchIndexCache indexCache = getIndexCache(searchQuery.getLocale()); - indexCache.search(searchQuery, collector); - } - - /** * Updates index. Checks if all contributions were indexed. If not, it indexes them. * * @throws OperationCanceledException * if indexing was cancelled */ public void ensureIndexUpdated(IProgressMonitor pm, SearchIndexWithIndexingProgress index) - throws OperationCanceledException, IndexingOperation.IndexingException { + throws OperationCanceledException { ProgressDistributor progressDistrib = index.getProgressDistributor(); progressDistrib.addMonitor(pm); @@ -843,24 +613,14 @@ public class LocalSearchManager implements ITocsChangedListener { } } - /** - * @param pm - * @param index - * @param progressDistrib - * @throws IndexingException - */ private synchronized void updateIndex(IProgressMonitor pm, SearchIndex index, - ProgressDistributor progressDistrib) throws IndexingException { + ProgressDistributor progressDistrib) { if (index.isClosed() || !index.needsUpdating()) { pm.beginTask("", 1); //$NON-NLS-1$ pm.worked(1); pm.done(); return; } - if (HelpBasePlugin.DEBUG_SEARCH) { - System.out.println("SearchManager indexing " + index.getLocale()); //$NON-NLS-1$ - } - // Perform indexing try { PluginVersionInfo versions = index.getDocPlugins(); if (versions == null) { @@ -872,14 +632,18 @@ public class LocalSearchManager implements ITocsChangedListener { IndexingOperation indexer = new IndexingOperation(index); indexer.execute(progressDistrib); return; - } catch (OperationCanceledException oce) { + } + catch (OperationCanceledException e) { progressDistrib.operationCanceled(); - HelpBasePlugin.logWarning("Search cancelled."); //$NON-NLS-1$ - throw oce; + throw e; + } + catch (IndexingException e) { + String msg = "Error indexing documents"; //$NON-NLS-1$ + HelpBasePlugin.logError(msg, e); } } - /** + /* * Closes all indexes. */ public void close() { @@ -908,68 +672,4 @@ public class LocalSearchManager implements ITocsChangedListener { } } } - - private void reindex(List hits, String locale) { - SearchIndexCache indexCache = getIndexCache(locale); - if (indexCache.exists()) { - indexCache.beginDeleteBatch(); - Iterator iter = hits.iterator(); - while (iter.hasNext()) { - SearchHit hit = (SearchHit)iter.next(); - indexCache.removeDocument(hit.getHref()); - } - indexCache.endDeleteBatch(); - } - indexCache.beginAddBatch(false); - Iterator iter = hits.iterator(); - while (iter.hasNext()) { - SearchHit hit = (SearchHit)iter.next(); - String filters = hit.getFilters(); - filters = setCurrentValues(filters); - indexCache.addDocument(hit.getHref(), SearchIndex.getIndexableURL(locale, hit.getHref()), filters); - } - indexCache.endAddBatch(true, true); - } - - /** - * Takes in a list of general filters that a document is sensitive to, and inserts - * current specific values, e.g. "os,plugin=my.plugin.id" -> "os=win32,plugin!=my.plugin.id". - * - * For single-value filters (e.g. os, ws, arch), the general form has the filter key, - * and the specific form is "[key]=[current_value]". - * - * For multi-value filters (e.g. plugin), the general form has "[name]=[value]", e.g. - * "plugin=my.plugin.id" which means the document is sensitive to whether or not - * my.plugin.id is present. The specific form is the same except if the plugin is - * not currently there it uses a "!=" instead of "=". - * - * @param filters the general filters, e.g. "os,ws,plugin=my.plugin" - * @return the current specific filters, e.g. "os=win32,ws=win32,plugin!=my.plugin" - */ - private String setCurrentValues(String filters) { - StringBuffer buf = new StringBuffer(); - StringTokenizer tok = new StringTokenizer(filters, ","); //$NON-NLS-1$ - boolean first = true; - while (tok.hasMoreTokens()) { - if (!first) { - buf.append(','); - } - first = false; - String filter = tok.nextToken(); - int index = filter.indexOf('='); - - // multi-value filter, e.g. "plugin=my.plugin.id" (there can be many plugins) - if (index > 0) { - String key = filter.substring(0, index); - String value = filter.substring(index + 1); - boolean isPositive = (XHTMLSupport.getFilterProcessor().isFilteredIn(key, value, true)); - buf.append(key + (isPositive ? "=" : "!=") + value); //$NON-NLS-1$//$NON-NLS-2$ - } - // single-value filter, e.g. "os=win32" (there can only be one OS) - else { - buf.append(filter + '=' + XHTMLSupport.getFilterProcessor().getCurrentValue(filter)); - } - } - return buf.toString(); - } } diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/search/PluginIndex.java b/org.eclipse.help.base/src/org/eclipse/help/internal/search/PluginIndex.java index 8f2ea508a..9273e60e3 100644 --- a/org.eclipse.help.base/src/org/eclipse/help/internal/search/PluginIndex.java +++ b/org.eclipse.help.base/src/org/eclipse/help/internal/search/PluginIndex.java @@ -151,12 +151,6 @@ public class PluginIndex { .getProperty(SearchIndex.DEPENDENCIES_KEY_ANALYZER); if (!targetIndex.isLuceneCompatible(lucene) || !targetIndex.isAnalyzerCompatible(analyzer)) { - if (HelpBasePlugin.DEBUG_SEARCH) { - System.out - .println("Ignoring prebuilt help search index for plugin " //$NON-NLS-1$ - + getPluginId() - + ". Index is not compatible with index in use."); //$NON-NLS-1$ - } return false; } } catch (MalformedURLException mue) { diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchHit.java b/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchHit.java index c9f63143f..b4b369c9d 100644 --- a/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchHit.java +++ b/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchHit.java @@ -27,7 +27,7 @@ public class SearchHit implements ISearchEngineResult2, Comparable { private String summary; private String id; private String participantId; - private String filters; + private boolean isPotentialHit; /** * Constructs a new SearchHit. @@ -39,10 +39,10 @@ public class SearchHit implements ISearchEngineResult2, Comparable { * @param toc the matching element in the TOC * @param id the unique id of the document * @param participantId the participant the hit came from - * @param filters all the filters this doc is sensitive to + * @param isPotentialHit this may be a false positive hit */ public SearchHit(String href, String label, String summary, float score, IToc toc, String id, - String participantId, String filters) { + String participantId, boolean isPotentialHit) { this.href = href; this.label = label; this.score = score; @@ -50,12 +50,9 @@ public class SearchHit implements ISearchEngineResult2, Comparable { this.summary = summary; this.id = id; this.participantId = participantId; - this.filters = filters; + this.isPotentialHit = isPotentialHit; } - /* (non-Javadoc) - * @see java.lang.Comparable#compareTo(java.lang.Object) - */ public int compareTo(Object o) { if (o == this) { return 0; @@ -65,9 +62,6 @@ public class SearchHit implements ISearchEngineResult2, Comparable { return (s1 < s2 ? 1 : s1 > s2 ? -1 : 0); } - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ public boolean equals(Object obj) { if (obj instanceof SearchHit) { if (obj == this) { @@ -78,53 +72,22 @@ public class SearchHit implements ISearchEngineResult2, Comparable { return false; } - /** - * Gets the href. - * - * @return Returns a String - */ public String getHref() { return href; } - /** - * Gets the label. - * - * @return Returns a String - */ public String getLabel() { return label; } - /** - * Gets the score. - * - * @return Returns a float - */ public float getScore() { return score; } - /** - * Gets the toc. - * - * @return Returns IToc or null - */ public IToc getToc() { return toc; } - - /** - * Returns the filters for which this hit's document is sensitive to. - * e.g. "os=linux,ws=gtk,plugin=org.eclipse.help" - */ - public String getFilters() { - return filters; - } - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ public int hashCode() { return href.hashCode(); } @@ -136,15 +99,11 @@ public class SearchHit implements ISearchEngineResult2, Comparable { public void setHref(String href) { this.href = href; } - - /** - * Sets the filters for which this hit's document is sensitive to. - * e.g. "os=linux,ws=gtk,plugin=org.eclipse.help" - */ - public void setFilters(String filters) { - this.filters = filters; - } + public void setPotentialHit(boolean isPotentialHit) { + this.isPotentialHit = isPotentialHit; + } + public void setScore(float score) { this.score = score; } @@ -153,11 +112,6 @@ public class SearchHit implements ISearchEngineResult2, Comparable { this.toc = toc; } - /* - * (non-Javadoc) - * - * @see org.eclipse.help.internal.search.federated.ISearchEngineResult#getDescription() - */ public String getDescription() { return getSummary(); } @@ -172,10 +126,6 @@ public class SearchHit implements ISearchEngineResult2, Comparable { return summary; } - /** - * @param summary - * The summary to set. - */ public void setSummary(String summary) { this.summary = summary; } @@ -209,4 +159,8 @@ public class SearchHit implements ISearchEngineResult2, Comparable { public boolean canOpen() { return participantId != null; } + + public boolean isPotentialHit() { + return isPotentialHit; + } } diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchIndex.java b/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchIndex.java index ecbbcaa54..7101d753d 100644 --- a/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchIndex.java +++ b/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchIndex.java @@ -182,10 +182,6 @@ public class SearchIndex implements ISearchIndex { * @return IStatus */ public IStatus addDocument(String name, URL url) { - if (HelpBasePlugin.DEBUG_SEARCH) { - System.out.println("SearchIndex.addDocument(" + name + ", " + url //$NON-NLS-1$ //$NON-NLS-2$ - + ")"); //$NON-NLS-1$ - } try { Document doc = new Document(); doc.add(Field.Keyword(FIELD_NAME, name)); @@ -319,9 +315,6 @@ public class SearchIndex implements ISearchIndex { * @return IStatus */ public IStatus removeDocument(String name) { - if (HelpBasePlugin.DEBUG_SEARCH) { - System.out.println("SearchIndex.removeDocument(" + name + ")"); //$NON-NLS-1$ //$NON-NLS-2$ - } Term term = new Term(FIELD_NAME, name); try { ir.delete(term); @@ -460,10 +453,6 @@ public class SearchIndex implements ISearchIndex { "Help search indexing directory could not be created for directory " + indexPath, ioe); //$NON-NLS-1$ continue; } - if (HelpBasePlugin.DEBUG_SEARCH) { - System.out - .println("SearchIndex.merge merging indexId=" + indexId + ", indexPath=" + indexPath); //$NON-NLS-1$ //$NON-NLS-2$ - } HelpProperties prebuiltDocs = new HelpProperties(INDEXED_DOCS_FILE, new File(indexPath)); prebuiltDocs.restore(); @@ -512,13 +501,6 @@ public class SearchIndex implements ISearchIndex { } public IStatus removeDuplicates(String name, String[] index_paths) { - if (HelpBasePlugin.DEBUG_SEARCH) { - System.out.print("SearchIndex.removeDuplicates(" + name); //$NON-NLS-1$ - for (int i = 0; i < index_paths.length; i++) { - System.out.print(", " + index_paths[i]); //$NON-NLS-1$ - } - System.out.println(")"); //$NON-NLS-1$ - } TermDocs hrefDocs = null; TermDocs indexDocs = null; Term hrefTerm = new Term(FIELD_NAME, name); @@ -857,10 +839,6 @@ public class SearchIndex implements ISearchIndex { } fos.close(); } - if (HelpBasePlugin.DEBUG_SEARCH) { - System.out.println("SearchIndex: Prebuilt index restored to " //$NON-NLS-1$ - + destDir + "."); //$NON-NLS-1$ - } setInconsistent(false); } catch (IOException ioe) { if (fos != null) { diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchIndexCache.java b/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchIndexCache.java deleted file mode 100644 index 6cc6786d0..000000000 --- a/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchIndexCache.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.help.internal.search; - -import java.io.File; -import java.net.URL; - -import org.apache.lucene.document.Document; -import org.apache.lucene.document.Field; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.help.internal.base.HelpBasePlugin; -import org.eclipse.help.internal.toc.TocManager; - -/** - * A search index used for caching filtered indexed documents. The master index - * documents are indexed unfiltered so there are potential false hits. This index - * is used to reindex those potential false hits (filtered this time) and search - * again. The index is updated as needed. - */ -public class SearchIndexCache extends SearchIndex { - - private String filters; - - /** - * Constructs a new cache index with the given info. The cache index sits - * beside the master index in the file system. - * - * @param locale the locale for this index - * @param analyzerDesc the analyzer to use - * @param tocManager the toc manager to use - */ - public SearchIndexCache(String locale, AnalyzerDescriptor analyzerDesc, TocManager tocManager) { - super(new File(HelpBasePlugin.getConfigurationDirectory(), "indexCache/" + locale), //$NON-NLS-1$ - locale, analyzerDesc, tocManager, null); - } - - /** - * A variant of addDocument() that also takes the current state of filters - * at the time of indexing. - * - * e.g. "os=win32,plugin=org.eclipse.help,plugin=org.eclipse.help.base" - * - * @param name the document name (href in our case) - * @param url the URL to get the content to index - * @param filters the currently active filters - * @return the status of the operation - */ - public IStatus addDocument(String name, URL url, String filters) { - this.filters = filters; - return super.addDocument(name, url); - } - - protected void addExtraFields(Document doc) { - super.addExtraFields(doc); - if (filters != null) { - doc.add(Field.UnIndexed("filters", filters)); //$NON-NLS-1$ - } - } -}
\ No newline at end of file diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchResults.java b/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchResults.java index c6fbdc24c..fdb210444 100644 --- a/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchResults.java +++ b/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchResults.java @@ -107,7 +107,7 @@ public class SearchResults implements ISearchHitCollector { if (urlEncodedWords.length() > 0) { href += "?resultof=" + urlEncodedWords; //$NON-NLS-1$ } - searchHitList.add(new SearchHit(href, label, rawHit.getSummary(), score, toc, rawHit.getRawId(), rawHit.getParticipantId(), rawHit.getFilters())); + searchHitList.add(new SearchHit(href, label, rawHit.getSummary(), score, toc, rawHit.getRawId(), rawHit.getParticipantId(), rawHit.isPotentialHit())); } searchHits = (SearchHit[]) searchHitList .toArray(new SearchHit[searchHitList.size()]); diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/search/XHTMLSearchParticipant.java b/org.eclipse.help.base/src/org/eclipse/help/internal/search/XHTMLSearchParticipant.java index 088d9289c..1e44b5e63 100644 --- a/org.eclipse.help.base/src/org/eclipse/help/internal/search/XHTMLSearchParticipant.java +++ b/org.eclipse.help.base/src/org/eclipse/help/internal/search/XHTMLSearchParticipant.java @@ -15,10 +15,7 @@ import java.io.InputStream; import java.io.Reader; import java.io.StringReader; import java.net.URL; -import java.util.HashSet; import java.util.Hashtable; -import java.util.Iterator; -import java.util.Set; import java.util.Stack; import javax.xml.parsers.SAXParser; @@ -33,7 +30,6 @@ import org.eclipse.core.runtime.Status; import org.eclipse.help.internal.base.HelpBasePlugin; import org.eclipse.help.internal.xhtml.BundleUtil; import org.eclipse.help.internal.xhtml.DynamicXHTMLProcessor; -import org.eclipse.help.internal.xhtml.XHTMLSupport; import org.eclipse.help.search.ISearchIndex; import org.eclipse.help.search.LuceneSearchParticipant; import org.xml.sax.Attributes; @@ -52,7 +48,7 @@ public class XHTMLSearchParticipant extends LuceneSearchParticipant { private Stack stack = new Stack(); private SAXParser parser; - private Set filters; + private boolean hasFilters; /* * Load XHTML dtds from help base plugin location. @@ -145,21 +141,8 @@ public class XHTMLSearchParticipant extends LuceneSearchParticipant { public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { stack.push(qName); - - /* - * Keep track of all the filters this document. e.g., - * "os=macosx", "ws=carbon", ... - */ - String filterAttribute = attributes.getValue("filter"); //$NON-NLS-1$ - if (filterAttribute != null) { - filters.add(filterAttribute); - } - if (qName.equalsIgnoreCase("filter")) { //$NON-NLS-1$ - String name = attributes.getValue("name"); //$NON-NLS-1$ - String value = attributes.getValue("value"); //$NON-NLS-1$ - if (name != null && value != null) { - filters.add(name + '=' + value); - } + if (attributes.getValue("filter") != null || qName.equalsIgnoreCase("filter")) { //$NON-NLS-1$ //$NON-NLS-2$ + hasFilters = true; } } @@ -215,29 +198,28 @@ public class XHTMLSearchParticipant extends LuceneSearchParticipant { */ public IStatus addDocument(ISearchIndex index, String pluginId, String name, URL url, String id, Document doc) { - filters = new HashSet(); InputStream stream = null; try { - if (parser == null) + if (parser == null) { parser = SAXParserFactory.newInstance().newSAXParser(); + } stack.clear(); ParsedXMLContent parsed = new ParsedXMLContent(index.getLocale()); XMLHandler handler = new XMLHandler(parsed); - stream = DynamicXHTMLProcessor.process(name, url.openStream(), index.getLocale(), index instanceof SearchIndexCache); + stream = DynamicXHTMLProcessor.process(name, url.openStream(), index.getLocale(), false); parser.parse(stream, handler); doc.add(Field.Text("contents", parsed.newContentReader())); //$NON-NLS-1$ - doc.add(Field.Text("exact_contents", parsed //$NON-NLS-1$ - .newContentReader())); + doc.add(Field.Text("exact_contents", parsed.newContentReader())); //$NON-NLS-1$ String title = parsed.getTitle(); - if (title != null) + if (title != null) { addTitle(title, doc); + } String summary = parsed.getSummary(); - if (summary != null) + if (summary != null) { doc.add(Field.UnIndexed("summary", summary)); //$NON-NLS-1$ - // store the filters this document is sensitive to - if (doc.getField("filters") == null && filters.size() > 0) { //$NON-NLS-1$ - filters = generalizeFilters(filters); - doc.add(Field.UnIndexed("filters", serializeFilters(filters))); //$NON-NLS-1$ + } + if (hasFilters) { + doc.add(Field.UnIndexed("filters", "true")); //$NON-NLS-1$ //$NON-NLS-2$ } return Status.OK_STATUS; } catch (Exception e) { @@ -291,64 +273,4 @@ public class XHTMLSearchParticipant extends LuceneSearchParticipant { } return buf.toString(); } - - /** - * Given the set of all filters in a document, generalize the filters to - * denote which filters this document is sensitive to. This strips off - * all the environment-specific information. For single value filters like - * os, simply keep the name of the filter. For multi value filters like plugin, - * keep each name and value pair. - * - * e.g., - * before: "os=linux,ws!=gtk,plugin!=org.eclipse.help,product=org.eclipse.sdk" - * after: "os,ws,plugin=org.eclipse.help,product" - * - * @param filters the filters contained in the document - * @return the filters this document is sensitive to in general - */ - private Set generalizeFilters(Set filters) { - Set processed = new HashSet(); - Iterator iter = filters.iterator(); - while (iter.hasNext()) { - String filter = (String)iter.next(); - int index = filter.indexOf('='); - if (index > 0) { - String[] tokens = filter.split("!?="); //$NON-NLS-1$ - String name = tokens[0]; - String value = tokens[1]; - // strip any leading NOT symbols ('!') - if (value != null && value.length() > 0 && value.charAt(0) == '!') { - value = value.substring(1); - } - if (XHTMLSupport.getFilterProcessor().isMultiValue(name)) { - processed.add(name + '=' + value); - } - else { - processed.add(name); - } - } - } - return processed; - } - - /** - * Converts the given set of filters to string form. e.g., - * "os,arch,plugin=org.eclipse.help" - * - * @param set the set of filters to serialize - * @return the serialized string - */ - private String serializeFilters(Set set) { - StringBuffer buf = new StringBuffer(); - Iterator iter = set.iterator(); - boolean firstIter = true; - while (iter.hasNext()) { - if (!firstIter) { - buf.append(','); - } - firstIter = false; - buf.append(iter.next()); - } - return buf.toString(); - } }
\ No newline at end of file diff --git a/org.eclipse.help.base/src/org/eclipse/help/search/XMLSearchParticipant.java b/org.eclipse.help.base/src/org/eclipse/help/search/XMLSearchParticipant.java index 1c207ff99..7c5f2277d 100644 --- a/org.eclipse.help.base/src/org/eclipse/help/search/XMLSearchParticipant.java +++ b/org.eclipse.help.base/src/org/eclipse/help/search/XMLSearchParticipant.java @@ -15,9 +15,6 @@ import java.io.InputStream; import java.io.Reader; import java.io.StringReader; import java.net.URL; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; import java.util.Stack; import javax.xml.parsers.SAXParser; @@ -28,7 +25,6 @@ import org.apache.lucene.document.Field; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.help.internal.base.HelpBasePlugin; -import org.eclipse.help.internal.xhtml.XHTMLSupport; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; @@ -42,7 +38,7 @@ import org.xml.sax.helpers.DefaultHandler; public abstract class XMLSearchParticipant extends LuceneSearchParticipant { private Stack stack = new Stack(); private SAXParser parser; - private Set filters; + private boolean hasFilters; /** * Class that implements this interface is used to store data obtained during the parsing phase. @@ -145,21 +141,8 @@ public abstract class XMLSearchParticipant extends LuceneSearchParticipant { throws SAXException { stack.push(qName); handleStartElement(qName, attributes, data); - - /* - * Keep track of all the filters this document. e.g., - * "os=macosx", "ws=carbon", ... - */ - String filterAttribute = attributes.getValue("filter"); //$NON-NLS-1$ - if (filterAttribute != null) { - filters.add(filterAttribute); - } - if (qName.equalsIgnoreCase("filter")) { //$NON-NLS-1$ - String name = attributes.getValue("name"); //$NON-NLS-1$ - String value = attributes.getValue("value"); //$NON-NLS-1$ - if (name != null && value != null) { - filters.add(name + '=' + value); - } + if (attributes.getValue("filter") != null || qName.equalsIgnoreCase("filter")) { //$NON-NLS-1$ //$NON-NLS-2$ + hasFilters = true; } } @@ -283,7 +266,6 @@ public abstract class XMLSearchParticipant extends LuceneSearchParticipant { */ public IStatus addDocument(ISearchIndex index, String pluginId, String name, URL url, String id, Document doc) { - filters = new HashSet(); InputStream stream = null; try { if (parser == null) @@ -302,10 +284,8 @@ public abstract class XMLSearchParticipant extends LuceneSearchParticipant { String summary = parsed.getSummary(); if (summary != null) doc.add(Field.UnIndexed("summary", summary)); //$NON-NLS-1$ - // store the filters this document is sensitive to - if (doc.getField("filters") == null && filters.size() > 0) { //$NON-NLS-1$ - filters = generalizeFilters(filters); - doc.add(Field.UnIndexed("filters", serializeFilters(filters))); //$NON-NLS-1$ + if (hasFilters) { + doc.add(Field.UnIndexed("filters", "true")); //$NON-NLS-1$ //$NON-NLS-2$ } return Status.OK_STATUS; } catch (Exception e) { @@ -348,58 +328,4 @@ public abstract class XMLSearchParticipant extends LuceneSearchParticipant { } return buf.toString(); } - - /** - * Given the set of all filters in a document, generalize the filters to - * denote which filters this document is sensitive to. This strips off - * all the environment-specific information. For single value filters like - * os, simply keep the name of the filter. For multi value filters like plugin, - * keep each name and value pair. - * - * e.g., - * before: "os=linux,ws=gtk,plugin=org.eclipse.help,product=org.eclipse.sdk" - * after: "os,ws,plugin=org.eclipse.help,product" - * - * @param filters the filters contained in the document - * @return the filters this document is sensitive to in general - */ - private Set generalizeFilters(Set filters) { - Set processed = new HashSet(); - Iterator iter = filters.iterator(); - while (iter.hasNext()) { - String filter = (String)iter.next(); - int index = filter.indexOf('='); - if (index > 0) { - String name = filter.substring(0, index); - if (XHTMLSupport.getFilterProcessor().isMultiValue(name)) { - processed.add(filter); - } - else { - processed.add(name); - } - } - } - return processed; - } - - /** - * Converts the given set of filters to string form. e.g., - * "os,arch,plugin=org.eclipse.help" - * - * @param set the set of filters to serialize - * @return the serialized string - */ - private String serializeFilters(Set set) { - StringBuffer buf = new StringBuffer(); - Iterator iter = set.iterator(); - boolean firstIter = true; - while (iter.hasNext()) { - if (!firstIter) { - buf.append(','); - } - firstIter = false; - buf.append(iter.next()); - } - return buf.toString(); - } }
\ No newline at end of file diff --git a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/preferences/HelpPreferencePage.java b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/preferences/HelpPreferencePage.java index c97fb02d1..217d94a2f 100644 --- a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/preferences/HelpPreferencePage.java +++ b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/preferences/HelpPreferencePage.java @@ -58,10 +58,6 @@ public class HelpPreferencePage extends PreferencePage implements private Button openInEditorButton; - private Button showPotentialHitsButton; - - private Button showActualHitsButton; - /** * Creates preference page controls on demand. * @@ -95,7 +91,6 @@ public class HelpPreferencePage extends PreferencePage implements createSpacer(mainComposite); createDynamicHelpArea(mainComposite); createSpacer(mainComposite); - createSearchArea(mainComposite); Dialog.applyDialogFont(mainComposite); return mainComposite; } @@ -196,25 +191,6 @@ public class HelpPreferencePage extends PreferencePage implements return data; } - private void createSearchArea(Composite parent) { - Group searchGroup = new Group(parent, SWT.NONE); - searchGroup.setText(Messages.HelpPreferencePage_search); - searchGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); - searchGroup.setLayout(new GridLayout()); - - showPotentialHitsButton = new Button(searchGroup, SWT.RADIO); - showPotentialHitsButton.setText(Messages.HelpPreferencePage_searchPotentialHits); - - showActualHitsButton = new Button(searchGroup, SWT.RADIO); - showActualHitsButton.setText(Messages.HelpPreferencePage_searchActualHits); - - boolean showPotentialHits = HelpBasePlugin.getDefault().getPluginPreferences() - .getBoolean(IHelpBaseConstants.P_KEY_SHOW_POTENTIAL_HITS); - - showPotentialHitsButton.setSelection(showPotentialHits); - showActualHitsButton.setSelection(!showPotentialHits); - } - private IPreferenceNode getPreferenceNode(String pageId) { Iterator iterator = PlatformUI.getWorkbench().getPreferenceManager() .getElements(PreferenceManager.PRE_ORDER).iterator(); @@ -266,11 +242,6 @@ public class HelpPreferencePage extends PreferencePage implements openInEditorButton.setSelection(openInEditor); } - boolean showPotentialHits = HelpBasePlugin.getDefault().getPluginPreferences() - .getDefaultBoolean(IHelpBaseConstants.P_KEY_SHOW_POTENTIAL_HITS); - showPotentialHitsButton.setSelection(showPotentialHits); - showActualHitsButton.setSelection(!showPotentialHits); - super.performDefaults(); } @@ -292,8 +263,6 @@ public class HelpPreferencePage extends PreferencePage implements if (openInEditorButton!=null) pref.setValue(IHelpBaseConstants.P_KEY_OPEN_IN_EDITOR, openInEditorButton.getSelection()); - pref.setValue(IHelpBaseConstants.P_KEY_SHOW_POTENTIAL_HITS, - showPotentialHitsButton.getSelection()); HelpBasePlugin.getDefault().savePluginPreferences(); return true; } diff --git a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/views/EngineResultSection.java b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/views/EngineResultSection.java index 1fc38003d..32697a5a8 100644 --- a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/views/EngineResultSection.java +++ b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/views/EngineResultSection.java @@ -18,7 +18,6 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.help.IHelpResource; import org.eclipse.help.internal.base.BaseHelpSystem; import org.eclipse.help.internal.base.HelpBasePlugin; -import org.eclipse.help.internal.base.IHelpBaseConstants; import org.eclipse.help.internal.search.SearchHit; import org.eclipse.help.search.ISearchEngineResult; import org.eclipse.help.search.ISearchEngineResult2; @@ -335,10 +334,6 @@ public class EngineResultSection { StringBuffer buff = new StringBuffer(); buff.append("<form>"); //$NON-NLS-1$ IHelpResource oldCat = null; - // boolean earlyExit = false; - - boolean showPotentialHits = HelpBasePlugin.getDefault().getPluginPreferences() - .getBoolean(IHelpBaseConstants.P_KEY_SHOW_POTENTIAL_HITS); for (int i = resultOffset; i < results.length; i++) { if (i - resultOffset == HITS_PER_PAGE) { @@ -368,7 +363,7 @@ public class EngineResultSection { int bindent = part.getShowCategories() && cat != null ? 5 : 0; buff.append("<li indent=\"" + indent + "\" bindent=\"" + bindent + "\" style=\"image\" value=\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ String imageId = desc.getId(); - boolean isPotentialHit = (showPotentialHits && hit instanceof SearchHit && ((SearchHit)hit).getFilters() != null); + boolean isPotentialHit = (hit instanceof SearchHit && ((SearchHit)hit).isPotentialHit()); if (hit instanceof ISearchEngineResult2) { URL iconURL = ((ISearchEngineResult2) hit).getIconURL(); if (iconURL != null) { diff --git a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/data/SearchData.java b/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/data/SearchData.java index 3f3871488..ec93562e7 100644 --- a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/data/SearchData.java +++ b/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/data/SearchData.java @@ -19,7 +19,6 @@ import javax.servlet.http.HttpServletResponse; import org.eclipse.help.internal.HelpPlugin; import org.eclipse.help.internal.base.BaseHelpSystem; import org.eclipse.help.internal.base.HelpBasePlugin; -import org.eclipse.help.internal.base.IHelpBaseConstants; import org.eclipse.help.internal.search.ISearchQuery; import org.eclipse.help.internal.search.QueryTooComplexException; import org.eclipse.help.internal.search.SearchHit; @@ -54,8 +53,6 @@ public class SearchData extends ActivitiesData { // QueryException if any private QueryTooComplexException queryException = null; - - private boolean showPotentialHits; /** * Constructs the xml data for the search resuls page. @@ -89,9 +86,6 @@ public class SearchData extends ActivitiesData { } } } - - showPotentialHits = HelpBasePlugin.getDefault().getPluginPreferences() - .getBoolean(IHelpBaseConstants.P_KEY_SHOW_POTENTIAL_HITS); } /** @@ -167,7 +161,7 @@ public class SearchData extends ActivitiesData { * @return whether or not the hit is a potential hit */ public boolean isPotentialHit(int i) { - return (showPotentialHits && (getMode() != MODE_INFOCENTER) && hits[i].getFilters() != null); + return ((getMode() != MODE_INFOCENTER) && hits[i].isPotentialHit()); } /** diff --git a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/SearchSerializer.java b/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/SearchSerializer.java index fbc78058a..d044bcd5e 100644 --- a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/SearchSerializer.java +++ b/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/SearchSerializer.java @@ -42,8 +42,8 @@ public class SearchSerializer { if (hit.getLabel() != null) { buf.append('\n' + indent + " label=\"" + XMLGenerator.xmlEscape(hit.getLabel()) + '"'); //$NON-NLS-1$ } - if (hit.getFilters() != null) { - buf.append('\n' + indent + " filters=\"" + XMLGenerator.xmlEscape(hit.getFilters()) + '"'); //$NON-NLS-1$ + if (hit.isPotentialHit()) { + buf.append('\n' + indent + " isPotentialHit=\"true\""); //$NON-NLS-1$ } buf.append('\n' + indent + " score=\"" + hit.getScore() + '"'); //$NON-NLS-1$ buf.append(">\n"); //$NON-NLS-1$ diff --git a/org.eclipse.ua.tests/data/help/search/test1.xhtml b/org.eclipse.ua.tests/data/help/search/test1.xhtml index d52fe3277..62f5145a2 100644 --- a/org.eclipse.ua.tests/data/help/search/test1.xhtml +++ b/org.eclipse.ua.tests/data/help/search/test1.xhtml @@ -13,7 +13,7 @@ to search for as part of this test: jehcyqpfjs vkrhjewiwh </p> <p filter="os=invalid"> -This paragraph is always filtered out, and is used to ensure that searching does not +This paragraph is always filtered out, and is used to test whether search will flag this document as a hit. Here is a unique word to search for: gsdduvfqnh vkrhjewiwh riehguanil </p> diff --git a/org.eclipse.ua.tests/data/help/search/test7.html b/org.eclipse.ua.tests/data/help/search/test7.html index b634fb857..f63e756b4 100644 --- a/org.eclipse.ua.tests/data/help/search/test7.html +++ b/org.eclipse.ua.tests/data/help/search/test7.html @@ -14,8 +14,8 @@ kejehrgaqm </p> <p filter="os=invalid"> -This paragraph is always filtered out, and is used to ensure that searching does not -flag this document as a hit. Here is a unique word to search for: hugftnhdtg +This paragraph is always filtered out, but search should still find it. Here is +a unique word to search for: hugftnhdtg </p> <p filter="plugin!=my.invalid.plugin.id.012345"> This paragraph, which has filter attribute "plugin!=my.invalid.plugin.id.012345" should never be filtered out. diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/BasicTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/BasicTest.java index aa9f140ca..eed5845c0 100644 --- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/BasicTest.java +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/BasicTest.java @@ -23,22 +23,14 @@ import junit.framework.TestSuite; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Preferences; import org.eclipse.help.internal.base.BaseHelpSystem; -import org.eclipse.help.internal.base.HelpBasePlugin; -import org.eclipse.help.internal.base.IHelpBaseConstants; import org.eclipse.help.internal.search.ISearchQuery; import org.eclipse.help.internal.search.SearchHit; import org.eclipse.help.internal.search.SearchQuery; import org.eclipse.help.internal.search.SearchResults; -import org.eclipse.help.ui.internal.HelpUIPlugin; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.activities.IWorkbenchActivitySupport; public class BasicTest extends TestCase { - private boolean oldPreference; - /* * The test data for testXHTMLSearch(). The first string in each array * is the word to search for. The rest are the expected hits' hrefs. @@ -56,14 +48,14 @@ public class BasicTest extends TestCase { // try OR'ing with a string from another doc.. should find both { "vkrhjewiwh OR rugnwjfyqj", "/org.eclipse.ua.tests/data/help/search/test1.xhtml", "/org.eclipse.ua.tests/data/help/search/test2.xhtml" }, - // these two words only appear next to each other in a paragraph that's always filtered out - { "\"vkrhjewiwh riehguanil\"", /* no hits */ }, + // these two words only appear next to each other in a paragraph that's filtered out - search should still find it + { "\"vkrhjewiwh riehguanil\"", "/org.eclipse.ua.tests/data/help/search/test1.xhtml" }, - // first one should be found, but second one only exists in a paragraph that's always filtered out - { "vkrhjewiwh AND riehguanil", /* no hits */ }, + // first one should be found, but second one only exists in a paragraph that's filtered out - search should still find + { "vkrhjewiwh AND riehguanil", "/org.eclipse.ua.tests/data/help/search/test1.xhtml" }, - // only exists in paragraph that's always filtered out - { "gsdduvfqnh", /* no hits */ }, + // only exists in paragraph that's filtered out - search should find + { "gsdduvfqnh", "/org.eclipse.ua.tests/data/help/search/test1.xhtml" }, // word is in test3.xhtml and also included by test4.xhtml, contributed // into test5.xhtml as an extension, and replaces a paragraph in test6.xhtml. @@ -80,7 +72,7 @@ public class BasicTest extends TestCase { // only exists in a paragraph in test7.html that should be filtered out // make sure this works for XHTML content inside .html file - { "hugftnhdtg", /* no hits */ }, + { "hugftnhdtg", "/org.eclipse.ua.tests/data/help/search/test7.html" }, // this doc is listed in TOC several times, using slightly different paths { "rqfedajhtg", "/org.eclipse.ua.tests/data/help/search/test9.htm" }, @@ -93,30 +85,6 @@ public class BasicTest extends TestCase { return new TestSuite(BasicTest.class); } - /* - * Ensure that org.eclipse.help.ui is started. It contributes extra content - * filtering that is used by this test. See UIContentFilterProcessor. - * - * Also, turn off potential hits searching for this test. - */ - protected void setUp() throws Exception { - HelpUIPlugin.getDefault(); - - Preferences pref = HelpBasePlugin.getDefault().getPluginPreferences(); - oldPreference = pref.getBoolean(IHelpBaseConstants.P_KEY_SHOW_POTENTIAL_HITS); - pref.setValue(IHelpBaseConstants.P_KEY_SHOW_POTENTIAL_HITS, false); - HelpBasePlugin.getDefault().savePluginPreferences(); - } - - /* - * Set the preference value back to whatever it was before. - */ - protected void tearDown() throws Exception { - Preferences pref = HelpBasePlugin.getDefault().getPluginPreferences(); - pref.setValue(IHelpBaseConstants.P_KEY_SHOW_POTENTIAL_HITS, oldPreference); - HelpBasePlugin.getDefault().savePluginPreferences(); - } - public void testSearch() throws Exception { for (int i=0;i<EXPECTED_RESULTS.length;++i) { String searchWord = EXPECTED_RESULTS[i][0]; @@ -172,53 +140,4 @@ public class BasicTest extends TestCase { } } } - - /** - * Tests searching with changing filtering conditions. Activities, for - * example, can change during a session, and the search should only - * find content that is *currently* not filtered out. - */ - public void testXHTMLActivityFilteringSearch() throws Exception { - String searchWord = "qjfuhemaok"; - String href = "/org.eclipse.ua.tests/data/help/search/test2.xhtml"; - String testActivity = "org.eclipse.ua.tests.activity"; - ISearchQuery query = new SearchQuery(searchWord, false, new ArrayList(), Platform.getNL()); - IWorkbenchActivitySupport activitySupport = PlatformUI.getWorkbench().getActivitySupport(); - Set withoutTestActivity = activitySupport.getActivityManager().getEnabledActivityIds(); - Set withTestActivity = new HashSet(withoutTestActivity); - withTestActivity.add(testActivity); - - // first try with activity turned off - should not find it - activitySupport.setEnabledActivityIds(withoutTestActivity); - SearchResults collector = new SearchResults(null, 500, Platform.getNL()); - BaseHelpSystem.getSearchManager().search(query, collector, new NullProgressMonitor()); - Assert.assertTrue("Found an unexpected search result. Was searching for string in a paragraph filtered by activity, and the activity was turned off, but the search came back positive", !containsHref(href, collector.getSearchHits())); - - // now try with it turned on - should find it - activitySupport.setEnabledActivityIds(withTestActivity); - collector = new SearchResults(null, 500, Platform.getNL()); - BaseHelpSystem.getSearchManager().search(query, collector, new NullProgressMonitor()); - Assert.assertTrue("Did not find an expected search result. Was searching for string in a paragraph filtered by activity, and the activity was turned on, but the search came back negative", containsHref(href, collector.getSearchHits())); - - // finally try again with it turned off - should not find it - activitySupport.setEnabledActivityIds(withoutTestActivity); - collector = new SearchResults(null, 500, Platform.getNL()); - BaseHelpSystem.getSearchManager().search(query, collector, new NullProgressMonitor()); - Assert.assertTrue("Found an unexpected search result. Was searching for string in a paragraph filtered by activity, and the activity was turned off, but the search came back positive (second attempt)", !containsHref(href, collector.getSearchHits())); - } - - private static boolean containsHref(String href, SearchHit[] hits) { - for (int i=0;i<hits.length;++i) { - String hitHref = hits[i].getHref(); - // ignore query params - int index = hitHref.indexOf('?'); - if (index != -1) { - hitHref = hitHref.substring(0, index); - } - if (href.equals(hitHref)) { - return true; - } - } - return false; - } } |