cancel
Showing results for 
Search instead for 
Did you mean: 

Search content in specific folder

billmce
Champ in-the-making
Champ in-the-making
I've read the Search page on the wiki, I've searched the forums, I've read lucene documentation, I've read XPATH documentation … but the solution to this problem escapes me.

I have folders in Alfresco laid out as:

Company Home|
……………….|
……………….|Client Name|
……………………………..|
……………………………..|Accounting
……………………………..|Sales
……………………………..|Human Resources

I'm trying to put together a webscript that will search for documents only in the 'Human Resources' folder.

var query = "PATH:\"/app:company_home/cm:Client_Name/cm:Human_Resources//*\"+TEXT:searchString";var results = search.luceneSearch(query);‍‍‍‍

Where am I going wrong and can you point me to some documentation on setting PATH for luceneSearch?
Any help appreciated … I'm at a loss.
Thanks.
9 REPLIES 9

openpj
Elite Collaborator
Elite Collaborator
You have to encode in ISO9075 each space name, in this way:
var query = "PATH:\"/app:company_home"+"/cm:"+search.ISO9075Encode("Client Name")+"/cm:"+search.ISO9075Encode("Human Resources")+"//*\" +TEXT:\"searchString\" ";‍‍‍‍‍
You can find this reference here:
http://wiki.alfresco.com/wiki/3.2_JavaScript_API#Search_API

Hope this helps.

billmce
Champ in-the-making
Champ in-the-making
Thank you … I had danced all around that solution without hitting it.
I appreciate you taking the time to give such a thorough solution.

billmce
Champ in-the-making
Champ in-the-making
Having past a major hurdle, I've got a little bit of work to do.

I've found that the lucene search is searching within the 'Data Dictionary'.  My web scripts are in
Company Home / Data Dictionary / Web Script Extensions / com / mycompany

During testing, I hard coded the search string.  To my surprise, in the results returned from the search was my javascript file.

Why is it searching outside the specified path? … and how can I stop it from searching outside the specified path?

Thanks

mikeh
Star Contributor
Star Contributor
You've currently got PATH as an optional search term - add a "+" in front, as you have for TEXT.

Thanks,
Mike

billmce
Champ in-the-making
Champ in-the-making
If I add the + I get no results at all … I'm certain that there are multiple files matching 'searchString' in the folder
/ Company Home / Client Name / Human Resources

var query = "+PATH:\"/app:company_home"+"/cm:"+search.ISO9075Encode("Client Name")+"/cm:"+search.ISO9075Encode("Human Resources")+"//*\" +TEXT:\"searchString\" ";‍‍‍‍‍

I'm using Community Edition 3.3.

Any help very much appreciated.

openpj
Elite Collaborator
Elite Collaborator
Probably it could be a wrong setting of mimetype: can you check if all the files in that space have a correct value for the mimetype property?
From the node browser you have to check the content property in the properties section.

billmce
Champ in-the-making
Champ in-the-making
This just isn't giving me the kind of results I need.
What I want to do is search only files the folder  '/Company Home/Fall and Associates/Creditors/TT900/' for the string "in other baskets".

In the folder  '/Company Home/Fall and Associates/Creditors/TT900/' are two files.
One is a copy of the other.  They both contain the string "in other baskets"  – they both should match this search.  I've added no other files to the repository.

I should find both files – but I don't. In addition, despite the '+PATH:' I am getting the script itself returned as a result (it's under '…/Data Dictionary /Web Script Extensions/…')

var query = "+PATH:\"/app:company_home"+"/cm:"+search.ISO9075Encode("Fall And Associates") + "/cm:"+search.ISO9075Encode("Creditors")+"/cm:"+search.ISO9075Encode("TT900") +"//*\" +TEXT:\"in other baskets\" ";var results = search.luceneSearch(query);‍‍‍‍‍

This is the result
<items>

<item>
<name>Duplicate2 of Kiva.pdf</name>
<title>
               number 2
            </title>
<size> 94,176 </size>
<author>billmc</author>
</item>

<item>
<name>searchDocs.get.js</name>
<title>
            </title>
<size> 1,708 </size>
<author>admin</author>
</item>
</items>

The 'searchDocs.get.js' is the name of the script (based on the Packt Book by Shariff in company). It should NOT be returned.
Missing is the expected 'Duplicate1 of Kiva.pdf' which is identitical (a copy) of the file returned.

Questions:
1) Is this lucene search syntax correct for what I'm trying to do?
2) Why do I keep getting matches from outside the PATH setting?  How can I stop that?
3) Why do both results get returned (along with Alfresco system files of various kinds) when I do the search from the webclient … but only one is returned in the webscript?
4) Is there another way, besides lucene to do this? 

I should add that this is on Community Edition 3.3 which we're using to evaluate Alfresco's suitability in our company. Search is obviously a huge factor in our evaluation.

Thanks in advance.

billmce
Champ in-the-making
Champ in-the-making
Simplifying a bit.

This doesn't return all the files .. and it seems to drop files now and then as I change the contents of the folder.

var query = "+PATH:\"/app:company_home"+"/cm:"+search.ISO9075Encode("Fall And Associates") + "/cm:"+search.ISO9075Encode("Creditors")+"/cm:"+search.ISO9075Encode("TT900") +"//*\"";var results = search.luceneSearch(query);‍‍‍‍‍

I have 3 copies of the same file in this folder … it only returns two of them.  
I think I've got something somewhere eating the first result?

What's going on?
What would be the simplest way for me to see the result as far as a ftl file goes?
TIA.

billmce
Champ in-the-making
Champ in-the-making
That's what it is … I've got some problem in my xml.ftl file that is eating a result.
My html.ftl file returns the correct output.

Thanks for the patience.