jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexandre Martins" <alexandremart...@gmail.com>
Subject Full-text Search in several workspaces
Date Fri, 23 Mar 2007 12:22:45 GMT
Hi all,

I need search something (full-text) in several workspaces, but i have a
problem. What a best way to perform this? Because i concat the results.
However, the last workspace will be their results in the end of my
collection. Make a sorting by jcr:score could be a good way?

below is my code,


StringBuffer strQuery = new StringBuffer();
            strQuery.append("SELECT * FROM nt:base WHERE CONTAINS(.,'"
                    + pTextQuery + "') ");
            if ((types != null) && (types.size() != 0)) {
                strQuery.append(" AND ( ");
                for (AssetTypeModel type : types) {
                    strQuery.append(" (jcr:mimeType='" + type.getMimeType()
                            + "') OR ");
                }
                strQuery.delete(strQuery.length() - 3, strQuery.length());
                strQuery.append(" ) ");
            }
            strQuery.append(" order by jcr:score DESC");
            Session session = null;
            try {
                for (WorkspaceModel workspace : workspaces) {
                    session = login(pRepository, pCredential, workspace
                            .getName());
                    QueryManager queryManager = session.getWorkspace()
                            .getQueryManager();
                    Query query = queryManager.createQuery(strQuery.toString
(),
                            Query.SQL);
                    QueryResult queryResult = query.execute();
                    NodeIterator iter = queryResult.getNodes();
                    while (iter.hasNext()) {
                        Node element = (Node) iter.next();
                        AssetModel asset = new AssetModel();
                        asset.setWorkspace(workspace);
                        asset.setName(element.getParent().getName());
                        asset.setPath(element.getParent().getPath());
                        asset.setSize(calculateSize(element.getProperty(
                        "jcr:data")));
                        lReturn.add(asset);
                    }
                }

            } catch (Exception e) {
                throw new BartEnvironmentException(getClass().getName(),
                        "findByNodeContentByWorkspaces", e);
            } finally {
                logoutSession(session);
            }

thanks,



-- 
Alexandre Costa Martins
CESAR - Recife Center for Advanced Studies and Systems
Software Engineer and Software Reuse Researcher
MSc Candidate at Federal University of Pernambuco
RiSE Member - http://www.rise.com.br

E-mail: alexandre.martins@cesar.org.br
MSN: xandecmartins@hotmail.com
GTalk: alexandremartins@gmail.com
Skype: xandecmartins
Mobile: +55 (81) 9929-9548
Office: +55 (81) 3425-4763
Fax: +55 (81) 3425-4701

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message