This method will allows to search the Alfresco document repository by content in the document.
returen the result
/**
* Alfresco Document search by Content.
* @param alfrescoSearchVO
*/
public List<String> searchByContent(AlfrescoSearchVO alfrescoSearchVO) {
LOGGER.entering("searchByContent");
List<String> documentList = null;
try {
initiate();
RepositoryServiceSoapBindingStub repositoryService = alfrescoServices
.getRepositoryService();
Query query = new Query(Constants.QUERY_LANG_LUCENE,
DOCUMENT_SEARCH_PATH1
+ " AND TEXT:(\""+ alfrescoSearchVO.getText() +"\")");
QueryResult queryResult = repositoryService.query(STORE, query, false);
ResultSet resultSet = queryResult.getResultSet();
ResultSetRow[] rows = resultSet.getRows();
if (rows == null) {
System.out.println("No query results found.");
if (alfrescoSearchVO.getText().trim().contains(" ")) {
String textArray[] = alfrescoSearchVO.getText().split(" ");
StringBuffer queryBuffer = new StringBuffer();
queryBuffer.append(" AND (");
for (int i=0; i<textArray.length; i++) {
if (i == 0) {
queryBuffer.append(
" TEXT:\""+ textArray[i].trim() +"\"");
} else {
queryBuffer.append(
" OR TEXT:\""+ textArray[i].trim() +"\"");
}
}
queryBuffer.append(" )");
if (queryBuffer.toString().length() > 0) {
System.out.println("Query :" + queryBuffer.toString());
query = new Query(Constants.QUERY_LANG_LUCENE,
DOCUMENT_SEARCH_PATH
+ queryBuffer.toString());
queryResult = repositoryService.query(STORE, query, false);
resultSet = queryResult.getResultSet();
rows = resultSet.getRows();
if (rows != null) {
documentList = iterateQueryResultSet(rows);
} else {
System.out.println("Final No query results found.");
}
}
}
} else {
documentList = iterateQueryResultSet(rows);
}
alfrescoServices.endSession();
} catch (Exception exception) {
exception.printStackTrace();
}
LOGGER.exiting("searchByContent");
return documentList;
}
/**
* The result will be iterate to content the document information.
* @param rows
*/
public List<String> iterateQueryResultSet(ResultSetRow[] rows){
LOGGER.entering("iterateQueryResultSet");
List<String> documentList = new ArrayList<String>();
try {
for (ResultSetRow row : rows) {
System.out.println("UID: " + row.getNode().getId());
System.out.println("Type: " + row.getNode().getType());
NamedValue[] values = row.getColumns();
System.out.println("Properties: ");
for (NamedValue col : values) {
/*if (col.getName().endsWith("title") || col.getName().endsWith("path")) {
System.out.println("\tName: " + col.getName());
System.out.println("\tValue: " + col.getValue());
System.out.println("------------------------");
}*/
if (col.getName().endsWith("path")) {
System.out.println("\tName: " + col.getName());
System.out.println("\tValue: " + col.getValue());
String path = col.getValue();
path = path.replace("/{http://www.alfresco.org/model/application/1.0}", "/app:");
path = path.replace("/{http://www.alfresco.org/model/site/1.0}", "/st:");
path = path.replace("/{http://www.alfresco.org/model/content/1.0}", "/cm:");
System.out.println("------------------------");
System.out.println("path:" + path);
documentList.add(path);
}
/*System.out.println("\tName: " + col.getName());
System.out.println("\tValue: " + col.getValue());*/
}
}
} catch (Exception exception) {
exception.printStackTrace();
}
LOGGER.exiting("iterateQueryResultSet");
return documentList;
}
/*Alfresco serach vo*/
public class AlfrescoSearchVO {
private String name;
private String title;
private String text;
private String author;
private String modifier;
private String creator;
private String contentType;
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the title
*/
public String getTitle() {
return title;
}
/**
* @param title the title to set
*/
public void setTitle(String title) {
this.title = title;
}
/**
* @return the text
*/
public String getText() {
return text;
}
/**
* @param text the text to set
*/
public void setText(String text) {
this.text = text;
}
/**
* @return the author
*/
public String getAuthor() {
return author;
}
/**
* @param author the author to set
*/
public void setAuthor(String author) {
this.author = author;
}
/**
* @return the modifier
*/
public String getModifier() {
return modifier;
}
/**
* @param modifier the modifier to set
*/
public void setModifier(String modifier) {
this.modifier = modifier;
}
/**
* @return the creator
*/
public String getCreator() {
return creator;
}
/**
* @param creator the creator to set
*/
public void setCreator(String creator) {
this.creator = creator;
}
/**
* @return the contentType
*/
public String getContentType() {
return contentType;
}
/**
* @param contentType the contentType to set
*/
public void setContentType(String contentType) {
this.contentType = contentType;
}
}
returen the result
/**
* Alfresco Document search by Content.
* @param alfrescoSearchVO
*/
public List<String> searchByContent(AlfrescoSearchVO alfrescoSearchVO) {
LOGGER.entering("searchByContent");
List<String> documentList = null;
try {
initiate();
RepositoryServiceSoapBindingStub repositoryService = alfrescoServices
.getRepositoryService();
Query query = new Query(Constants.QUERY_LANG_LUCENE,
DOCUMENT_SEARCH_PATH1
+ " AND TEXT:(\""+ alfrescoSearchVO.getText() +"\")");
QueryResult queryResult = repositoryService.query(STORE, query, false);
ResultSet resultSet = queryResult.getResultSet();
ResultSetRow[] rows = resultSet.getRows();
if (rows == null) {
System.out.println("No query results found.");
if (alfrescoSearchVO.getText().trim().contains(" ")) {
String textArray[] = alfrescoSearchVO.getText().split(" ");
StringBuffer queryBuffer = new StringBuffer();
queryBuffer.append(" AND (");
for (int i=0; i<textArray.length; i++) {
if (i == 0) {
queryBuffer.append(
" TEXT:\""+ textArray[i].trim() +"\"");
} else {
queryBuffer.append(
" OR TEXT:\""+ textArray[i].trim() +"\"");
}
}
queryBuffer.append(" )");
if (queryBuffer.toString().length() > 0) {
System.out.println("Query :" + queryBuffer.toString());
query = new Query(Constants.QUERY_LANG_LUCENE,
DOCUMENT_SEARCH_PATH
+ queryBuffer.toString());
queryResult = repositoryService.query(STORE, query, false);
resultSet = queryResult.getResultSet();
rows = resultSet.getRows();
if (rows != null) {
documentList = iterateQueryResultSet(rows);
} else {
System.out.println("Final No query results found.");
}
}
}
} else {
documentList = iterateQueryResultSet(rows);
}
alfrescoServices.endSession();
} catch (Exception exception) {
exception.printStackTrace();
}
LOGGER.exiting("searchByContent");
return documentList;
}
/**
* The result will be iterate to content the document information.
* @param rows
*/
public List<String> iterateQueryResultSet(ResultSetRow[] rows){
LOGGER.entering("iterateQueryResultSet");
List<String> documentList = new ArrayList<String>();
try {
for (ResultSetRow row : rows) {
System.out.println("UID: " + row.getNode().getId());
System.out.println("Type: " + row.getNode().getType());
NamedValue[] values = row.getColumns();
System.out.println("Properties: ");
for (NamedValue col : values) {
/*if (col.getName().endsWith("title") || col.getName().endsWith("path")) {
System.out.println("\tName: " + col.getName());
System.out.println("\tValue: " + col.getValue());
System.out.println("------------------------");
}*/
if (col.getName().endsWith("path")) {
System.out.println("\tName: " + col.getName());
System.out.println("\tValue: " + col.getValue());
String path = col.getValue();
path = path.replace("/{http://www.alfresco.org/model/application/1.0}", "/app:");
path = path.replace("/{http://www.alfresco.org/model/site/1.0}", "/st:");
path = path.replace("/{http://www.alfresco.org/model/content/1.0}", "/cm:");
System.out.println("------------------------");
System.out.println("path:" + path);
documentList.add(path);
}
/*System.out.println("\tName: " + col.getName());
System.out.println("\tValue: " + col.getValue());*/
}
}
} catch (Exception exception) {
exception.printStackTrace();
}
LOGGER.exiting("iterateQueryResultSet");
return documentList;
}
/*Alfresco serach vo*/
public class AlfrescoSearchVO {
private String name;
private String title;
private String text;
private String author;
private String modifier;
private String creator;
private String contentType;
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the title
*/
public String getTitle() {
return title;
}
/**
* @param title the title to set
*/
public void setTitle(String title) {
this.title = title;
}
/**
* @return the text
*/
public String getText() {
return text;
}
/**
* @param text the text to set
*/
public void setText(String text) {
this.text = text;
}
/**
* @return the author
*/
public String getAuthor() {
return author;
}
/**
* @param author the author to set
*/
public void setAuthor(String author) {
this.author = author;
}
/**
* @return the modifier
*/
public String getModifier() {
return modifier;
}
/**
* @param modifier the modifier to set
*/
public void setModifier(String modifier) {
this.modifier = modifier;
}
/**
* @return the creator
*/
public String getCreator() {
return creator;
}
/**
* @param creator the creator to set
*/
public void setCreator(String creator) {
this.creator = creator;
}
/**
* @return the contentType
*/
public String getContentType() {
return contentType;
}
/**
* @param contentType the contentType to set
*/
public void setContentType(String contentType) {
this.contentType = contentType;
}
}
No comments:
Post a Comment