Thursday, November 15, 2012

Alfresco Content search example

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;
    }
   
}

3 comments:

  1. An overwhelming web journal I visit this blog, it's unfathomably amazing. Unusually, in this present blog's substance made inspiration driving truth and reasonable. The substance of data is enlightening
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  2. Thanks for sharing
    Best QA / QC Course in India, Hyderabad. sanjaryacademy is a well-known institute. We have offer professional Engineering Course like Piping Design Course, QA / QC Course,document Controller course,pressure Vessel Design Course, Welding Inspector Course, Quality Management Course, #Safety officer course.
    QA / QC Course
    QA / QC Course in india
    QA / QC Course in hyderabad

    ReplyDelete
  3. Nice Blog
    "Yaaron media is one of the rapidly growing digital marketing company in Hyderabad,india.Grow your business or brand name with best online, digital marketing companies in ameerpet, Hyderabad. Our Services digitalmarketing, SEO, SEM, SMO, SMM, e-mail marketing, webdesigning & development, mobile appilcation.
    "
    Best web designing companies in Hyderabad
    Best web designing & development companies in Hyderabad
    Best web development companies in Hyderabad

    ReplyDelete