3

I am using the latest version of alfresco 5.1 version. one of my requirement is to create properties (key / value) where user enter the key as well as the value.

so I have done that like this

    Map<QName, Serializable> props = new HashMap<QName, Serializable>();
    props.put(QName.createQName("customProp1"), "prop1");
    props.put(QName.createQName("customProp2"), "prop2");
    ChildAssociationRef associationRef = nodeService.createNode(nodeService.getRootNode(storeRef), ContentModel.ASSOC_CHILDREN, QName.createQName(GUID.generate()), ContentModel.TYPE_CMOBJECT, props);

Now what I want to do is search the nodes with these newly created properties. I was able to search the newly created property like this.

public List<NodeRef> findNodes() throws Exception {
    authenticate("admin", "admin");
    StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
    List<NodeRef> nodeList = null;
    Map<QName, Serializable> props = new HashMap<QName, Serializable>();
    props.put(QName.createQName("customProp1"), "prop1");
    props.put(QName.createQName("customProp2"), "prop2");
    ChildAssociationRef associationRef = nodeService.createNode(nodeService.getRootNode(storeRef), ContentModel.ASSOC_CHILDREN, QName.createQName(GUID.generate()), ContentModel.TYPE_CMOBJECT, props);
    NodeRef nodeRef = associationRef.getChildRef();
    String query = "@cm\\:customProp1:\"prop1\"";
    SearchParameters sp = new SearchParameters();
    sp.addStore(storeRef);
    sp.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp.setQuery(query);
    try {
        ResultSet results = serviceRegistry.getSearchService().query(sp);
        nodeList = new ArrayList<NodeRef>();
        for (ResultSetRow row : results) {
            nodeList.add(row.getNodeRef());
            System.out.println(row.getNodeRef());
        }
        System.out.println(nodeList.size());
    } catch (Exception e) {
        e.printStackTrace();
    }
    return nodeList;
}

The alfresco-global.properties indexer configuration is

index.subsystem.name=buildonly
index.recovery.mode=AUTO
dir.keystore=${dir.root}/keystore

Now my question is

Is it possible to achieve the same using the solr4 indexer ? Or Is there any way to use buildonly indexer for a particular query ?

2 Answers2

1

In your query String query = "@cm\\:customProp1:\"prop1\""; remove cm as you are building the QName on the fly so it does not come under cm i.e. (ContentModel) properties. So your query will be

String query = "@\\:customProp1:\"prop1\"";

Hope this will work for you

  • Thanks Sachin, I tried your solution it works with the **buildonly** indexer. Since I am using indexer **solr4** your query results in empty set. – Joyson Dsouza Oct 03 '16 at 12:00
0

First, double check if you're simply experiencing eventual consistency, as described below. If you are, and if this presents a problem for you, consider switching to CMIS queries while staying on SOLR.

http://docs.alfresco.com/5.1/concepts/solr-event-consistency.html

Other than this, check if the node has been indexed at all. If it has, take a closer look at how you build your query.

How to find List of unindexed file in alfresco

Community
  • 1
  • 1
Lista
  • 2,186
  • 1
  • 15
  • 18
  • Hi Lista, Thank you for your efforts. I have asked the same question in alfresco IRC channel and it seems like I can not search for the properties created on the fly. The property has to be attached to a model !! – Joyson Dsouza Sep 26 '16 at 12:42
  • I see, I haven't realized those props are not in your model, haven't worked with that case at all to be totally honest. What's the reason for omitting them from the model? – Lista Sep 26 '16 at 13:00
  • 1
    well the requirement was to have properties associated with a specific node, where user can enter the key as well as value of his choice and these properties should not be visible(available) to other nodes. The user should be able to search a node based on the created properties !! – Joyson Dsouza Sep 26 '16 at 13:33