Search not finding aspect after I make updates. NodeService.hasAspect is finding it... after updating search results
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2013 10:14 AM
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.
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.
Labels:
- Labels:
-
Archive
6 REPLIES 6
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2013 01:53 PM
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
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2013 08:30 AM
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
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2013 11:52 AM
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
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2013 09:04 PM
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
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-07-2013 06:46 PM
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
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2013 02:09 PM
Thank you for your help Axel!
-Josh
-Josh
