cancel
Showing results for 
Search instead for 
Did you mean: 

Search not finding aspect after I make updates. NodeService.hasAspect is finding it... after updating search results

josh_barrett
Confirmed Champ
Confirmed Champ
I am trying to write an action that creates thumbnails in the background. 
This action:
-executes a query to see what needs to be thumbnailed
-if no results exits
-iterates through the result adding thumbnails and adds a marker aspect to the node
-Sleeps for 10 seconds
-and executes query again.

I tested this with one node and it runs over and over again.  It is not finding the aspect in the query.

Here is the code (groovy):
<groovy>
     protected void processAction( String query) {
        List<NodeRef> nodeRefs = createQueue(query)
        if (nodeRefs.size() == 0) return
        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Boolean>(){
            public Boolean execute() throws Throwable {
                for (nodeRef in nodeRefs) {
                    Action action = actionService.createAction(DermThumbnailAction.NAME)
                    actionService.executeAction(action, nodeRef)
                }
                return true;
            }
        });
        Thread.sleep(10000);
        processAction( query)
    }
</groovy>

Here is the output of my log:
2013-04-23 09:37:34,124  INFO  [alfresco.actions.DermThumbnailProcessor] [defaultAsyncAction1] Starting thumbnail process…
2013-04-23 09:37:34,130  DEBUG [alfresco.service.ADPSearchService] [defaultAsyncAction1] Getting nodes using query: TYPE:"adpp:doc" -ASPECT:"adpp:thumbnailAspect"
2013-04-23 09:37:35,484  DEBUG [alfresco.service.ADPSearchService] [defaultAsyncAction1] Search TYPE:"adpp:doc" -ASPECT:"adpp:thumbnailAspect" returned 1
2013-04-23 09:37:35,542  DEBUG [alfresco.actions.DermThumbnailAction] [defaultAsyncAction1]  Does not have a thumbnail workspace://SpacesStore/dfe35ea2-dcfb-4e30-9cad-fcb635cef523
2013-04-23 09:37:35,543  DEBUG [alfresco.service.ADPThumbnailService] [defaultAsyncAction1] Creating thumbnail for workspace://SpacesStore/dfe35ea2-dcfb-4e30-9cad-fcb635cef523
2013-04-23 09:37:36,548  INFO  [alfresco.service.ADPThumbnailService] [defaultAsyncAction1] Thumbnail created for workspace://SpacesStore/dfe35ea2-dcfb-4e30-9cad-fcb635cef523
2013-04-23 09:37:46,553  DEBUG [alfresco.service.ADPSearchService] [defaultAsyncAction1] Getting nodes using query: TYPE:"adpp:doc" -ASPECT:"adpp:thumbnailAspect"
2013-04-23 09:37:46,566  DEBUG [alfresco.service.ADPSearchService] [defaultAsyncAction1] Search TYPE:"adpp:doc" -ASPECT:"adpp:thumbnailAspect" returned 1
2013-04-23 09:37:46,569  DEBUG [alfresco.actions.DermThumbnailAction] [defaultAsyncAction1] Already has a thubmnail workspace://SpacesStore/dfe35ea2-dcfb-4e30-9cad-fcb635cef523
2013-04-23 09:37:56,570  DEBUG [alfresco.service.ADPSearchService] [defaultAsyncAction1] Getting nodes using query: TYPE:"adpp:doc" -ASPECT:"adpp:thumbnailAspect"
2013-04-23 09:37:56,579  DEBUG [alfresco.service.ADPSearchService] [defaultAsyncAction1] Search TYPE:"adpp:doc" -ASPECT:"adpp:thumbnailAspect" returned 1

…. 
Never finds the aspect via search but finds it when I do a check for the aspect before adding the thumbnail.  I must be doing something wrong.


6 REPLIES 6

afaust
Legendary Innovator
Legendary Innovator
Hello,

what is the "ADPSearchService"? This does not appear to be a standard Alfresco search service / component. This means that unless the code of that class is available, I couldn't venture a guess if I wanted to…

