IBM Content Navigator:如何配置搜索功能打开时自动执行搜索?
Great question! Unfortunately, IBM Content Navigator (ICN) doesn’t have a built-in configuration option to auto-execute a search when the user selects the search feature. As the forum discussion noted, you’ll need to build a custom plugin to make this work. Below’s a practical, step-by-step implementation guide:
1. Set Up Your ICN Plugin Project
First, use the ICN Plugin Development Kit (PDK) to create a new plugin project. You’ll need two core files:
plugin.xml: Defines the plugin’s metadata and extensionsplugin.js: Contains the logic to trigger auto-search
2. Define the Plugin Metadata (plugin.xml)
This file registers your plugin with ICN and links to your custom logic. Here’s a minimal example:
<?xml version="1.0" encoding="UTF-8"?> <plugin id="com.yourorg.plugins.AutoSearchPlugin" name="Auto Search Trigger Plugin" version="1.0.0" provider="Your Organization"> <description>Automatically runs a search when the user opens the ICN search feature</description> <requires> <product name="IBM Content Navigator" version="3.0.0" /> <!-- Adjust to your ICN version --> </requires> <components> <component id="AutoSearchLogic" type="configurationPane" class="com.yourorg.plugins.AutoSearchPlugin"> <description>Holds auto-search trigger logic</description> </component> </components> <extensions> <extension point="ecm.configurationPane" id="AutoSearchConfig"> <configurationPane id="com.yourorg.plugins.AutoSearchPlugin" name="Auto Search Settings" /> </extension> </extensions> </plugin>
3. Implement the Auto-Search Logic (plugin.js)
This code listens for when the search feature is activated (either when the search pane loads or when the user switches to the search view) and triggers a search automatically. We’ll use ICN’s Dojo-based API to hook into these events:
define([ "dojo/_base/declare", "ecm/widget/admin/PluginConfigurationPane", "dojo/_base/lang", "dojo/on", "ecm/widget/search/SearchPane" ], function( declare, PluginConfigurationPane, lang, on, SearchPane ) { return declare("com.yourorg.plugins.AutoSearchPlugin", [PluginConfigurationPane], { postCreate: function() { this.inherited(arguments); // Listen for when the search pane is first created on(ecm.model.desktop, "searchPaneCreated", lang.hitch(this, function(searchPane) { this._runAutoSearch(searchPane); })); // Also listen for view switches (in case the user navigates back to search later) on(ecm.model.desktop, "currentViewChanged", lang.hitch(this, function(newView) { if (newView?.id === "search") { const activeSearchPane = ecm.model.desktop.getSearchPane(); if (activeSearchPane) this._runAutoSearch(activeSearchPane); } })); }, _runAutoSearch: function(searchPane) { const currentQuery = searchPane.searchQuery; // Option 1: Run the last saved search query if (!currentQuery.isEmpty()) { searchPane.executeSearch(); } // Option 2: Run a default preset search (customize this to your needs) else { currentQuery.setQuery("*:*"); // Search all content currentQuery.setSearchScope("ALL"); // Search all repositories/classes searchPane.executeSearch(); } }, // Required configuration pane methods (can leave empty if no admin settings are needed) load: function(callback) { callback(); }, save: function(callback) { callback(); } }); });
4. Deploy and Test the Plugin
- Package your plugin into a ZIP file (include
plugin.xml,plugin.js, and any assets like icons if you added them) - Log into the ICN Admin Console → go to Plugins → Load Plugin and upload your ZIP
- Enable the plugin and assign it to your target desktop configuration
- Restart the ICN application server
- Test it: When you switch to the search view, the plugin should automatically trigger a search (either using the last query or your default preset)
Customization Tips
- Add an admin configuration panel to let users set default search queries/scopes instead of hardcoding them
- Adjust the trigger condition (e.g., only run auto-search once per session, or only if a specific repository is selected)
- Verify compatibility with your ICN version (some API methods may differ between 3.x and 4.x)
内容的提问来源于stack exchange,提问作者Denis Milovanov

