Find first level pages using query - aem

I want to fetch all the pages below the current path using query, as i need to sort them also so using the query. I am using below criteria which is giving me the pages below hierarchy but also goes deep till it contains child.
path=/content/geometrixx/en/toolbar
type=cq:Page
orderby=#jcr:content/cq:lastModified
I show be below result like :
/content/geometrixx/en/toolbar/newsletter (crxde, html, json)
/content/geometrixx/en/toolbar/sitemap (crxde, html, json)
/content/geometrixx/en/toolbar/account (crxde, html, json)
/content/geometrixx/en/toolbar/account/register (crxde, html, json)
/content/geometrixx/en/toolbar/account/register/thank_you (crxde, html, json)
As in Account page i dont need the sub pages in result set. Please provide any criteria that fit into such type of query.
Thanks

You can use flat property of the PathPredicateEvaluator
The sample query would be
type=cq:Page
path=/content/geometrixx/en/toolbar
path.flat=true
orderby=#jcr:content/cq:lastModified
orderby.sort=desc
It would translate to the following XPath query
/jcr:root/content/geometrixx/en/toolbar/element(*, cq:Page)
order by jcr:content/#cq:lastModified descending
To know more about the various properties available, refer the implementing classes of PredicateEvaluator.

If you're using an XPath query, you can simply remove the double forward slash. E.g. using the QueryBuilder debugger, your predicates give an XPath of /jcr:root/content/geometrixx/en/toolbar//element(*, cq:Page)
If you change this to:
/jcr:root/content/geometrixx/en/toolbar/element(*, cq:Page)
i.e. removing the second forward slash immediately before "element", it will just search direct children. You can preview this on the CRX explorer:
http://localhost:4502/crx/explorer/ui/search.jsp?Path=&Query=%2fjcr%3aroot%2fcontent%2fgeometrixx%2fen%2ftoolbar%2felement(*%2c%20cq%3aPage)

Related

AEM Query Builder: Need to search for specific text on all properties on all pages

I need to do a search for all nodes that contain a specific piece of text. I know I can use the LIKE operation for this, but the issue is how to search for the string when you are not specifying any properties? Basically if any property on any node on any page contains the string, I wwant to return those results?
Can anyone help?
G
You can use this to search for any substring inside any properties under any path using AEM Query Builder. You can use asterisk or * If you do not want a substring and just the full text then remove the "*" and give the search text;
path=/content
fulltext=*anyTextToSearch*
OR IN XPATH Query
/jcr:root/content/path/to/page//*[jcr:contains(., '(*anyTextToSearch*')]
OR IN SQL2
SELECT * FROM [nt:unstructured] AS node
WHERE ISDESCENDANTNODE(node, "/search/in/path")
AND CONTAINS([propertyName], "*anyTextToSearch*")
I think you can try 'fulltext' search,
path=/content
fulltext=searchtext

Fulltext query on properties and subnodes does not work properly - AEM Query Builder

I'm trying to perform a query on the CRX of a 6.2 Adobe AEM version.
I have to execute a fulltext query on (aNode is a generic subnode of /content/connect/it/supplier/):
1) all properties of /content/connect/it/supplier/aNode/jcr:content
2) all subnodes of /content/connect/it/supplier/aNode/jcr:content/service/legal
as you can see, highlighted in red, in the following picture of the JCR OAK:
To achive my target I've used the following query using AEM query builder debugger:
path:/content/connect/it/supplier
orderBy:#jcr:score
p.limit:-1
group.p.or:true
group.1_fulltext:*something to search*
group.1_fulltext.relPath:jcr:content
group.2_fulltext:*something to search*
group.2_fulltext.relPath:jcr:content/service/legal
Searching for 'something to search' on the properties of jcr:content works properly.
I'm not able to search on the subnodes of 'jcr:content/service/legal'. It does not retrieve anything.
Try:
path:/content/connect/it/supplier
orderBy:#jcr:score
p.limit:-1
fulltext=*something to search*
group.p.or:true
group.1_relPath:jcr:content
group.2_relPath:jcr:content/service/legal
That should work. See the following links:
https://helpx.adobe.com/experience-manager/6-2/sites/developing/using/querybuilder-api.html
http://www.aemcq5tutorials.com/tutorials/adobe-aem-cq5-tutorials/aem-query-builder/
relPath is always limiting the search to the element specified. With that approach you will not reach your goal. You could remove the relPath for group.2 which might give you too many results.
fulltext=something to search
group.p.or=true
group.1_path=/content/connect/it/supplier
This automatically searches the fulltext in jcr:content and the subnode below it. This will server your purpose of searching in jcr:content properties and subnodes of jcr:content
If you want to search the fulltext of multiple paths
fulltext=something to search
group.p.or=true
group.1_path=/content/connect/it/supplier
group.2_path=/content/connect/it/xyz

Search for pages tagged with a tag title

In order to get pages tagged with a certain tag in AEM query builder, we will do as this doc (https://helpx.adobe.com/experience-manager/6-2/sites/developing/using/querybuilder-api.html)
path=/content/...
type=cq:Page
tagid=marketing:interest/product
tagid.property=jcr:content/cq:tags
But how do we get pages that have the same tag title without using the whole tag's ID or full path above ?
For example
path=/content/...
type=cq:Page
tagtitle=product
tagid.property=jcr:content/cq:tags
You could use something like that:
JCR like:
path=/content/..
type=cq:Page
property=jcr:content/#cq:tags
property.value=%tagname
property.operation=like
This would search for cq:tags property with value that ends with "product".
See more about jcr:like function.
Another possible solution:
Full text search:
path=/content/somesite
type=cq:Page
fulltext.relPath=jcr:content/#cq:tags
fulltext=tagname
See more about jcr:contains function

Yii2 remove empty fields from url string

I need your help. I have an Active Form in my Yii2 application and when I submit my form it shows values (no matter empty or not) of every field of the form to the GET-string so it looks like
domain.com/index?ItemSearch%5Brooms_arr%5D=&ItemSearch%5Bprice_type%5D=& ItemSearch%5Bprice_type%5D=0&ItemSearch%5Barea_from%5D=&ItemSearch%5Barea_to%5D=&... etc.
I need to have cleaner query string which will contain only non-empty params?
For example domain.com/index?rooms_arr=12&price_type=normal.
Please suggest me what is the best way to do this?
This is not the yii2 problem. It is a native html form works like this. If you really do want to exclude all not filled inputs from the query string you could filter all this params via jQuery and set them to disable state, here is the code
$('form').submit(function(e){
var emptyinputs = $(this).find('input').filter(function(){
return !$.trim(this.value).length; // get all empty fields
}).prop('disabled',true);
});

Populating some fields after selecting the element using Struts2-Dojo autocompleter

I am using sx tag i.e. struts-dojo-tag of struts 2 to autosuggest one field on one page. It is working fine. Now I want to populate other fields on the same page based on the selection of autosuggest field. I tried calling javascript on the above field on various events like onselect, onchange,etc with no success.
JSP code :
<sx:autocompleter autoComplete="true" listKey="id" listValue="brandName" name="brand.brandName" id="brandName" cssClass="textfield" list="brandList" onchange="populateInfo(this.value);"></sx:autocompleter>
here I want to autosuggest brandNames available and on selecting the brand, I want to populate data regarding the brand in some others fields. I tried calling java script function populateInfo(), but the function is not getting called.
Can you please help me out?
I think this problem can be solved by using select tag of struts2-jquery.
You can have a look in these showcase