Creating your own Search plugin
You can create your own Search plugin.
Conditions:
- The new NodeSearch class must implement the “NodeSearch” interface.
- The new NodeSearch class must be created in the package “com.openkm.plugin.search”.
- The new NodeSearch class must be annotated with “@PluginImplementation”.
- The new NodeSearch class must extend “BasePlugin”.
NodeSearch interface:
package com.openkm.plugin.search;
import com.openkm.bean.NodeSearchConfig;import com.openkm.core.AccessDeniedException;import com.openkm.core.DatabaseException;import com.openkm.core.ParseException;import com.openkm.core.RepositoryException;import com.openkm.db.bean.QueryParams;import com.openkm.ws.rest.util.SimpleNodeBaseResultSet;import net.xeoh.plugins.base.Plugin;
import java.io.IOException;
/** * Node Search */public interface NodeSearch extends Plugin { SimpleNodeBaseResultSet findSimpleNodeBasePaginated(QueryParams params, int offset, int limit) throws AccessDeniedException, RepositoryException, IOException, ParseException, DatabaseException;
NodeSearchConfig getConfig() throws DatabaseException;
String getName();}The new class must be created in the com.openkm.plugin.search package because the plugin system will try to load it from there.
Method description
Section titled “Method description”| Method | Type | Description |
|---|---|---|
| findSimpleNodeBasePaginated(QueryParams params, int offset, int limit) | SimpleNodeBaseResultSet | Perform a search based on the query parameters. The offset and limit values set the range of the results. |
| getConfig() | NodeSearchConfig | Used to set visible search fields. By default, all the search fields are hidden. |
| getName() | String | The name of the plugin. |
Example
Section titled “Example”TestNodeSearch class:
package com.openkm.plugin.search;
import com.openkm.bean.NodeSearchConfig;import com.openkm.core.AccessDeniedException;import com.openkm.core.DatabaseException;import com.openkm.core.ParseException;import com.openkm.core.RepositoryException;import com.openkm.db.bean.QueryParams;import com.openkm.module.db.DbSearchModule;import com.openkm.plugin.BasePlugin;import com.openkm.ws.rest.util.SimpleNodeBaseResultSet;import net.xeoh.plugins.base.annotations.PluginImplementation;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.beans.factory.annotation.Autowired;
import java.io.IOException;
@PluginImplementationpublic class TestNodeSearch extends BasePlugin implements NodeSearch { private static final Logger log = LoggerFactory.getLogger(TestNodeSearch.class);
@Autowired private DbSearchModule dbSearchModule;
@Override public SimpleNodeBaseResultSet findSimpleNodeBasePaginated(QueryParams params, int offset, int limit) throws AccessDeniedException, RepositoryException, IOException, ParseException, DatabaseException { return dbSearchModule.findSimpleNodeBasePaginated(null, params, offset, limit); }
@Override public NodeSearchConfig getConfig() throws DatabaseException { NodeSearchConfig nsc = new NodeSearchConfig(); nsc.setTabBasicVisible(true); nsc.setSaveSearchVisible(true); nsc.setContextVisible(true); nsc.setContentVisible(true); nsc.setNameVisible(true); nsc.setDateVisible(true); return nsc; }
@Override public String getName() { return "Test search sample"; }}