sphinxAPI more than one sort method implementation - sphinx

while fetching records from sphinxApi , i have used the following sort mode. SetSortMode (SPH_SORT_EXTENDED, " field DESC"). Records need to be display randomly. so i have added the below sort method also. SetSortMode(SPH_SORT_EXTENDED, "#random");But records display randomly. But records not display based on first sort method. How to implement two sort methods in single query? Please suggest. Advance thanks

SetSortMode(SPH_SORT_EXTENDED, "field DESC, #random");
(Although I dont know for sure if #random can be combined with others. Extended does support multiple sort orders otherwise)

Related

Mongodb performance design

I have the below use case.
Let's say I have user, order details in the same collection.
Id is user_id|order_id
I have the below informations in single document.
user_detail: {
name, age, email, address
}
Assume single email, single address, single phone number field.
Then order detail which contains order id, order items, etc.
Order details contains indices also.
Note: My use case is something different I am trying to map it.
Approach 1:
Replace the order details. Replace that order wherever it is present.
Approach2:
Have a order collection, compare the changes on the order, update the changed fields where and all this order is present for that customer.
Here, order detail could be present on multiple users. Kindly assume to map my use case.
I implemented approach 2. It seems time consuming, non-scalable. I wonder which one is better or any new approaches? My concern is more about the data in the index.
Any suggestions?

Group By Grouping Sets Returning Unexpected Result

I have a table on which I'm using Group by Group Sets and it is returning one row of data that I do not understand. I was hope you all could help me make sense of it:
The first row that is returned contains Null for both Balance and WarehouseNo, but I know that the Total Value corresponds to WarehouseNo WW-COI with Balance as Null (see second image proving this).
Why does it appear as null when using Group By Grouping Sets?
I think you have a couple different confusions going on here.
Grouping sets are usually used for getting rid of Union All where you need different groupings on the same table.
In your case, you are keeping your Union All because it is on two different tables.
So, from what it seems, you probably just want to use a normal Group By to keep your groupings linked together. It's not clear to me why you'd need grouping sets here.
Now... to answer your question:
Since you are using grouping sets on this unioned dataset, it is going to do a different grouping for the two sets you provided.
Concurrently, it is going to do a grouping on just WarehouseNo and separately at the same time it is going to do a different grouping of just Balance.
Not seeing your original data, this is probably the reason you are getting Nulls in places you didn't expect.
If you want the two columns to be linked, you would need to include them both in the same set. as in:
Group By Grouping Sets ((WarehouseNo, Balance), (another grouping you may want))
The "other grouping" could well be just (WarehouseNo) or (Balance) or even no grouping (). But only you can decide why that information might be important to you.
So, from the looks of it, you probably just want to use a normal Group By here. But quite possibly I'm missing something that I don't understand about your data and what you are trying to achieve with it.
Hope that helps. :)

FOR LAST - Query, giving wrong result

I'm looking to use the following query to find the last tender id.
FOR EACH tender-table NO-LOCK WHERE tender-table.kco = 1 BY tender-table.id:
DISPLAY tender-table.id.
END.
This query looks at all the tender id's and brings back all the results of all the id's in ascending order. The results i get are
1,035
1.036
......
1,060
1,061
1,062
1,063
1,064
1,065
1,066
FOR LAST tender-table NO-LOCK WHERE tender-table.kco = 1 BY tender-table.id:
DISPLAY tender-table.id.
END.
However when i use this query to find the last id, i get the result,
1,061
When I should be seeing the result 1,066. Can anyone suggest why this is happening?
FOR LAST is a very deceptive statement. (So is FOR FIRST.) It does not behave in an intuitive manner. The sort order is NOT specified by the BY statement. You will get the LAST record according to the index which is used and no sorting will take place. When the BY refers to an unindexed field (or one which does not sort in the order of the index actually used) or when the WHERE clause does not obviously map to an index in the order that you are hoping for you will have mysterious records chosen.
Personally, I strongly suggest that you forget about using FOR FIRST & FOR LAST. A better option, which always sorts as expected, would be:
FOR EACH tableName WHERE someCriteria BREAK BY sortOrder:
LEAVE.
END.
DISPLAY whatEver.
(Add "DESCENDING" to flip from FIRST to LAST...)
Just in case anyone needs convincing -- try this with the "sports" database:
for first customer no-lock by discount:
display name discount.
end.
Sorry I have managed to figure it out that the 1,066 values didn't have tender-table.kco = 1. this solves the problem. thanks your time.

ColumnSorting with AsyncDataProvider - how to find out which column the user wants to sort by?

I am implementing a GWT CellTable with paging and sorting by multiple columns dynamically.
The basics can be found in the CellTable Developer's Guide.
However, the dynamic example does not tell how to find out by which column the user wants to sort (it simply sorts by the 'name' column). That's not enough in my case, as I want to allow the user to sort by different columns.
The only solution I could think of, which is not very elegant, is to keep track of which column is sorted in ascending order or not (using table.getColumnSortList(indexOfColumn).isAscending()) and then figuring out which one has been clicked by comparing the values for each column (the one that changed is probably what the user clicked).
This involves keeping information in my classes that should be available somewhere in the CellTable! But I can't find that information!
Thanks for any help.
I found the answer. As explained in the javadocs for com.google.gwt.user.cellview.client.ColumnSortList:
An ordered list containing the sort history of Columns in a table. The 0th item is the ColumnSortInfo of the most recently sorted column.
So, to know which column was last sorted by, you simply do:
ColumnSortInfo info = table.getColumnSortList().get(0);
Column<Type> sortByColumn = info.getColumn();

Core Data Fetched Results Order

I"m working with a core data model of Employees. Each employee is assigned a building and a department. I am returning everyone in building 1 with the predicate, building == 1 and using the sectionNameKeyPath parameter to break the result set down into groups by department.
Right now I have a sort descriptor ordering the departments alphabetically, but is there a way to ignore sorting them alphabetically and organize them in my own way, like engineers first, security second so on and so forth? I'm still getting used to the terminology and there's probably something I'm overlooking.
Thanks,
Note that the sortDescriptors property of the fetched results controller is an array, so you can set multiple sort descriptors which will be used in the order you specify them (e.g. first by department.name, then by lastName, then by firstName).