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

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

Related

Issues with the usage of #> operator in postgres

I'm having a post, each post has tags (varchar[]), and I'm trying to find related ones according to tags. This is why I want to check if all tags of the target post or any of its subsets are contained in the 'tags' arrays of other posts.
I've checked several sources:
Postgres: check if array field contains value?
https://www.postgresql.org/docs/9.1/functions-array.html
According to them, #> should be suitable for this case, however neither
select * from posts where tags #> '{"California", "K-8"}';
nor
select * from posts where tags #> array['California', 'K-8']::varchar[];
work properly: I got an empty result while I have two posts with tags:
{'California','K-8','Legislation','AB77'}, {'California','K-8','Tips & Tricks'}
I would greatly appreciate it if someone could advise a solution to this issue :-)
EDIT: I've figured out what was wrong - the issue was in the format of stored data: after I had changed
{'California','K-8','Tips & Tricks'}
to
{California,K-8,"Tips & Tricks"}
in pgAdmin everything started to work properly.
I've figured out what was wrong - the issue was in the format of stored data: after I had changed
{'California','K-8','Tips & Tricks'}
to
{California,K-8,"Tips & Tricks"}
in pgAdmin everything started to work properly.

TYPO3 queryBuilder: How to work with BINARY in where() clause?

I just have a short question.
There's no description in the following API overview of TYPO3 how to use a "BINARY" in where() clause: https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Database/QueryBuilder/Index.html#expr
What I want to achieve? this one:
WEHRE BINARY `buyer_code` = "f#F67d";
Actually I can only do the following:
->where(
$queryBuilder->expr()->eq('buyer_code', 'f#F67d')
);
But in this case I don't get a satisfying result for myself because I need case-sensitive here :-)
An another buyer_code exists "f#F67D" (the last char is uppercase) but I do need to look for the other one.
Thanks for helping.
Since TYPO3 is using Doctrine API here, you could try to do
->where('BINARY `buyer_code` = ' . $queryBuilder->createNamedParameter('f#F67d'))
Please keep in mind, that this query now only works for database backends, supporting the BINARY keyword!
Please have a look at Doctrine2 case-sensitive query The thread is a bit older, but seems to cover background and solution for your problem.

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 ?

Entity Framework .Include does not support paths with more than 8 dot-separated names

I've opened a bug on Microsoft Connect for this, but no response (see edit below for their response) in a long while. So here it goes:
When trying to request an entity framework with its relation using the "Include" function in the linq query, it's impossible to request a relation through a path of more than 8 steps (8 . dot characters in the path). This prevents me from completing some of my dynmically generated queries that require access to more than that level of redirection.
Instead of completing the query successfully I get the following exception:
"Foo.Bar.Baz...(some more path string here)", the current limit of "8" is insufficient.
at System.Data.Common.MultipartIdentifier.IncrementStringCount(String name, String[] ary, Int32& position, String property)
at System.Data.Common.MultipartIdentifier.ParseMultipartIdentifier(String name, String leftQuote, String rightQuote, Char separator, Int32 limit, Boolean removequotes, String property, Boolean ThrowOnEmptyMultipartName)
at System.Data.Objects.Span.ParsePath(String path)
at System.Data.Objects.Span.Include(String path)
at System.Data.Objects.Span.IncludeIn(Span spanToIncludeIn, String pathToInclude)
Has anyone figured why this is so, or a way around this? Looking at the code (with Reflector) of ParsePath it seems that they hard-coded the magic number 8 in there...
UPDATE: Microsoft's response:
Thank you for raising this issue. We plan to remove the limit of the number of elements in an Include path in the next release.
UPDATE 2: Despite Microsoft's response quoted above, the bug was not fixed in EF 4.1
UPDATE 3: According to Microsoft, should be fixed in .NET 4.5, but I didn't test the developer preview to see if it works.
probably fixed in latest .net 4.5
https://connect.microsoft.com/VisualStudio/feedback/details/640423/entity-framework-include-strings-are-arbitrarily-limited-to-a-path-of-depth-8#tabs
I have not seen this, but here are 2 possible work arounds:
Loop through the data and use Load for each row. Note this will create a call to the database for each row, so it is really slow.
Flatten the data in a view and then select from the view. This creates a lot of redundant data, so more memory and network use.