Search code examples
lucenealfresco

Lucene query : parse execption


I am using alfresco and trying to execute these queries,

These are my queries.

1st:

PATH:"/app:company_home/st:sites/cm:swsdp/cm:dataLists/cm:aea88103-517e-4aa0-a3be-de258d0e6465//*"

1st query is working properly but 2nd query is not able to parse

2nd

+PATH:"/app:company_home/st:swsdp/cm:/cm:dataLists/cm:9787a75b-cbc9-4d42-b76c-df88461e62c6//*"

Exception : Cannot parse '+PATH:"/app:company_home/st:swsdp/cm:/cm:dataLists/cm:9787a75b-cbc9-4d42-b76c-df88461e62c6//*" AND +TYPE:"fdm:formDatalist"': Failed to parse XPath... Unexpected '9787'

I tried by escaping but still getting same.

+PATH:"/app:company_home/st:swsdp/cm:/cm:dataLists/cm:9787a75b\-cbc9\-4d42-b76c\-df88461e62c6//

I noticed that in 1st query cm:aea88103-517e-4aa0-a3be-de258d0e6465 starts with latter but in 2nd query cm:9787a75b-cbc9-4d42-b76c-df88461e62c6 this contains numbers in starting so that it's not able to parse.

Please solve this error.


Solution

  • Certain characters need to be encoded in hexa for lucene PATH queries.

    You need to encode your path this way :

    var rawString = "//test:123 DIR/FILE.TXT @"; 
    => rawString: //test:123 DIR/FILE.TXT @   
    var encodedString = search.ISO9075Encode(rawString);
    => encodedString: _x002f__x002f_test_x003a_123_x0020_DIR_x002f_FILE.TXT_x0020__x0040_
    var decodedString = search.ISO9075Decode(encodedString);
    => decodedString: //test:123 DIR/FILE.TXT @  
    

    See alfresco documentation for more information : http://docs.alfresco.com/5.2/references/API-JS-iso9075Encode.html