Hi Gimantha,
This is a very useful functionality. Thanks for adding this. I have 1
question. Can you tell me the difference of result between the following 2
combinations.
"sortType" : "DESC"
"reversed" : false
and
"sortType" : "ASC"
"reversed" : true
My query is, that if you can do either ASC or DESC, why do you need a
separate parameter to reverse the order? What am I missing?
seshi
On Wed, Mar 16, 2016 at 6:21 PM, Gimantha Bandara <[email protected]> wrote:
> Hi all,
>
> We have two methods in AnalyticsDataService namely "search" and
> "getDrillDownRecords". These two methods returns record Ids sorted by the
> Relevance score ( Relevance score is generated by Lucene at the search
> time. Record ids that match most with the given search query will have a
> higher score and will be the first records that comes first in the result
> list). With the new sorting functionality, the matching records can be
> retrieved either descending or ascending sort order of a specific field/s.
>
> Followings are the new search methods added to AnalyticsDataService.
>
> List<SearchResultEntry> search(int tenantId, String tableName, String
> query, int start, int count, *List<SortByField> sortByFields*) throws
> AnalyticsException
> List<SearchResultEntry> drillDownSearch(int tenantId,
> AnalyticsDrillDownRequest request) throws AnalyticsIndexException
>
> The last parameter to search method is srotByField. This is a list which
> contains the fields by which the users wants to sort the records.
> SortByField class will have the 3 attributes, fieldName, sortType,
> isReversed.
>
> 1. *fieldName* is the field by which the records need to be sorted.
> 2. *sortType* is either SORT.ASC or SORT.DESC (Denotes ascending or
> descending)
> 3. *isRevesed* says whether the sorted records need to be returned
> reversed in order or not. (optional)
>
> Search APIs take a list of SortByFields, which means the records can be
> sorted by multiple fields. Records will be sorted by the second SortByField
> if the value for the first SortByField is same.
>
>
>
>
> *REST APIs*
>
>
> *Search*
> Analytics REST call[1] now has an additional parameter call "sortBy" to
> support sorting. A sample request payload will look like below.
>
> POST https://localhost:9443/analytics/search
>
> {
> "tableName" : "Students",
> "query" : "Grade:10",
> "start" : 0,
> "count" : 100,
> "sortBy" : [{
> "field" : "totalScore",
> "sortType" : "DESC" //can be DESC or ASC
> "reversed" : false //optional
> }]
> }
>
> Above will return the matching records sorted by totalScore field in
> descending order.
>
>
>
> *Drilldown*
> Drilldown API[2] also supports sorting. Following is a sample request on
> how to sort the students whose City is Colombo and who are in Grade 10 in
> descending order.
>
> POST https://localhost:9443/analytics/drilldown
>
> {
> "tableName":"Students",
> "categories":[
> {
> "fieldName":"location",
> "path":["Sri Lanka", "Colombo]
> }
> ],
> "query":"Grade:10",
> "recordCount":100,
> "sortBy":[
> {
> "field":"totalScore",
> "sortType":"DESC"
> }
> ]
> }
>
>
>
> *Javascript APIs*
>
> Javascript APIs is used at client side for custom development based on DAS.
>
> *Search*
>
> Search method[3] in Javascript APIs has an additional parameter to pass
> sort information to get sorted records. Following is a sample JS call to
> get sorted records.
>
> var queryInfo = {
> tableName : "Students",
> searchParams : {
> query : "Grade : 10",
> start : 0,
> count : 100,
> sortBy : [
> {
> field : "totalScore",
> sortType : "DESC", // This can be ASC, DESC
> reversed : "false" //optional
> }
> ]
> }
> };
>
> client.search(queryInfo, function(data) {
> console.log (data["message"]);
> }, function(error) {
> console.log("error occured: " + error["message"]);
> });
>
>
> *DrillDown*
> Using DrillDown API[4] in JS APIs, we can achieve the same as REST
> DrillDown API. Following is a sample request on how to sort the students
> whose City is Colombo and who are in Grade 10 in descending order.
>
> var drillDownReq = {
> tableName : "Students",
> drillDownInfo : {
> categories : [
> {
> fieldName : "location",
> path : ["Srilanka", "Colombo"]
> }]
> query : "Grade : 10",
> recordStart : 0,
> recordCount : 100,
> sortBy : [
> {
> field : "totalScore",
> sortType : "DESC", // This can be ASC, DESC
> reversed : "false" //optional
> }
> ]
> };
>
> client.drillDownSearch(drillDownReq, function(data) {
> console.log (data["message"]);
> }, function(error) {
> console.log("error occured: " + error);
> });
>
> Please note that the fields that you wants records to be sorted by, need
> to be indexed beforehand.
>
> [1]
> https://docs.wso2.com/display/DAS301/Retrieving+Specific+Records+through+a+Drill+Down+Search+via+REST+API
> [2]
> https://docs.wso2.com/display/DAS301/Retrieving+All+Records+Matching+the+Given+Search+Query+via+REST+API
> [3]
> https://docs.wso2.com/display/DAS301/Retrieving+All+Records+Matching+the+Given+Search+Query+via+JS+API
> [4]
> https://docs.wso2.com/display/DAS301/Retrieving+Specific+Records+through+a+Drill+Down+Search+via+JS+API
>
> --
> Gimantha Bandara
> Software Engineer
> WSO2. Inc : http://wso2.com
> Mobile : +94714961919
>
> _______________________________________________
> Architecture mailing list
> [email protected]
> https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture
>
>
_______________________________________________
Architecture mailing list
[email protected]
https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture