AEM search for files in DAM - aem

I want to search files in my DAM folder using querybuilder. In my test folder, I have 1 .pptx file (powerpoint) and 1 .png file (image).
But when I run the below query, I get 3 results:
1. <PPTX file>/jcr:content
2. <PPTX file>.jcr:content/subassets/slide1/jcr:content
3 <image file>/jcr:content
The query is:
path=/content/dam/my-folder
type=dam:AssetContent
p.limit=-1
Are there any other predicates available to restrict this to 2 results, (files only) ?
I've tried "type=dam:Asset", but it gives 0 results. and "type=nt:base" gives 20 results

What you are looking for is the predicate mainasset. When you specify mainasset=true in your query it would ignore the subassets in the result. So, you can just search for type dam:Asset and specify the mainasset predicate as shown below.
path=/content/dam/my-folder
type=dam:Asset
mainasset=true
p.limit=-1
For more information on the list of available predicates in AEM, refer to this user guide.

Below AEM 6.3 -
Use path.flat predicate to narrow down the search to only the direct children and not the subtree.
path=/content/dam/we-retail/en/mahna
path.flat=true
type=dam:AssetContent
You can also use nodename predicate to query node names with a specific file extension
path=/content/dam/we-retail/en/mahna
type=dam:Asset
group.1_nodename=*.pptx
group.2_nodename=*.JPG
group.p.or=true

Related

AEM Querybuilder - How to return only the folders under a path?

I'm trying to rerun only the folders from a given path using query builder on AEM
Query:
path=/content/dam/we-retail/en
type=sling:OrderedFolder
p.hits=selective
p.nodedepth=1
p.limit=-1
Or URL http://localhost:4502/bin/querybuilder.json?p.hits=selective&p.limit=-1&p.nodedepth=1&path=%2fcontent%2fdam%2fwe-retail%2fen&type=sling%3aOrderedFolder
The query returns 35 records, while there are only 6 folders under /content/dam/we-retail/en. How can i return only these 6?
If you are looking at returning only the direct children under a path, use the property path.flat=true.
path=/content/dam/we-retail/en
path.flat=true
type=sling:OrderedFolder
p.hits=selective
p.nodedepth=1
p.limit=-1
However, it is better to loop through the child nodes and identify the folders rather than querying in cases like this where you need only the direct children.
More about the Path Predicate Evaluator here.

Multiple Keyword matching problems

I have a product description of the following text:
"DODGE H4C14S03706G-2G ILH48 37.06 W/ BALDOR VEM3558T"
I attempt a search "H4C1" and Algolia produces relevant results however
if I perform a search of "H4C1 VEM35" Algolia produces no results.
Is there a way to get Algolia to produce relevant results on this search?
By default, Algolia is only doing prefix matching for the last word of the search query, which means it would only match records containing H4C1 as a full word, and VEM35 as a full word or a prefix. However H4C1 is only a prefix of H4C14S03706G-2G, not a full word.
You can change the behavior by tweaking the queryType setting (the value you want is prefixAll), you can find more info in the FAQ and the documentation

AEM CQ5 Query Builder: How to get result by searching for 2 different values in same property?

I want to get result matches with all nodes contains property 'abc' value as 'xyz' or 'pqr'.
I am trying in below ways:
http://localhost:4502/bin/querybuilder.json?path=/content/campaigns/asd&property=abc&property.1_value=/%xyz/%&property.2_value=/%pqr/%property.operation=like&p.limit=-1&orderby:path
http://localhost:4502/bin/querybuilder.json?path=/content/campaigns/asd&property=abc&property.1_value=/%xyz/%&property.2_value=/%pqr/%&property.1_operation=like&property.2_operation=like&p.limit=-1&orderby:path
http://localhost:4502/bin/querybuilder.json?path=/content/campaigns/asd&1_property=abc&1_property.1_value=/%xyz/%&1_property.1_operation=like&2_property=abc&1_property.1_value=/%xyz/%&2_property.1_operation=like&p.limit=-1&orderby:path
But none of them served my purpose. Any thing that I am missing in this?
The query looks right and as such should work. However if it is just xyz or pqr you would like to match in the query, you may not need the / in the values.
For eg.
path=/content/campaigns/asd
path.self=true //In order to include the current path as well for searching
property=abc
property.1_value=%xyz%
property.2_value=%abc%
property.operation=like
p.limit=-1
Possible things which you can check
Check if the path that you are trying to search contains the desired nodes/properties.
Check if the property name that you are using is right.
If you want to match exact values, you can avoid using the like operator and remove the wild cards from the values.
You can actually use the 'OR' operator in your query to combine two or more values of a property.
For example in the query debug interface : http:///libs/cq/search/content/querydebug.html
path=/content/campaigns/asd
property=PROPERTY1
property.1_value=VALUE1
property.2_value=VALUE2
property.operation=OR
p.limit=-1
It worked with below query:
http://localhost:4502/bin/querybuilder.json?orderby=path
&p.limit=-1
&path=/content/campaigns
&property=jcr:content/par/nodeName/xyz
&property.1_value=pqr
&property.2_value=%abc%
&property.operation=like
&type=cq:Page
Note: property name should be fully specified form the type of node we are expecting.
Ex: jcr:content/par/nodeName/xyz above instead of just xyz

