XPATH Query in CQ5 - xpath

I am trying to get all the orders under user. I am using below XPTAH query.
/jcr:root/home/users/a/admin/commerce/orders//element(*)[#orderId] this result below records :
/home/users/a/admin/commerce/orders/order-2014-Apr-12
/home/users/a/admin/commerce/orders/order-2015-Apr-15
/home/users/a/admin/commerce/orders/order-2015-Apr-13
Now i have requirements that order should be in the sorted order as per booked(that i am looking for) , Other is i will have dynamic parameter which will I pass through the method in which i have the XPTH query executed e.g. 6 or ALL . 6 will display the last 6 months order only (that i am looking for). For all orders i can use the query with sort condition /jcr:root/home/users/a/admin/commerce/orders//element(*)[#orderId] order by #orderPlaced descending . I have orderPlaced property of Date type 2014-04-12T17:05:35.085+05:30. So want to put condition result will include last 6 months.
Thanks

try the query-debugger located at /libs/cq/search/content/querydebug.html
it shows the query in different formats including xpath-syntax. for instance you get the ordering syntax by running this url:
querydebugger

This solved my problem :
type=unstructured
path=/home/users/a/admin/commerce/orders
path.flat=true
orderby=#orderPlaced
orderby.sort=desc
1_relativedaterange.property=orderPlaced
1_relativedaterange.lowerBound=-6M
1_relativedaterange.upperBound=0

Related

How to get the matching data from two tables?

I'm used to compare 2 data, one data has an id and the other data is the one that needs comparing to get the matching datas. see code below.
DB::table('requests')->where('reqItem',$inventory->invItem)->get();
The code shown above displays all requests information that equals to the compared inventory item.
Now what i want to do now is to compare 2 tables without any id (ex. $inventory->invItem). I don't know how to ask this question but i hope you get what i mean. The figure below shows the way i wanted it to be.
You can run this query. Here, 'inventory' is the name of second table (change it accordingly)
DB::table('requests')
->join('inventory', 'requests.reqItem', '=', 'inventory.invItem')
->select('inventory.reqItem')
->get();

Make a group by with a where in statement Laravel

I am writing a little script to load an Attendee_logs, based that counts the total of prints for based on the hour.
First I load the id's from the attendees
$allAttendees->pluck('id')->implode(',')
So I get 389832, 321321 from this (this are the id's from the attendees, based on a group).
Now I want to group them by the hour.
But I cannot find out how I add the whereIn statement
$badgesPrintedByDate = DB::table('Attendee_logs')->select(DB::raw('hour(created_at)'), DB::raw('COUNT(id)'))->whereIn('id', [$allAttendees->pluck('id')->implode(',')])->groupBy(DB::raw('hour(created_at)'));
When I do it like this, I get an empty result.
But when I remove the whereIn I get a result.
So my question, How can I count the rows based on the Hour and where I also give the ID's with it :)?
I think this is gonna work:
$badgesPrintedByDate = DB::table('Attendee_logs')->select(DB::raw('hour(created_at)'), DB::raw('COUNT(id)'))->whereIn('id', $allAttendees->pluck('id')->all())->groupBy(DB::raw('hour(created_at)'));
Instead of saying:
$allAttendees->pluck('id')->all()
Which returns an array of ids, you can also say:'
$allAttendees->pluck('id')->values()
Or:
$allAttendees->pluck('id')->toArray();

Pig - Filter a column twice in the same filter

I'm trying to filter the same column twice. I basically want to only get the record in which one column is between the values of other 2 columns.
Imagine this:
(id,year_min,year_max,year)
(4470,1999,2001,2011)
(4471,2006,2013,2013)
So filtering like this it doesn't work:
filter1 = filter set by (year_min <= year and year_max >= year)
Is there another way of filtering it instead of breaking that filter into several ones?
Also, all the columns are bytearray.
PS: That is not the whole set but that is basically what I want to achieve.
Thanks.
I guess the year_max and year got swapped in your schema. It should be like this right? id, year_min, year, year_max but your schema says id, year_min, year_max, year . I modified the schema its works fine for me. Can you check it?

Salesforce SOQL query length and efficiency

I am trying to solve a problem of deleting only rows matching two criteria, each being a list of ids. Now these Ids are in pairs, if the item to be deleted has one, it must have the second one in the pair, so just using two in clauses will not work. I have come up with two solutions.
1) Use the two in clauses but then loop over the items and check that the two ids in question appear in the correct pairing.
I.E.
for(Object__c obj : [SELECT Id FROM Object__c WHERE Relation1__c in :idlist1 AND Relation2__c in:idlist2]){
if(preConstructedPairingsAsString.contains(''+obj.Relation1__c+obj.Relation2__c)){
listToDelete.add(obj);
}
}
2) Loop over the ids and build an admittedly long query.
I like the second choice because I only get the items I need and can just throw the list into delete but I know that salesforce has hangups with SOQL queries. Is there a penalty to the second option? Is it better to build and query off a long string or to get more objects than necessary and filter?
In general you want to put as much logic as you can into soql queries because that won't use any script statements and they execute faster than your code. However, there is a 10k character limit on soql queries (can be raised to 20k) so based on my back of the envelope calculations you'd only be able to put in 250 id pairs or so before hitting that limit.
I would go with option 1 or if you really care about efficiency you can create a formula field on the object that pairs the ids and filter on that.
formula: relation1__c + '-' + relation2__c
for(list<Object__c> objs : [SELECT Id FROM Object__c WHERE formula__c in :idpairs]){
delete objs;
}

iReports Grouping Bug - Multiple Occurrences?

I'm am getting irritated with iReports. Problem is that I have a data set returning data for multiple customers and I want to use the "Group Expression" against the customer ID and have the report lay out the Detail Tabs per customer.
I'm finding that, seeming randomly, where there is more that one data row for a customer iReports will generate two or more groupings (Sometimes it does what I expect and group all the customer data together), the field IDing the customer is the same and doesn't change.
Has anyone seen this before? To be honest I can't believe it is actually a bug, but something I've missed. Just much searching as yet to find a suitable result.
I think this is a data sorting problem.
The quote from iReport Ultimate Guide:
JasperReports groups records by evaluating the group expression. Every
time the expression's value changes, a new group instance is created.
The engine does not perform any record sorting (if not explicitly
requested), so when we define groups we should always take care of the
records sorting. That is, if we want to group a set of addresses by
country, the records we select for the report should already by
ordered by country. It is simple to sort data when using an SQL query
by using the ORDER BY clause. When this is not possible (that is, when
obtaining the records from an XML document), we can request that
JasperReports sort the data for us. This can be done using the sort
options available in the query window
You can sort data in these ways:
in case using of Database jdbc connection datasource type you can add ORDER BY customerId clause to the report's query, where customerId - column name of field with customer id
in case using of File csv connection or something like this you can organize data sorting by adding sortField property for field to the report's template (jrxml file):
<jasperReport ...>
...
<field name="customerId" class="java.lang.String"/>
<sortField name="customerId"/>
SQL Statement has ORDER BY?
iReport group is grouped by customer_id?

Resources