Solr - always sort specific subset to last of collection - sorting

I'm pretty new to solr. How can I make a subset of records always appear in the last position?
For example:
I have product records such as: (product_id)
ABC001, ABC002 , ABC003, ....
Each has its own attributes (two different tables): (product_id, attribute_id)
ABC001 (A1, A3, A5), ABC002 (A2, A4, A5), ...
I want all products that contain A5 always to appear last when sorting the result. Is there any way I can achieve this? I'm using Solr 4.10.2.
Thanks a lot for your help.

Related

How can I write a Google Sheets query function that will sort a list that has a Letter and number properly?

In google sheets, I have a ton of data that needs to be sorted like this: P1, P2, P3, etc using a QUERY function. when I do an "ORDER BY" clause in my QUERY formula, it returns the list incorrectly putting P10 right after P1 as shown below
I got the list returned like this...
P1
P10
P2
P3
etc.
screenshot for reference
How can I get it to sort properly so that P10 comes after P9 and so forth?
Thank you!
What's happening here is entirely correct, it's just the consequence of how lexicographic ordering works with digits when the strings aren't all the same length. To get around this you need to split the column in two (one just containing the alphabetic portion, the other containing the numeric portion) and sort by both of those columns, OR use string manipulation to add padding zeroes to the number portion (i.e. make P1 into P01). There are various ways of doing all the above, and without any context it's difficult to state which is the most appropriate way for your needs.
you may try adding this sort\regex part to your working QUERY to get your expected output style.
=LAMBDA(z,SORT(z,--REGEXEXTRACT(INDEX(z,,1),"\d+"),1))(QUERY({A2:B13},"Select * ORDER BY Col1"))
Replace 1 in the INDEX(z,,1) with the appropriate column number of P in your query output.

Efficiently scanning on composite row key in hbase

I have my hbase table structured as follows:
a1:b1
a1:b2
a2:b1
a3:b2
Is there any way I can efficiently check if the first part of the row key exists in the hbase table? I do not want to retrieve the records,
I just want to check if a1, a2, a3 exist.
If you are doing this via a Scan, then you can operate only on row keys, without loading any columns by adding the following filters to your Scan:
KeyOnlyFilter
FirstKeyOnlyFilter
However if you are doing this via a get, then I think you'd have to specify at least one column. If I remember correctly, an error will be thrown if you haven't added any columns to your get.

Sorting a CrossTab Report Crystal Reports

Recently I had a problem with sorting a crosstab. I finally found a way to display the results as expected so I thought my solution may eventually help somebody else.
The "original order" doesn't work within Crystal Reports crosstabs unfortunately. The original "order by" section of my sql query contained two column: first a nvarchar column then a int column. In my results I only needed to display a concatenation of those two columns so the results normally looked like this with sql : A1, A2, A3, A10, A11.
But when it came to display the results in a Crystal Report crosstab, the sorting was different because crosstab's sorting is based on the columns/rows displayed only, not the "original order by" from the query results, so the results showed with the crosstab was instead: A1, A10, A11, A2, A3.
My way to solve this issue was to add those 2 fields within the rows section before my "concat field" because they were required for the sorting and to display only my "concat field". To hide fields within a crosstab, just go to this tab: "Customize Style Tab" (from the Cross-Tab Expert). Then select the field to hide within the Rows section and click "Suppress Subtotal" and then "Suppress Label". And it worked like a charm. Hopefully it will helps you guys saving time.
But This solution have some limitations like
if you want to export the report in Excel then it will add extra cells in grand total.
otherwise it is a good to go.
Example:
If you have 3 rows(A,B,C) to display and you added one row and you suppress it to solve your sorting issue then in Excel its grand total looks like
A B C
a 1 3
b 2 2
---------------------------
Total: 3 5

Using the same OrderByAttribute for two attributes in one dimension

In my SSAS cube I have a dimension with attributes A and B, and I want both to be displayed in the sort order specified by a third attribute C. If I specify C as the OrderByAttribute for A and reprocess the cube, then A is sorted correctly.
If I then specify C as the OrderByAttribute for B as well and reprocess the cube, then A continues to be sorted correctly but B does not. Values of B are displayed in an order that seems arbitrary. I have triple-checked that there is no difference in the way A and B are configured.
Is there some conceptual reason why two attributes in a single dimension cannot be both sorted by the same third attribute?
I have now located the problem but still looking for a solution.
As mentioned in the comments, the dsv has tables CM and DisplayOrder between which there are two relationships -- from CM.A to DisplayOrder.primarykey and from CM.B to DisplayOrder.primarykey. SSAS constructs the attribute A using the query:
select distinct CM.A, DisplayOrder.SortOrder
from
(<named query for CM>) as CM,
(<named query for DisplayOrder>) as DisplayOrder
where CM.A = DisplayOrder.primarykey
That is correct and works fine. But when SSAS constructs the attribute B, it uses the query:
select distinct CM.B, DisplayOrder.SortOrder
from
(<named query for CM>) as CM,
(<named query for DisplayOrder>) as DisplayOrder
where CM.A = DisplayOrder.primarykey
Note that the where clause links the two tables using A rather than for B.
So in summary, when the dsv has two tables with two relationships between them, the join in the queries generated by SSAS to implement the OrderByAttribute always use one of those relationships and ignores the other.
Any idea why, or if there is a property somewhere I may have missed?

Joining grouped tables

I have two different scripted data sets that I am pulling data from and aggregating (on the same key). What I want to do is to display one one line the aggregated data from both sources. The data is coming from a scripted data source (POJOs).
A simplified example is given below in which an Order has many Components, with each component being for a different customer at a different quoted price. Then when each Order is filled in different lots (or Fills) at different prices. I want to be able to produce a summary of each Order with the total Ordered and Filled quantity, and the weighted average quoted price and filled price.
An Order Component table
Order ID, Customer Num, Qty, Quoted Px
Ord01,Cust01,3,100
Ord01,Cust02,3,102
Ord02,Cust01,5,200
Ord02,Cust03,5,204
And then a Order Fullfillment table
OrderID,FillId,Qty,CostPx
Ord01,F01,4,100
Ord01,F02,2,106
Ord02,F03,2,200
Ord02,F04,8,210'
I would like to display something like this:
Order ID, Order Qty, Fill Qty, Avg Order Px, Avg Fill Px
Ord01, 6, 6, 101, 102
Ord02, 10, 10, 202, 208
I've tried using subreports and that seems to be able to get me the results but in a terrible format. The subtable headers repeat so every order gets it's own headers.
You may want to create a BIRT joined dataset between your two scripted datasets, based on a full outer join on the "order ID" column, and then use this joined dataset in your report. It should meet your needs.
I solved my problem by more or less following the following guide.
So I created a List linked to my first data source. I then added a group on Order ID so that I had one list row per Order. In the group header I added a 2x1 grid, I placed a table of the Order Components into one side of the grid and a table of Fills into the other. I had to add filters to both of these so that they only contained data for the correct OrderId. I then grouped the tables by OrderId, added my aggregation fields.
All that is left is to set the visibilty. So I set the visibility of the table details to false. In order to only show the table header once (instead of once per order) I added a Running Count aggregation to the List and set the visibiity to invisible when this aggregation was greater than 1.
Was actually quite easy in the end but took me ages to work out how to do it.

Resources