cancel
Showing results for 
Search instead for 
Did you mean: 

Lucene Search doesn´t work after uploading a file

weggyboy
Champ in-the-making
Champ in-the-making
Hi!
I´m trying to find .doc files in a Alfresco folder with JavaScript after the user uploads a new file into this folder.
The process is quite simple:
- the user uploads a new file
- javascript searches for old files
- if there is any file found, they shall be moved into an archive folder

I´m trying to do these search with Lucene but it is not working.
After I upload the file, following error message is displayed:

Die Operation Transaction didn't commit: Failed to execute script 'workspace://SpacesStore/f5b9d977-7a42-11dc-a3bd-0fbb90973a69': TypeError: Cannot read property "@cm\:name:*doc" from undefined (AlfrescoScript#3) hat einen Systemfehler verursacht.

I was wondering, if the problem is in the query syntax or in the fact, that the LuceneSearch tryes to read properties from the uploaded file and then  collapses, like the Failure message says "Cannot read property".

Does anybody have any idea???
If the problem is the syntax, what is the right way?

Thanks!


This is my Javascript code:

// check if it is any .doc file in the folder already
// if there is one, move it to temp
var nodes = space.childrenByLuceneSearch["@cm\\:name:*doc"]; // <= IT DOESN`T WORK
var tempNode = parent.childByNamePath("temp");

for (var i=0; i < nodes.length; i++)
{
   if (tempNode != null)
      nodes[i].move(tempNode);
}

// check if it is a "last_transformed.html" file in the folder already
var lastfile = space.childByNamePath("last_transformed.html");
var transformed = document.transformDocument("text/html", space);

if (lastfile == null) {
   lastfile = space.createFile("last_transformed.html");
}

lastfile.content = transformed.content;
transformed.remove();

2 REPLIES 2

weggyboy
Champ in-the-making
Champ in-the-making
Hi!

I´ve solved the problem without luceneSearch()…
Sometimes is better to keep things simple.

Thanks anyway!

kevinr
Star Contributor
Star Contributor
You are not using the JavaScript API correctly - the childrenByLucene[] call is FreeMarker API call - in JavaScript you use the search object instead:
http://wiki.alfresco.com/wiki/JavaScript_API#Search_API

Thanks,

Kevin