Finding node/asset using Name LIKE in CQ5?

I want to find an asset under a particular path and that has a name like '%xyz%'.
I referred to this page "9 JCR Queries every AEM developer should know"
Please refer to point number 7. It clearly states that I can use a combination of Name() Like '%xyz%'
APPROACH 1
So I fired a query
String jcrQuery = "SELECT * FROM [dam:Asset] WHERE NAME() LIKE '%"+conditionalSelectString+"%'";
And I go javax.jcr.UnsupportedRepositoryOperationException.
Approach 2
I found this amazing page with CQ5 that helps you construct JCR-SQL2 queries
http://localhost:4502/crx/explorer/ui/search.jsp
So with the help of this I generated the query
select * from dam:Asset where jcr:path like '/content/dam/pdf/%' and contains(*, '%Slide%')
This works fine when I fire this query on the search.jsp page of CQ5. But when I try to fire this query in a class within my bundle I get an Exception
So how do I fire a query that searches a DAM Asset by name using like and not exact name. I know that NAME can be used to find node with exact match.
How do I use name and Like together ?

CQ5 QueryBuilder Search Not Working as Expected (when property NOT present)

I'm trying to produce a query that will return all pages under a path where a property is NOT present.
Effectively I want the query builder query that will produce the following xpath: /jcr:root/content/site/my/path//element(*, cq:Page)[not(jcr:content/task/#finished)]
For CQ 5.3 the 'exists' property doesn't seem to be present (according to the docs: http://docs.adobe.com/docs/en/cq/5-3/javadoc/com/day/cq/search/eval/JcrPropertyPredicateEvaluator.html), however it looks like I can use 'not', so I've tried the following two examples but neither work as I expect in query debugger:
1
path=/content/site/my/path
type=cq:Page
property=jcr:content/task/finished
property.operation=not
2
path=/content/site/my/path
type=cq:Page
property=jcr:content/task/finished
property.operation=not
property.value=true
I've also seen pages that suggest these should work, and I can't seem to see any hotfixes that would cover fixing this (assuming it isn't actually working correctly).
Can anyone offer a solution or point out where I'm going wrong?
Using CQ 5.3, upgraded to crx 2.2.
Cheers
Chris
I have a few resource that I hope help you:
My blog post about query API options: http://itgumby.github.io/blog/2014/10/cq-queries-demystified/
6 Dimension's post about specific query examples: http://labs.sixdimensions.com/blog/2014-10-07/9-jcr-sql-2-queries-every-aem-dev-should-know/
Adobe QueryBuilder documentation: http://docs.adobe.com/docs/en/aem/6-0/develop/search/querybuilder-api.html
Non-empty SQL2 (From the 6D post):
SELECT * FROM [cq:PageContent] WHERE [jcr:title] IS NOT NULL
Which means you could convert that to WHERE [jcr:title] IS NULL
If using QueryBuilder predicates, the property generally won't exist (deleted from node) if it is false. Please manually verify in your case using CRX-DE lite and examining the node & its properties. If the property does exist, but its value is false, then:
path=/content/site/my/path
type=cq:Page
property=#jcr:content/task/finished
property.value=false
For any still struggling, this is how you do it
path=/content/site/my/path
type=cq:Page
property=jcr:content/task/finished
property.operation=exists
property.value=false