Regards
Axel

Hi Axel,

That class is just a helper Service class for searching.  It uses the Alfresco SearchService under the covers.

package com.adp.alfresco.service

import org.alfresco.service.cmr.repository.NodeRef
import org.alfresco.service.cmr.repository.NodeService
import org.alfresco.service.cmr.repository.Path
import org.alfresco.service.cmr.repository.StoreRef
import org.alfresco.service.cmr.search.ResultSet
import org.alfresco.service.cmr.search.SearchParameters
import org.alfresco.service.cmr.search.SearchService
import org.alfresco.service.namespace.NamespaceService
import org.apache.commons.logging.Log
import org.apache.commons.logging.LogFactory

import java.text.SimpleDateFormat


class ADPSearchService {
    private SearchService searchService
    private NodeService nodeService
    private NamespaceService namespaceService
    public static final SimpleDateFormat luceneSDF = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.sssZ")
    private static Log logger = LogFactory.getLog(ADPSearchService.class)

    public List<NodeRef> getNodeRefs(String query){
        logger.debug("Getting nodes using query: " + query)
        SearchParameters sp = createBasicLuceneSearchParameter(query)
        return getNodeRefs(sp)
    }


    public List<NodeRef> getNodeRefs(SearchParameters sp){
        ResultSet results = null
        try{
            results = searchService.query(sp)
            List<NodeRef>nodeRefs = results.getNodeRefs()
            logger.debug("Search "+sp.getQuery()+" returned "+nodeRefs.size())
            return nodeRefs
        }
        catch (Exception e) {
            logger.error("ERROR SEARCHING - "+sp.getQuery()+" - "+e.getMessage(),e)
        }
        finally{
            if(results != null)
            {
                results.close()
            }
        }
        return new ArrayList<NodeRef>()
    }

    public SearchParameters createBasicLuceneSearchParameter(String query){
        SearchParameters sp = new SearchParameters()
        sp.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE)
        sp.setLanguage(SearchService.LANGUAGE_LUCENE)
        sp.setQuery(query)
        return sp
    }

    public void setSearchService(SearchService searchService) {
        this.searchService = searchService
    }

    public void setNodeService(NodeService nodeService) {
        this.nodeService = nodeService
    }

    public void setNamespaceService(NamespaceService namespaceService) {
        this.namespaceService = namespaceService
    }


    public List<NodeRef> getNodeRefs(String query, int limit) {
        SearchParameters sp = createBasicLuceneSearchParameter(query)
        sp.setLimit(limit)
        return getNodeRefs(sp)
    }
}

Thanks,

Josh

afaust
Legendary Innovator
Legendary Innovator
Hello,
are you using embedded Lucene or SOLR? Is SOLR actively tracking changes? Have you tried your query in the Node Browser?

Apart from the looping and usage of Thread.sleep instead of a cron-/regular-scheduled job, the code doesn't look like it is the immediate cause of your problem.

Regards
Axel

josh_barrett
Confirmed Champ
Confirmed Champ
What I found is the transaction doesn't commit until the process stops.  That seems to be why Solr is not finding the changes.

What I need to figure out is how to continue this process while forcing the transaction to commit so the DB updates and Solr can index the changes.  Have you written code with partial commits or multiple transactions nested in a long running process?

Thanks,

Josh

afaust
Legendary Innovator
Legendary Innovator
Hello,

in terms of Alfresco transactions there is no such things as partial commits. You have to seperate your process in individual transactions, i.e. one per iteration. The simplest way to do this is using RetryingTransactionHelper.doInTransaction(RetryingTransactionCallback, boolean, boolean) where the RetryingTransactionCallback encapsulates your single-iteration logic, forcing a new transaction by passing true as the last boolean parameter (which is "requiresNew").

Regards
Axel

josh_barrett
Confirmed Champ
Confirmed Champ
Thank you for your help Axel!

-Josh