View Source

This feature allows users to create their own Document Repository module, thus integrating their preferred indexing/storage engine or change document repository behavior with their own.

There are several steps to load and use custom document repository.

h2. Create a class implementing the {{DocumentRepositoryAPI}} interface.

This will be the object, providing all functionality for adding, retrieving and removing documents, index management and search.

Example:

{code:title=MyDocumentRepository.java|borderStyle=solid}
package my.package.name;

import java.util.Map;
import java.util.Set;

import com.ontotext.kim.client.corpora.KIMDocument;
import com.ontotext.kim.client.documentrepository.DocumentQuery;
import com.ontotext.kim.client.documentrepository.DocumentRepositoryAPI;
import com.ontotext.kim.client.documentrepository.DocumentRepositoryException;
import com.ontotext.kim.client.query.DocumentQueryResult;
import com.ontotext.kim.client.query.KIMQueryException;

public class MyDocumentRepository implements DocumentRepositoryAPI{

@Override
public void addDocument(KIMDocument doc) throws DocumentRepositoryException {
// TODO Auto-generated method stub

}

// Various methods to @Override here
// ...
// ...

@Override
public DocumentQueryResult getDocumentIds(DocumentQuery query) throws KIMQueryException {
// TODO Auto-generated method stub
return null;
}
}

{code}

h2. Create a class that will initialize and return your document repository object

This class must implement the {{CustomDocumentRepositoryImplementation}} interface. The interface provides two methods:
* {{init(FeatureSchema fSchema)}} - initializes your document repository
* {{getDocumentRepositoryInstance()}} - returns the initialized {{DocumentRepositoryAPI}} object

All implementing classes must have a constructor without parameters in order to be dynamically loaded using reflection. After the new object is created, the {{init(...)}} method is called. Developers can put various code there, as well as in the {{getDocumentRepositoryInstance()}} method, which would return the object to serve as {{DocumentRepositoryAPI}}.

Example:

{code:title=MyDocumentRepositoryLoader.java|borderStyle=solid}

package my.package.name;

import com.ontotext.kim.client.documentrepository.CustomDocumentRepositoryImplementation;
import com.ontotext.kim.client.documentrepository.DocumentRepositoryAPI;
import com.ontotext.kim.client.documentrepository.DocumentRepositoryException;
import com.ontotext.kim.client.documentrepository.FeatureSchema;

public class MyDocumentRepositoryImplementationLoader implements CustomDocumentRepositoryImplementation {

private FeatureSchema featureSchema;

@Override
public DocumentRepositoryAPI getDocumentRepositoryInstance() throws DocumentRepositoryException {

MyDocumentRepository documentRepository = new MyDocumentRepository();
documentRepository.setFeatureSchema(this.featureSchema);

return documentRepository;
}

@Override
public void init(FeatureSchema featureSchema) {
this.featureSchema = featureSchema;

}
}
{code}

h2. Configure KIM to use the custom {{DocumentRepositoryAPI}} object

In order to load the custom {{DocumentRepositoryAPI}} object, one should:
* pack the custom code as a jar library and add it to KIM classpath (put the *.jar* file in the *<KIM_HOME/lib* directory)
* update the corresponding configuration options in *<KIM_HOME/config/document.repository.properties>*

{code}
com.ontotext.kim.KIMConstants.DOCUMENT_REPOSITORY_TYPE = other
com.ontotext.kim.KIMConstants.CUSTOM_DOC_REPOSITORY_CLASS_NAME = my.package.name.MyDocumentRepositoryLoader
{code}

Parameter {{com.ontotext.kim.KIMConstants.DOCUMENT_REPOSITORY_TYPE}} should be set to {{other}} while parameter {{com.ontotext.kim.KIMConstants.CUSTOM_DOC_REPOSITORY_CLASS_NAME}} should point to the class implementing the {{CustomDocumentRepositoryImplementation}} interface.