Creating your own Search plugin

NodePaginator is used to customize the file browser columns shown, including metadata columns.

You can create your own NodePaginator.

Conditions:

  • The new NodePaginator class must implement the "NodeSearch" interface.
  • The new NodePaginator class must be created under 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 into com.openkm.plugin.search package because the plugin system will try to load it from there.

Do not miss the tag @PluginImplementation otherwise, the plugin system will not be able to detect the new class.

More information about Register a new plugin.

Method description

MethodTypeDescription

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

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";
	}
}
Table of contents [ Hide Show ]