Thursday 12 May 2016

Retrieving Documents and properties based on Content Based Retrieval(CBR)

//Retrieving Documents and properties based on Content Based Retrieval(CBR)

//content-based document searching

import java.util.Iterator;
import javax.security.auth.Subject;

import com.filenet.api.collection.DocumentSet;
import com.filenet.api.core.Connection;
import com.filenet.api.core.Document;
import com.filenet.api.core.Domain;
import com.filenet.api.core.Factory;
import com.filenet.api.core.ObjectStore;
import com.filenet.api.query.SearchSQL;
import com.filenet.api.query.SearchScope;
import com.filenet.api.util.UserContext;

public class ceUtil {

public static void main(String[] args) {
ceUtil obj = new ceUtil();
obj.FetchCEObjects(obj.getCEConnection());


}

public Connection getCEConnection() {

Connection conn = null;
try {

String ceURI = "http://localhost:9080/wsi/FNCEWS40MTOM/";

String userName = "userName";
String password = "password";
conn = Factory.Connection.getConnection(ceURI);
Subject subject = UserContext.createSubject(conn, userName,
password, null);
UserContext uc = UserContext.get();
uc.pushSubject(subject);
} catch (Exception e1) {
e1.printStackTrace();
}
System.out.println("CE Connection" + conn);
return conn;
}

public void FetchCEObjects(Connection conn) {
try {
Domain domain = Factory.Domain.fetchInstance(conn, null, null);
ObjectStore objStore = Factory.ObjectStore.fetchInstance(domain,"OSNAME", null);

SearchScope search = new SearchScope(objStore);
String keyWord = "keyword in attachment";

String mySQLString= "SELECT d.this, DocumentTitle,Name FROM docClass d INNER JOIN ContentSearch v ON v.QueriedObject= d.This WHERE d.IsCurrentVersion= TRUE AND CONTAINS(d.*,'" + keyWord+ "')";
SearchSQL sql= new SearchSQL(mySQLString); 
DocumentSet documents = (DocumentSet) search.fetchObjects(sql,Integer.valueOf("50"),null, Boolean.valueOf(true));
com.filenet.api.core.Document doc; 

Iterator it = documents.iterator();
while (it.hasNext())
{
doc = (Document)it.next();
System.out.println("document="+doc.get_Name());
}

} catch (Exception e) {
e.printStackTrace();
}
}

}


/*
Additinal Queries for Content Based search

SELECT d.This, DocumentTitle, Name FROM docClass d INNER JOIN VerityContentSearch v ON v.QueriedObject= d.This WHERE d.IsCurrentVersion= TRUE AND CONTAINS(d.*,'model <SENTENCE> Deluxe')
//Search for documents that contain the two key words in a sentence (use with <SENTENCE>).

SELECT d.This, DocumentTitle, Name FROM docClass d INNER JOIN VerityContentSearch v ON v.QueriedObject= d.This WHERE d.IsCurrentVersion= TRUE AND CONTAINS(d.*, 'tested <NEAR/25> passed')
//Search for documents that contain the two key words located close to each other (use with <NEAR>)
*/

*******************************************************************************

//Sample code for retrieving the properties based on CBR

RepositoryRowSet rowSet= search.fetchRows(sql, Integer.valueOf("50"),null,Boolean.valueOf(true));
Iterator itRow= rowSet.iterator();
RepositoryRow row; 
com.filenet.api.property.Properties props; 
com.filenet.api.property.Property prop; 
while (itRow.hasNext()) 
{
row = (RepositoryRow)itRow.next();
props = row.getProperties(); 
Iterator itProp= props.iterator(); 
while (itProp.hasNext())
{
prop =(com.filenet.api.property.Property) itProp.next();
if(prop.getPropertyName().equalsIgnoreCase("Rank"))
{
System.out.println(prop.getPropertyName() +" = " + prop.getFloat64Value().toString());
else
System.out.println(prop.getPropertyName()+" = " + prop.getStringValue());
}
}
}

No comments:

Post a Comment