XPATH or SQL query to get files from parent and one child folder

Hello everyone,

I am stuck finding a solution to the below:
My content folder structure looks as follows:
/root/content/documents/…/…/parentFolder:
- childFolderA
- childFolderB
Both the parentFolder and its children folders contain files. Now, I want to write a query that only gets data from the parentFolder and childFolderA , but not from the other children folders.
Please note, There are many children folders , so I was be able to use a NOT clause.

Below are the SQL and XPath queries I tried, but did not give me the desired result:

SQL : select * from hippo:handle WHERE jcr:path LIKE ‘/content/%/parentFolderA/%’ OR jcr:path LIKE ‘/content/%/parentFolderA/childFolderA/%’

Error: javax.jcr.query.InvalidQueryException: Invalid combination of jcr:path clauses

XPATH Query : /jcr:root/content//parentFolderA/element(, hippo:handle) | /jcr:root/content//parentFolderA/childFolderA/element(, hippo:handle)

The XPath query does not throw an error and does not give me any results as well.

Please note , i have to apply an offset and limit on the query , so I wont be able to split them into individual queries. :frowning:

I really appreciate your help. Thank you in advance.

Best regards
Kiki

see:

Part you are interested in is in “Scope the Query with HstQueryBuilder” parameter.
You can also call query.toString() to see created xpath (if you need xpath )

in addition, you can also use

excludeScopes

constraints.

Thank you very much for such quick response.

Unfortunately, I am using the JCR API to execute the query. Hence I wont be able to use the HST library options.

I referred to this documentation, https://documentation.bloomreach.com/library/development/query-the-repository.html . I was wondering if I could build an XPATH query just like the ones in the document ?

Best
Kiki

Anything you can do with HstQuery you can do with the JCR API. You should take a look at the source of HstQueryImpl for inspiration.

The scope is done on the hippo:paths property.

 //*[@hippo:paths='some-uuid" and not(@hippo:paths='some-other-uuid')]

Thank you , this solution works for one path.

If I have the same parentFolderA/childFolderA structure (with the same names) under different folders across my root directory, I wont be able to use the UUID in that case.

The issue I am facing is my OR (pipeline operator) condition isnt working as expected on the hippo repository browser when I try to union two query results together.

AFAIK you cannot search on multiple paths. This will have to be done with two queries.

Yeah , I think so too. Thanks for the help!