find nodes with a specific child association

僤鯓⒐⒋嵵緔 提交于 2021-02-11 07:47:30

问题


I am looking for a query (lucene, fts-alfresco or ...) to return all the document which have a specific child association (that is not null).

Some context: Documents of type abc:document have a child-association abc:linkedDocument. Not all document have an other document linked to them, some have none some have one or multiple.

I need a fast and easy way to get an overview of all the documents that do have at least one document linked to them.

Currently I have a webscript that does what I need, but prefer not to have tons of webscripts which are not business related.

code:

        SearchParameters sp = new SearchParameters();
        String query = "TYPE:\"abc:document\"";
        StoreRef store = StoreRef.STORE_REF_WORKSPACE_SPACESSTORE;
        sp.addStore(store);
        sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);
        sp.setQuery(query);

        ResultSet rs = services.getSearchService().query(sp);
        List<NodeRef> nodeRefs = rs.getNodeRefs();
        for (NodeRef ref : nodeRefs) {
            List<ChildAssociationRef> refs = services.getNodeService().getChildAssocs(ref);
            for(ChildAssociationRef chref : refs){
            if(chref.getQName().equals(AbcModel.ASSOC_LINKED_DOC)){
                logger.debug("Document with linked doc: {}", ref);
                break;
            }
        }
        }

回答1:


Associations aren't query-able so you'll have to do what you are doing, which is essentially checking every node in a result set for the presence of a desired association.

The only improvement I can suggest is that you can ask for the child associations of a specific type which would prevent you from having to check the type of every child association, see How to get all Child associations with a specific Association Type Alfresco (Java)



来源:https://stackoverflow.com/questions/40997706/find-nodes-with-a-specific-child-association

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!