Skip to content
Other versions

Loading…

Creating your own Search plugin

You can create your own NodePaginator.

Conditions:

  • The new NodePaginator class must implement the “NodeSearch” interface.
  • The new NodePaginator class must be created in the package “com.openkm.plugin.search”.
  • The new NodePaginator class must be annotated with “@PluginImplementation”.
  • The new NodePaginator class must extend “BasePlugin”.

NodePaginator 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 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.

TestNodeSearch class:

ackage 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;
@PluginImplementation
public 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";
}
}