cancel
Showing results for 
Search instead for 
Did you mean: 

LUcene query to search only in selected folder

dsnkostic
Champ in-the-making
Champ in-the-making
I am trying to write Lucene query where you can only search for contents in selected folder and not to go recursive in sub-folders.
Here is an example so far…


    String queryStr = "PATH:\"/" + projectPath + "//.\" ";
    queryStr += " AND TYPE:\"{http://www.alfresco.org/model/content/1.0}content\"";
    Query query = new Query(Constants.QUERY_LANG_LUCENE, queryStr);

    RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();
    Store storeRef = new Store(Constants.WORKSPACE_STORE, ZADConstants.SPACESSTORE);
    Node [] nodes = null;
    nodes = repositoryService.get(new Predicate(null, storeRef, query));
2 REPLIES 2

jcustovic
Champ in-the-making
Champ in-the-making
Instead of using '//' use only one slash '/' and use '*' instead of '.'.
In your case: String queryStr = "PATH:\"/" + projectPath + "/*\" ";

You can find full documentation at http://wiki.alfresco.com/wiki/Search#Path_Queries

dsnkostic
Champ in-the-making
Champ in-the-making
Of course!
I didn't realized that Lucene uses almost same syntax as XPath. Thank you for your solution. Smiley Happy